import {
    type ReactNode
} from "react";
import NCoreUIKitBottomSheet from "./bottomSheet";
import NCoreUIKitDialog from "./dialog";
import NCoreUIKitLocalize from "./localize";
import NCoreUIKitModal from "./modal";
import NCoreUIKitSnackBar from "./snackBar";
import NCoreUIKitTheme from "./theme";
import NCoreUIKitToast from "./toast";
import {
    type NCoreUIKitConfig
} from "../types";
import {
    Host
} from "../helpers/portalize";

class CoreContext<T extends NCoreUIKitConfig> {
    NCoreUIKitBottomSheet: NCoreUIKitBottomSheet;
    NCoreUIKitLocalize: NCoreUIKitLocalize<T>;
    NCoreUIKitSnackBar: NCoreUIKitSnackBar;
    NCoreUIKitTheme: NCoreUIKitTheme<T>;
    NCoreUIKitDialog: NCoreUIKitDialog;
    NCoreUIKitModal: NCoreUIKitModal;
    NCoreUIKitToast: NCoreUIKitToast;

    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: []
        });

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

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

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

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

    Provider = ({
        children
    }: {
        children: ReactNode
    }) => {
        const BottomSheetContext = this.NCoreUIKitBottomSheet;
        const LocalizeContext = this.NCoreUIKitLocalize;
        const SnackBarContext = this.NCoreUIKitSnackBar;
        const DialogContext = this.NCoreUIKitDialog;
        const ModalContext = this.NCoreUIKitModal;
        const ToastContext = this.NCoreUIKitToast;
        const ThemeContext = this.NCoreUIKitTheme;

        return <ThemeContext.Provider>
            <LocalizeContext.Provider>
                <Host name="snack-bar-system">
                    <SnackBarContext.Provider>
                        <SnackBarContext.Render>
                            <Host name="toast-system">
                                <Host name="modal-system">
                                    <ModalContext.Provider>
                                        <ModalContext.Render>
                                            <DialogContext.Provider>
                                                <DialogContext.Render>
                                                    <ToastContext.Provider>
                                                        <ToastContext.Render>
                                                            <Host name="bottomSheet-system">
                                                                <BottomSheetContext.Provider>
                                                                    <BottomSheetContext.Render>
                                                                        {children}
                                                                    </BottomSheetContext.Render>
                                                                </BottomSheetContext.Provider>
                                                            </Host>
                                                        </ToastContext.Render>
                                                    </ToastContext.Provider>
                                                </DialogContext.Render>
                                            </DialogContext.Provider>
                                        </ModalContext.Render>
                                    </ModalContext.Provider>
                                </Host>
                            </Host>
                        </SnackBarContext.Render>
                    </SnackBarContext.Provider>
                </Host>
            </LocalizeContext.Provider>
        </ThemeContext.Provider>;
    };
};
export default CoreContext;
