//全局变量
import './Global';
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import { ThemeProvider } from '@contexts/themeContext';
import { ShopProvider } from '@contexts/shopContext';
import { Provider } from 'react-redux';
import store from './app/store';
import * as Sentry from "@sentry/react";
import { Capacitor } from '@capacitor/core';
import { TextZoom } from '@capacitor/text-zoom';
if (!Capacitor.isNativePlatform()) {
    // 只有在纯浏览器/PWA 才注册 SW
    window.addEventListener('load', () => {
        navigator.serviceWorker?.register('/service-worker.js')
                 .then(reg => console.log('SW register success', reg))
                 .catch(err => console.error('SW register failed', err));
    });
}
else
{
    TextZoom.set({ value: 1 });
}


global.dispatch = store.dispatch;
Sentry.init({
    dsn: "https://4686ef0d926e140fb482e63efcde1cdf@o4507102375641088.ingest.us.sentry.io/4507102380687360",
    integrations: [
        Sentry.browserTracingIntegration(),
        Sentry.feedbackIntegration({
            // Additional SDK configuration goes in here, for example:
            colorScheme: "dark",
            autoInject: false,
            isEmailRequired: true,
        }),
    ],
    // Performance Monitoring
    // tracesSampleRate: 1.0, //  Capture 100% of the transactions
    tracesSampleRate: 0.25, //  Capture 100% of the transactions
    // Set 'tracePropagationTargets' to control for which URLs distributed tracing should be enabled
    tracePropagationTargets: ["localhost", "*", /^https:\/\/yourserver\.io\/api/],
    // Session Replay
    replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
    replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
});

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
    <Provider store={store}>
        <BrowserRouter>
            <ThemeProvider>
                <ShopProvider>
                    <App />
                </ShopProvider>
            </ThemeProvider>
        </BrowserRouter>
    </Provider>
);

