import React, { Suspense } from 'react';
import ReactDOM from 'react-dom/client'

// Override toLocaleDateString globally to support DD-mmm-YYYY format (e.g. 10-dec-2026)
const originalToLocaleDateString = Date.prototype.toLocaleDateString;
Date.prototype.toLocaleDateString = function (
    this: Date,
    locales?: string | string[],
    options?: Intl.DateTimeFormatOptions
): string {
    if (options && !options.day && (options.weekday || options.month || options.year || options.hour || options.minute)) {
        return originalToLocaleDateString.call(this, locales, options);
    }
    if (isNaN(this.getTime())) {
        return "Invalid Date";
    }
    const day = String(this.getDate()).padStart(2, '0');
    const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
    const month = months[this.getMonth()];
    const year = this.getFullYear();
    return `${day}-${month}-${year}`;
};

// Perfect Scrollbar
import 'react-perfect-scrollbar/dist/css/styles.css';

// Tailwind css
import './tailwind.css';

// Leaflet css
import 'leaflet/dist/leaflet.css';

// i18n (needs to be bundled)
import './i18n';

// Router
import { RouterProvider } from 'react-router-dom';
import router from './router/index';

// Redux
import { Provider } from 'react-redux';
import store from './store/index';
import Loader from './components/Loader';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
    <React.StrictMode>
        <Suspense fallback={<Loader />}>
            <Provider store={store}>
                <RouterProvider router={router} />
            </Provider>
        </Suspense>
    </React.StrictMode>
);

