import {
    type ReactNode
} from "react";
import NCoreUIKitLocalize from "./localize";
import NCoreUIKitModal from "./modal";
import NCoreUIKitTheme from "./theme";
import {
    type NCoreUIKitConfig
} from "../types";

class CoreContext<T extends NCoreUIKitConfig> {
    NCoreUIKitLocalize: NCoreUIKitLocalize<T>;
    NCoreUIKitTheme: NCoreUIKitTheme<T>;
    NCoreUIKitModal: NCoreUIKitModal;

    constructor(initialState: T) {
        this.NCoreUIKitTheme = new NCoreUIKitTheme({
            initialSelectedActiveSharpness: initialState.initialSelectedActiveSharpness,
            initialSelectedGapPropagation: initialState.initialSelectedGapPropagation,
            initialSelectedPalette: initialState.initialSelectedPalette,
            initialSelectedTheme: initialState.initialSelectedTheme,
            projectThemes: initialState.projectThemes
        });

        this.NCoreUIKitLocalize = new NCoreUIKitLocalize({
            initialSelectedLocale: initialState.initialSelectedLocale,
            projectLocales: initialState.projectLocales
        });

        this.NCoreUIKitModal = new NCoreUIKitModal({
            data: []
        });
    }

    Provider = ({
        children
    }: {
        children: ReactNode
    }) => {
        const LocalizeContext = this.NCoreUIKitLocalize;
        const ModalContext = this.NCoreUIKitModal;
        const ThemeContext = this.NCoreUIKitTheme;

        return <ThemeContext.Provider>
            <LocalizeContext.Provider>
                <ModalContext.Provider>
                    <ModalContext.Render>
                        {children}
                    </ModalContext.Render>
                </ModalContext.Provider>
            </LocalizeContext.Provider>
        </ThemeContext.Provider>;
    };
};
export default CoreContext;
