import {
    type ViewStyle,
    type TextStyle,
    StyleSheet
} from "react-native";
import {
    type SelectBoxDynamicStyleType,
    type SelectBoxTypes,
    type SelectBoxType
} from "./type";
import type {
    Mutable
} from "../../types";

export const TEXT_INPUT_TYPE_STYLES: Record<
    SelectBoxType,
    SelectBoxTypes
> = {
    default: {
        focusBorderColor: "emphasized",
        borderColor: "emphasized",
        hintTextIconColor: "mid",
        placeholderColor: "low",
        containerColor: "mid",
        hintTextColor: "mid",
        titleColor: "high",
        inputColor: "mid",
        iconColor: "mid"
    },
    question: {
        focusBorderColor: "emphasized",
        borderColor: "emphasized",
        hintTextIconColor: "mid",
        placeholderColor: "low",
        containerColor: "mid",
        hintTextColor: "mid",
        titleColor: "mid",
        inputColor: "mid",
        iconColor: "mid"
    },
    success: {
        placeholderColor: "successLow",
        hintTextIconColor: "success",
        focusBorderColor: "success",
        containerColor: "success",
        hintTextColor: "success",
        borderColor: "success",
        titleColor: "success",
        inputColor: "success",
        iconColor: "success"
    },
    warning: {
        placeholderColor: "warningLow",
        hintTextIconColor: "warning",
        focusBorderColor: "warning",
        containerColor: "warning",
        hintTextColor: "warning",
        borderColor: "warning",
        titleColor: "warning",
        inputColor: "warning",
        iconColor: "warning"
    },
    danger: {
        placeholderColor: "dangerLow",
        hintTextIconColor: "danger",
        focusBorderColor: "danger",
        containerColor: "danger",
        hintTextColor: "danger",
        borderColor: "danger",
        titleColor: "danger",
        inputColor: "danger",
        iconColor: "danger"
    },
    info: {
        placeholderColor: "infoLow",
        hintTextIconColor: "info",
        focusBorderColor: "info",
        containerColor: "info",
        hintTextColor: "info",
        borderColor: "info",
        titleColor: "info",
        inputColor: "info",
        iconColor: "info"
    }
};

export const getSelectBoxType = ({
    type
}: {
    type: SelectBoxType;
}) => {
    const currentType = TEXT_INPUT_TYPE_STYLES[type];

    return currentType;
};

const stylesheet = StyleSheet.create({
    cleanButton: {
        justifyContent: "center",
        alignItems: "center",
        alignSelf: "center",
        zIndex: 99
    },
    icon: {
        justifyContent: "center",
        alignContent: "center",
        alignItems: "center",
        zIndex: 99
    },
    rightIcon: {
        justifyContent: "center",
        alignItems: "center",
        alignSelf: "center",
        zIndex: 99
    },
    container: {
        flexDirection: "column",
        boxSizing: "border-box"
    },
    contentContainer: {
        boxSizing: "border-box",
        flexDirection: "row",
        borderStyle: "solid",
        alignItems: "center",
        position: "relative",
        minWidth: 200
    },
    titleContainer: {
        flexDirection: "row",
        alignItems: "center"
    },
    hintText: {
        flexDirection: "row",
        alignItems: "center"
    },
    overlay: {
        position: "absolute",
        display: "none",
        zIndex: 98,
        bottom: 0,
        right: 0,
        left: 0,
        top: 0
    },
    content: {
        width: "100%",
        flex: 1,
        flexShrink: 1
    },
    contentText: {
        minHeight: 20
    },
    hintTextIcon: {
    },
    required: {
    },
    subTitle: {
    },
    title: {
    }
});

export const useStyles = ({
    CustomPrefixComponent,
    spreadBehaviour,
    inlineSpaces,
    currentType,
    isDisabled,
    isActive,
    radiuses,
    borders,
    colors,
    spaces,
    type
}: SelectBoxDynamicStyleType) => {
    const styleType = type === "danger" ? "error" : type === "question" ? "neutral" : type;

    const styles = {
        contentContainer: {
            backgroundColor: colors.content.container[currentType.containerColor],
            borderColor: colors.content.container[currentType.containerColor],
            paddingBottom: spaces.spacingMd,
            paddingRight: spaces.spacingMd,
            borderRadius: radiuses.actions,
            paddingLeft: spaces.spacingMd,
            paddingTop: spaces.spacingMd,
            borderWidth: borders.line
        } as Mutable<ViewStyle>,
        required: {
            marginRight: inlineSpaces.required
        } as Mutable<ViewStyle>,
        overlay: {
            borderRadius: radiuses.actions - 1
        } as Mutable<ViewStyle>,
        subTitle: {
            marginLeft: inlineSpaces.subTitle
        } as Mutable<TextStyle>,
        titleContainer: {
            marginBottom: spaces.spacingSm
        } as Mutable<ViewStyle>,
        icon: {
            marginRight: spaces.spacingSm
        } as Mutable<ViewStyle>,
        hintTextIcon: {
            marginRight: spaces.spacingXs
        } as Mutable<ViewStyle>,
        cleanButton: {
            marginLeft: spaces.spacingSm
        } as Mutable<ViewStyle>,
        rightIcon: {
            marginLeft: spaces.spacingSm
        } as Mutable<ViewStyle>,
        hintText: {
            marginTop: spaces.spacingSm
        } as Mutable<TextStyle>,
        container: {
            alignSelf: "auto"
        } as Mutable<ViewStyle>,
        content: {
        } as Mutable<ViewStyle>,
        contentText: {
        } as Mutable<TextStyle>,
        title: {
        } as Mutable<TextStyle>
    };

    if(isDisabled) {
        const disableStyleType = styleType === "default" ? "neutral" : styleType;

        styles.overlay.backgroundColor = colors.system.state.overlay.disabled[disableStyleType];
        styles.container.borderColor = colors.system.state.overlay.disabled[disableStyleType];
    }

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

    if (spreadBehaviour === "stretch") {
        styles.container.alignSelf = spreadBehaviour;
        styles.container.justifyContent = "center";
        styles.container.flexShrink = 1;
        styles.container.width = "100%";
    }

    if(isActive) {
        styles.contentContainer.borderColor = colors.content.border.emphasized;
    }

    if(CustomPrefixComponent) {
        styles.content.marginLeft = spaces.spacingSm;
    }

    return styles;
};
export default stylesheet;
