import { TargetItem } from '@/types/user';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import Modal from 'react-native-modal';
import Cascader, { CascaderItem } from '../cascader';

interface ClassifyModalProps {
    modalVisible: boolean;
    setModalVisible: (visible: boolean) => void;
    podiumPosition: { x: number, y: number, width: number, height: number };
    handleChange: (selectedItems: CascaderItem[]) => void;
    data: TargetItem[];
}
const ClassifyModal = (props: ClassifyModalProps) => {
    const { modalVisible, setModalVisible, podiumPosition, handleChange, data } = props;
    const { t } = useTranslation();
    return (
        <Modal
            isVisible={modalVisible}
            onBackdropPress={() => setModalVisible(false)}
            swipeDirection="right" // 支持向右滑动关闭
            propagateSwipe={true}
            animationIn="slideInRight"     // 入场动画
            animationOut="slideOutRight"   // 出场动画
            backdropOpacity={0.5}
            onSwipeComplete={() => setModalVisible(false)}
            style={{ margin: 0, justifyContent: 'flex-start', marginTop: podiumPosition.height + podiumPosition.y }}
        >
            <View style={styles.modalView}>
                <View style={styles.modalHeader}>
                    <Text style={{ opacity: 0 }}>Settings</Text>
                    <Text style={styles.modalTitle}>{t('generalSetting.classify', { ns: 'personal' })}</Text>
                    <TouchableOpacity onPress={() => setModalVisible(false)}>
                        <Text style={styles.closeButton}>×</Text>
                    </TouchableOpacity>
                </View>
                <ScrollView style={styles.modalContent} showsVerticalScrollIndicator={false}>
                    <Cascader
                        data={data}
                        onChange={handleChange}
                    />
                </ScrollView>
                <TouchableOpacity
                    style={styles.confirmButton}
                    onPress={() => {
                        setModalVisible(false)
                    }}
                    activeOpacity={0.8}
                >
                    <Text className="text-[#fff] font-bold text-lg">
                        {t('generalSetting.confirm', { ns: 'personal' })}
                    </Text>
                </TouchableOpacity>
            </View>
        </Modal>
    );
};

const styles = StyleSheet.create({
    modalView: {
        width: '100%',
        height: '60%',
        backgroundColor: 'white',
        borderRadius: 24,
        paddingVertical: 16,
    },
    modalHeader: {
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
        marginBottom: 20,
        borderBottomWidth: 1,
        borderBottomColor: '#E5E5E5',
    },
    modalTitle: {
        fontSize: 20,
        fontWeight: 'bold',
        color: '#4C320C',
    },
    closeButton: {
        fontSize: 28,
        color: '#4C320C',
        padding: 10,
    },
    modalContent: {
        flex: 1,
        paddingHorizontal: 16,
    },
    modalText: {
        fontSize: 16,
        color: '#4C320C',
    },
    premium: {
        backgroundColor: "#FAF9F6",
        padding: 16,
        borderRadius: 24,
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
    },
    content: {
        flex: 1,
        flexDirection: 'column',
        gap: 4,
        backgroundColor: '#FAF9F6',
        borderRadius: 24,
        paddingVertical: 8
    },
    item: {
        paddingHorizontal: 16,
        paddingVertical: 8,
        flexDirection: 'row',
        justifyContent: 'space-between',
        alignItems: 'center',
    },
    itemText: {
        fontSize: 14,
        fontWeight: '600',
        color: '#4C320C',
    },
    upgradeButton: {
        backgroundColor: '#E2793F',
        borderRadius: 20,
        paddingHorizontal: 16,
        paddingVertical: 8,
    },
    upgradeButtonText: {
        color: '#fff',
        fontSize: 14,
        fontWeight: "600"
    },
    switchContainer: {
        width: 50,
        height: 30,
        borderRadius: 15,
        justifyContent: 'center',
        paddingHorizontal: 2,
    },
    switchOn: {
        backgroundColor: '#E2793F',
        alignItems: 'flex-end',
    },
    switchOff: {
        backgroundColor: '#E5E5E5',
        alignItems: 'flex-start',
    },
    switchCircle: {
        width: 26,
        height: 26,
        borderRadius: 13,
    },
    switchCircleOn: {
        backgroundColor: 'white',
    },
    switchCircleOff: {
        backgroundColor: '#A5A5A5',
    },
    confirmButton: {
        backgroundColor: '#E2793F',
        borderRadius: 20,
        paddingHorizontal: 16,
        paddingVertical: 8,
        marginHorizontal: 16,
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
    },
});

export default ClassifyModal;