import { View, Text, StyleSheet } from "react-native";
import React, { useState } from "react";
import CreateLyricsHeader from "./components/CreateLyricsHeader";
import { BlurView } from "expo-blur";
import { Palette, Style } from "../../styles";
import { FONT_FAMILY } from "../../styles/Fonts";
import ItemContainer from "../../components/ItemContainer/ItemContainer";

const Rhymes = ({ selected: selectedProp, setSelected: setSelectedProp }) => {
  const [internalSelected, setInternalSelected] = useState(null);
  const selected = selectedProp ?? internalSelected;
  const setSelected = setSelectedProp ?? setInternalSelected;

  const onPressSelect = (item) => {
    if (selected === item) {
      setSelected(null);
    } else {
      setSelected(item);
    }
  };

  return (
    <View style={{ flex: 1, gap: 10, marginTop: 16 }}>
      <CreateLyricsHeader title="Avec ou sans rimes" />
      <ItemContainer height={200}>
        <View style={{ gap: 10 }}>
          {["Avec rimes", "Sans rimes", "Mélange des deux"].map(
            (item, index) => {
              const selectedItem = selected === item;

              return (
                <CreateLyricsHeader
                  key={index}
                  onPress={() => onPressSelect(item)}
                  tint={selectedItem ? "default" : "dark"}
                  colors={
                    selectedItem
                      ? ["#FFFFFF00", "#FFFFFF"]
                      : [Palette.tran, Palette.tran]
                  }
                  containerStyle={{
                    ...styles.itemContainer,
                  }}
                >
                  <View
                    style={{
                      height: 40,
                      ...Style.containerCenter,
                      paddingHorizontal: 14,
                    }}
                  >
                    <Text style={styles.dropzone}>{item}</Text>
                  </View>
                </CreateLyricsHeader>
              );
            }
          )}
        </View>
      </ItemContainer>
    </View>
  );
};

export default Rhymes;

const styles = StyleSheet.create({
  itemContainer: {
    height: 54,
    backgroundColor: Palette.glass,
    borderRadius: 14,
    overflow: "hidden",
    shadowColor: "#00000040",
    shadowOffset: {
      width: 0,
      height: 2,
    },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,
    elevation: 5,
  },
  dropzone: {
    fontSize: 16,
    color: Palette.white,
    fontFamily: FONT_FAMILY.InterRegular,
    textAlign: "center",
  },
});
