import {
    type TextStyle,
    type ViewStyle,
    StyleSheet
} from "react-native";
import {
    type NotificationIndicatorDynamicStyleType,
    type NotificationIndicatorTypeConstantType,
    type NotificationIndicatorTypes,
    type NotificationIndicatorType
} from "./type";
import type {
    Mutable
} from "../../types";

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

export const getNotificationIndicatorType = ({
    type
}: NotificationIndicatorTypeConstantType): NotificationIndicatorTypes => {
    const currentType = NOTIFICATION_INDICATOR_TYPE_STYLES[type];

    return currentType;
};

const stylesheet = StyleSheet.create({
    container: {
        backgroundColor: "transparent",
        borderColor: "transparent",
        position: "relative"
    },
    indicatorContainer: {
        borderStyle: "solid",
        position: "absolute",
        minHeight: 18,
        minWidth: 18
    },
    titleContainer: {
        position: "relative"
    },
    title: {
    },
    loading: {
    },
    overlay: {
        position: "absolute",
        display: "none",
        zIndex: 999,
        bottom: 0,
        right: 0,
        left: 0,
        top: 0
    }
});

export const useStyles = ({
    floorBackgroundColor,
    spreadBehaviour,
    currentType,
    isDisabled,
    isLoading,
    radiuses,
    borders,
    colors,
    spaces,
    type
}: NotificationIndicatorDynamicStyleType) => {
    const styleType = type === "danger" ? "error" : type;

    const styles = {
        container: {
            padding: spaces.spacingSm
        } as Mutable<ViewStyle>,
        indicatorContainer: {
            backgroundColor: colors.content.container[currentType.containerColor],
            borderColor: colors.content.container[floorBackgroundColor],
            paddingHorizontal: spaces.spacingSm,
            paddingVertical: spaces.spacingXs,
            borderWidth: borders.subtract,
            borderRadius: radiuses.full
        } as Mutable<ViewStyle>,
        titleContainer: {
        } as Mutable<ViewStyle>,
        title: {

        } as Mutable<TextStyle>,
        loading: {
        } as Mutable<ViewStyle>,
        overlay: {

        } as Mutable<ViewStyle>
    };

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

    if (isLoading) {
        styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
        styles.overlay.display = "flex";
    }

    if (isDisabled) {
        styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
        styles.overlay.display = "flex";
    }

    return styles;
};
export default stylesheet;
