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

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

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

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

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

    Provider = ({
        children
    }: {
        children: ReactNode
    }) => {
        const EmbeddedMenuContext = this.NCoreUIKitEmbeddedMenu;
        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;
        const MenuContext = this.NCoreUIKitMenu;

        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>
                                                                        <Host name="menu-system">
                                                                            <MenuContext.Provider>
                                                                                <MenuContext.Render>
                                                                                    <EmbeddedMenuContext.Provider>
                                                                                        {children}
                                                                                    </EmbeddedMenuContext.Provider>
                                                                                </MenuContext.Render>
                                                                            </MenuContext.Provider>
                                                                        </Host>
                                                                    </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;
