import { Colors } from "@/constants/Colors";
import { TabItem } from "@/services/base";
import { Image } from "expo-image";
import React from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";

// 小程序 item 宽度 162rpx = 81pt
const ITEM_WIDTH = 81;

interface QuickEntryProps {
  data: TabItem[];
  onPress?: (item: TabItem) => void;
}

export function QuickEntry({ data, onPress }: QuickEntryProps) {
  return (
    <View style={styles.container}>
      <View style={styles.center}>
        {data.map((item, index) => (
          <TouchableOpacity
            key={index}
            style={styles.item}
            activeOpacity={0.7}
            onPress={() => onPress?.(item)}
          >
            <View style={styles.itemBox}>
              <Image
                source={item.cover}
                style={styles.icon}
                contentFit="contain"
              />
              <Text style={styles.title}>{item.title}</Text>
            </View>
          </TouchableOpacity>
        ))}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    width: "100%",
    marginTop: 10,
    marginBottom: 5,
    paddingHorizontal: 10,
  },
  center: {
    width: "100%",
    flexDirection: "row",
    flexWrap: "wrap",
    justifyContent: "space-around",
  },
  item: {
    width: ITEM_WIDTH,
    alignItems: "center",
  },
  itemBox: {
    alignItems: "center",
    // Glow effect for icons
    shadowColor: Colors.neonBlue,
    shadowOffset: { width: 0, height: 0 },
    shadowOpacity: 0.3,
    shadowRadius: 5,
  },
  icon: {
    width: 48, // Reduced slightly from ITEM_WIDTH to fit better
    height: 48,
    marginBottom: 4,
  },
  title: {
    fontSize: 11,
    fontWeight: "500",
    color: Colors.textSecondary,
    textShadowColor: "rgba(0, 243, 255, 0.3)",
    textShadowOffset: { width: 0, height: 0 },
    textShadowRadius: 3,
  },
});
