import {
    type TextStyle,
    type ViewStyle,
    StyleSheet
} from "react-native";
import {
    type StickerDynamicStyleType,
    type StickerTypeConstantType,
    type StickerTypes,
    type StickerType
} from "./type";
import type {
    Mutable
} from "../../types";

export const CHECK_BOX_TYPE_STYLES: Record<
    StickerType,
    {
        containerColor: keyof NCoreUIKit.ContainerContentColors;
        titleColor: keyof NCoreUIKit.TextContentColors;
        iconColor: keyof NCoreUIKit.IconContentColors;
    }
> = {
    success: {
        containerColor: "success",
        titleColor: "success",
        iconColor: "success"
    },
    warning: {
        containerColor: "warning",
        titleColor: "warning",
        iconColor: "warning"
    },
    danger: {
        containerColor: "danger",
        titleColor: "danger",
        iconColor: "danger"
    },
    info: {
        containerColor: "info",
        titleColor: "info",
        iconColor: "info"
    },
    neutral: {
        containerColor: "mid",
        titleColor: "mid",
        iconColor: "mid"
    },
    primary: {
        containerColor: "mid",
        titleColor: "mid",
        iconColor: "mid"
    }
};

export const getStickerType = ({
    type
}: StickerTypeConstantType): StickerTypes => {
    const currentType = CHECK_BOX_TYPE_STYLES[type];

    return currentType;
};

const stylesheet = StyleSheet.create({
    container: {
        backgroundColor: "transparent",
        justifyContent: "center",
        flexDirection: "row",
        alignItems: "center"
    },
    titleContainer: {
        justifyContent: "flex-start",
        flexDirection: "row",
        alignItems: "center"
    },
    title: {
        textAlign: "center",
        margin: 0
    }
});

export const useStyles = ({
    spreadBehaviour,
    iconPosition,
    currentType,
    customColor,
    radiuses,
    colors,
    spaces,
    size
}: StickerDynamicStyleType) => {
    const styles = {
        container: {
            paddingHorizontal: size === "small" ? spaces.spacingSm : spaces.spacingMd,
            paddingVertical: size === "small" ? spaces.spacingXs : spaces.spacingSm,
            backgroundColor: colors.content.container[currentType.containerColor],
            borderRadius: radiuses.chip,
            alignSelf: "auto"
        } as Mutable<ViewStyle>,
        titleContainer: {
        } as Mutable<ViewStyle>,
        title: {
        } as Mutable<TextStyle>,
        icon: {
        } as Mutable<ViewStyle>
    };

    if(customColor) {
        styles.container.backgroundColor = colors.content.container[customColor];
    }

    if (spreadBehaviour === "baseline") {
        styles.container.alignSelf = spreadBehaviour;
        styles.container.width = "auto";
    }

    if(iconPosition === "right") {
        styles.icon.marginLeft = spaces.spacingXs;
    } else {
        styles.icon.marginRight = spaces.spacingXs;
    }

    return styles;
};
export default stylesheet;
