import {
    type TextStyle,
    type ViewStyle,
    StyleSheet
} from "react-native";
import type {
    ToastDynamicStyleType,
    ToastTypeConstantType,
    ToastTypes,
    ToastType
} from "./type";
import type {
    Mutable
} from "../../types";
import {
    windowWidth
} from "../../utils";

export const TOAST_TYPE_STYLES: Record<
    ToastType,
    {
        containerColor: keyof NCoreUIKit.ContainerContentColors;
        subTitleColor: keyof NCoreUIKit.TextContentColors;
        actionColor: keyof NCoreUIKit.TextContentColors;
        titleColor: keyof NCoreUIKit.TextContentColors;
        iconColor: keyof NCoreUIKit.IconContentColors;
    }
> = {
    primary: {
        actionColor: "onPrimary",
        iconColor: "emphasized",
        containerColor: "mid",
        subTitleColor: "low",
        titleColor: "mid"
    },
    danger: {
        subTitleColor: "dangerLow",
        containerColor: "danger",
        actionColor: "danger",
        titleColor: "danger",
        iconColor: "danger"
    },
    success: {
        subTitleColor: "successLow",
        containerColor: "success",
        actionColor: "success",
        titleColor: "success",
        iconColor: "success"
    },
    warning: {
        subTitleColor: "warningLow",
        containerColor: "warning",
        actionColor: "warning",
        titleColor: "warning",
        iconColor: "warning"
    },
    info: {
        subTitleColor: "infoLow",
        containerColor: "info",
        actionColor: "info",
        titleColor: "info",
        iconColor: "info"
    },
    neutral: {
        containerColor: "mid",
        subTitleColor: "low",
        actionColor: "mid",
        titleColor: "mid",
        iconColor: "mid"
    }
};

export const getToastType = ({
    type
}: ToastTypeConstantType): ToastTypes => {
    const currentType = TOAST_TYPE_STYLES[type];

    return currentType;
};

const stylesheet = StyleSheet.create({
    container: {
        position: "absolute",
        alignSelf: "center",
        zIndex: 99998
    },
    containerObject: {
        flexDirection: "row",
        alignItems: "center"
    },
    contentContainer: {
        justifyContent: "center",
        alignItems: "flex-start",
        flexDirection: "column",
        flexShrink: 1
    },
    iconContainer: {
        justifyContent: "center",
        alignItems: "center"
    },
    title: {
        textAlign: "left"
    },
    subTitle: {
        textAlign: "left"
    }
});

export const useStyles = ({
    safeAreaBottom,
    currentType,
    radiuses,
    subTitle,
    colors,
    spaces
}: ToastDynamicStyleType) => {
    const styles = {
        container: {
            backgroundColor: colors.content.container[currentType.containerColor],
            maxWidth: windowWidth - (spaces.spacingMd * 2),
            bottom: safeAreaBottom + 100,
            borderRadius: radiuses.full
        } as Mutable<ViewStyle>,
        containerObject: {
            paddingHorizontal: spaces.spacingLg,
            paddingVertical: spaces.spacingMd
        } as Mutable<ViewStyle>,
        contentContainer: {

        } as Mutable<ViewStyle>,
        title: {

        } as Mutable<TextStyle>,
        subTitle: {
            marginTop: spaces.spacingXs
        } as Mutable<TextStyle>,
        iconContainer: {
            paddingRight: spaces.spacingSm,
            marginRight: spaces.spacingSm
        } as Mutable<ViewStyle>,
        action: {
            paddingBottom: spaces.spacingSm,
            paddingRight: spaces.spacingSm,
            paddingLeft: spaces.spacingMd,
            paddingTop: spaces.spacingSm,
            marginLeft: spaces.spacingMd
        } as Mutable<ViewStyle>
    };

    if(subTitle) {
        styles.container.borderRadius = radiuses.lg;
    }

    return styles;
};
export default stylesheet;
