import {
    type TextStyle,
    type ViewStyle,
    StyleSheet
} from "react-native";
import type {
    SnackBarDynamicStyleType,
    SnackBarTypeConstantType,
    SnackBarTypes,
    SnackBarType
} from "./type";
import type {
    Mutable
} from "../../types";
import {
    windowWidth
} from "../../utils";

export const SNACK_BAR_TYPE_STYLES: Record<
    SnackBarType,
    {
        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 getSnackBarType = ({
    type
}: SnackBarTypeConstantType): SnackBarTypes => {
    const currentType = SNACK_BAR_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,
        flex: 1
    },
    iconContainer: {
        justifyContent: "center",
        alignItems: "center"
    },
    title: {
        textAlign: "left"
    },
    subTitle: {
        textAlign: "left"
    }
});

export const useStyles = ({
    isInlineSafeArea,
    isFullWidth,
    safeAreaTop,
    currentType,
    radiuses,
    colors,
    spaces
}: SnackBarDynamicStyleType) => {
    const styles = {
        container: {
            backgroundColor: colors.content.container[currentType.containerColor],
            width: windowWidth - (spaces.spacingMd * 2),
            top: safeAreaTop + spaces.spacingSm,
            borderRadius: radiuses.lg
        } 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(isFullWidth) {
        styles.container.width = windowWidth;
        styles.container.borderRadius = 0;
    }

    if(isInlineSafeArea) {
        styles.container.paddingTop = safeAreaTop;
        styles.container.top = 0;
    }

    return styles;
};
export default stylesheet;
