import {
    type ViewStyle,
    StyleSheet,
    Platform
} from "react-native";
import type {
    MenuDynamicStyle
} from "./type";
import type {
    Mutable
} from "../../types";
import {
    webStyle
} from "../../utils";

const stylesheet = StyleSheet.create({
    contentContainer: {
        justifyContent: "flex-start",
        flexDirection: "column",
        alignItems: "stretch"
    },
    headerContainer: {
        justifyContent: "center",
        alignItems: "flex-start",
        width: "100%"
    },
    container: {
        flexDirection: "column",
        ...Platform.select({
            web: {
                minWidth: 280,
                maxWidth: 340,
                width: "auto"
            },
            default: {
                width: "82%"
            }
        }),
        position: "absolute",
        display: "flex",
        height: "100%",
        zIndex: 99997,
        bottom: 0,
        left: 0,
        top: 0
    },
    content: {
        flex: 1,
        ...webStyle({
            overflowX: "hidden"
        })
    },
    safeAreaView: {
        flex: 1
    },
    seperator: {
    }
});

export const useStyles = ({
    customBackgroundColorKey,
    customBackgroundColor,
    glassEffect,
    colors,
    spaces
}: MenuDynamicStyle) => {
    const styles = {
        container: {
            backgroundColor: colors.content.container.default,
            ...webStyle({
                WebkitBackdropFilter: `blur(${glassEffect}px)`,
                backdropFilter: `blur(${glassEffect}px)`
            })
        } as Mutable<ViewStyle>,
        headerContainer: {
            paddingHorizontal: spaces.spacingMd,
            paddingTop: spaces.spacingMd
        } as Mutable<ViewStyle>,
        seperator: {
            marginVertical: spaces.spacingMd
        } as Mutable<ViewStyle>
    };

    if(customBackgroundColor) {
        styles.container.backgroundColor = customBackgroundColor;
    }

    if(customBackgroundColorKey) {
        styles.container.backgroundColor = colors.project[customBackgroundColorKey];
    }

    return styles;
};

export default stylesheet;
