import {
    type ForwardRefRenderFunction
} from "react";
import {
    type INCoreUIKitIconCallbackProps
} from "./icon";
import {
    type LocalizeType,
    type LocaleType
} from "./locale";
import {
    type ModalDataType,
    type ModalType
} from "./modal";
import {
    type GapPropagationType,
    type SharpnessType,
    type PaletteType,
    type ThemesType,
    type ThemeType
} from "./theme";
import defaultLocaleJSON from "../variants/locales/default.json";
import defaultThemeJSON from "../variants/themes/default.json";

export type {
    PortalizedComponentProps
} from "./portalize";

export type {
    INCoreUIKitIconCallbackProps,
    INCoreUIKitIconProps,
    NCoreUIKitIcon
} from "./icon";

export type {
    ThemeContextStateType,
    ThemeContextType
} from "./theme";

export type {
    LocalizeContextStateType,
    LocalizeContextType
} from "./locale";

export type {
    GapPropagationType,
    NCoreUIKitConfig,
    SharpnessType,
    ModalDataType,
    LocalizeType,
    PaletteType,
    ThemesType,
    LocaleType,
    ModalType,
    ThemeType
};

export type RecursiveRecord = {
  [key: string]: string | RecursiveRecord;
};

export interface RefForwardingComponent<T, P = object> extends ForwardRefRenderFunction<T, P> {};

export type Mutable<T> = {
    -readonly [P in keyof T]: T[P];
};

type NCoreUIKitConfig = ThemesType & LocalizeType & ModalType;

declare global {
    namespace NCoreUIKit {
        type GapPropagationKey = GapPropagationType;
        type SharpnessKey = SharpnessType;
        type PaletteKey = PaletteType;
        type LocaleKey = LocaleType;
        type ThemeKey = ThemeType;

        type IconCallbackProps = INCoreUIKitIconCallbackProps;

        interface ActivePalette {
            inlineSpaces: InlineSpaces;
            typography: Typography;
            colors: ThemeTokens;
            radiuses: Radiuses;
            borders: Borders;
            spaces: Spaces;
        }

        interface Palette {
            isNeedAndroidTypographyFixer: boolean;
            typography: TypographyWithVariants;
            palettes: ThemePalettes;
            shapes: Shapes;
        }

        type SpacesWithVariants = Record<GapPropagationType, Spaces>;

        type RadiusesWithVariants = Record<SharpnessType, Radiuses>;

        type Shapes = {
            radiuses: RadiusesWithVariants;
            inlineSpaces: InlineSpaces;
            spaces: SpacesWithVariants;
            borders: Borders;
        };

        type DefaultSpaces = Record<keyof typeof defaultThemeJSON.shapes.spaces.compact, number>;

        interface Spaces extends DefaultSpaces {}

        type DefaultBorders = Record<keyof typeof defaultThemeJSON.shapes.borders, number>;

        interface Borders extends DefaultBorders {
        }

        type DefaultInlineSpaces = Record<keyof typeof defaultThemeJSON.shapes.inlineSpaces, number>;

        interface InlineSpaces extends DefaultInlineSpaces {
        }

        type DefaultRadiuses = Record<keyof typeof defaultThemeJSON.shapes.radiuses.rounded, number>;

        interface Radiuses extends DefaultRadiuses {}

        type TypographyWithVariants = Record<GapPropagationType, Typography>;

        type DefaultTypography = Record<keyof typeof defaultThemeJSON.typography.compact, TypographyToken>;

        interface Typography extends DefaultTypography {}

        interface TypographyToken {
            letterSpacing: number;
            fontWeight: string;
            fontFamily: string;
            lineHeight: number;
            fontSize: number;
        }

        type ThemePalettes = Array<ThemePalette>;

        interface ThemePalette {
            themes: Theme;
            name: string;
        }

        type Theme = Record<ThemeKey, ThemeTokens>;

        type ColorsMerged = DefaultSystemColors & DefaultContentColors;

        type ThemeTokens = {
            content: ContentColorPalette;
            system: SystemColorPalette;
        };

        type DefaultPalette = typeof defaultThemeJSON.palettes[0];

        type SystemData = DefaultPalette["themes"]["dark"]["system"];
        type DefaultSystemColors = SystemData;

        interface SystemColorPalette extends DefaultSystemColors {
        }

        type ContentData = DefaultPalette["themes"]["dark"]["content"];
        type DefaultContentColors = ContentData;

        interface ContentColorPalette extends DefaultContentColors {
        }

        type ContainerContentColors = DefaultContentColors["container"];
        type BorderContentColors = DefaultContentColors["border"];
        type IconContentColors = DefaultContentColors["icon"];
        type TextContentColors = DefaultContentColors["text"];

        type DisabledSystemColors = DefaultSystemColors["disabled"];
        type StateSystemColors = DefaultSystemColors["state"];

        type Locales = Array<Locale>;

        interface Locale {
            translations: Translation;
            locale: string;
            isRTL: boolean;
        }

        type DefaultLocalization = typeof defaultLocaleJSON[0];

        type GeneratedTranslations = {
            [K in keyof DefaultLocalization["translations"]]: DefaultLocalization["translations"][K];
        };

        interface Translation extends GeneratedTranslations {
        }
    }
}
