import {
    type ViewStyle,
    StyleSheet
} from "react-native";
import type {
    AvatarGroupSizeConstantType,
    AvatarGroupDynamicStyleType,
    AvatarGroupMeasuresKeys,
    AvatarGroupSizeType
} from "./type";
import type {
    Mutable
} from "../../types";

export const AVATAR_GROUP_SIZES: Record<AvatarGroupSizeType, AvatarGroupMeasuresKeys> = {
    xLarge: {
        fontSize: "headlineMediumSize",
        iconSize: 40,
        size: 80
    },
    large: {
        fontSize: "headlineSmallSize",
        iconSize: 32,
        size: 64
    },
    xxxLarge: {
        fontSize: "displayMediumSize",
        iconSize: 76,
        size: 150
    },
    xxLarge: {
        fontSize: "displaySmallSize",
        iconSize: 60,
        size: 120
    },
    xSmall: {
        fontSize: "labelMediumSize",
        iconSize: 18,
        size: 32
    },
    small: {
        fontSize: "labelLargeSize",
        iconSize: 22,
        size: 40
    },
    xxSmall: {
        fontSize: "labelSmallSize",
        iconSize: 14,
        size: 24
    },
    medium: {
        fontSize: "bodyLargeSize",
        iconSize: 26,
        size: 48
    }
};

export const getAvatarGroupSize = ({
    size
}: AvatarGroupSizeConstantType): AvatarGroupMeasuresKeys => {
    const currentSize = AVATAR_GROUP_SIZES[size];

    return {
        fontSize: currentSize.fontSize,
        iconSize: currentSize.iconSize,
        size: currentSize.size
    };
};

const stylesheet = StyleSheet.create({
    iconContainer: {
        justifyContent: "center",
        alignItems: "center"
    },
    moreAvatarsContainer: {
        justifyContent: "center",
        alignItems: "center"
    },
    container: {
        flexDirection: "row",
        position: "relative"
    },
    icon: {
    }
});

export const useStyles = ({
    avatarBackgroundColor,
    borderColor,
    currentSize,
    isDisabled,
    isLoading,
    avatars,
    borders,
    colors
}: AvatarGroupDynamicStyleType) => {
    const styles = {
        iconContainer: {
            borderColor: borderColor ? borderColor === "transparent" ? "transparent" : colors.content.border[borderColor] : avatarBackgroundColor ? colors.content.container[avatarBackgroundColor] : colors.content.container.default,
            transform: [
                {
                    translateX: avatars && avatars.length === 1 ? 0 : (currentSize.size / 3) * -1
                }
            ],
            backgroundColor: colors.content.container.subtle,
            borderRadius: currentSize.size / 2,
            borderWidth: borders.subtract,
            height: currentSize.size,
            width: currentSize.size
        } as Mutable<ViewStyle>,
        moreAvatarsContainer: {
            borderColor: borderColor ? borderColor === "transparent" ? "transparent" : colors.content.border[borderColor] : avatarBackgroundColor ? colors.content.container[avatarBackgroundColor] : colors.content.container.default,
            backgroundColor: colors.content.container.subtle,
            transform: [
                {
                    translateX: (currentSize.size / 1.5) * -1
                }
            ],
            borderRadius: currentSize.size / 2,
            borderWidth: borders.subtract,
            height: currentSize.size,
            width: currentSize.size
        } as Mutable<ViewStyle>,
        container: {
        } as Mutable<ViewStyle>,
        icon: {
        } as Mutable<ViewStyle>,
        avatar: {
        } as Mutable<ViewStyle>
    };

    if(isDisabled) {
        styles.container.opacity = 0.33;
    }

    if(isLoading) {
        styles.container.opacity = 0.33;
    }

    return styles;
};
export default stylesheet;
