import React, { useEffect, useState } from "react";
import { Button, Dialog, View, Text, TextField } from "react-native-ui-lib";
import { StyleSheet } from "react-native";
import { PanningDirectionsEnum } from "react-native-ui-lib/src/incubator/panView";
import { IBrainDump, useBrainDumpContext } from "@/contexts/DumpContext";
import { Entypo, EvilIcons, Feather, Octicons } from "@expo/vector-icons";
import { TouchableOpacity } from "react-native-gesture-handler";
import PenIcon from "@/assets/svgs/PenIcon";
import BinIcon from "@/assets/svgs/BinIcon";
import DropModalIcon from "@/assets/svgs/DropModalIcon";
import CloseXIcon from "@/assets/svgs/CloseXIcon";

const MoveBrainDump = (props: {
  item: IBrainDump;
  isVisible: boolean;
  setIsVisible: (value: boolean) => void;
}) => {
  const { updateBrainDumpItem, deleteBrainDump } = useBrainDumpContext();
  const [description, setDescription] = useState<string>(
    props.item.description
  );

  useEffect(() => {
    updateBrainDumpItem(props.item.id, { description: description });
  }, [description]);

  return (
    <Dialog
      bottom={true}
      height={"90%"}
      panDirection={PanningDirectionsEnum.DOWN}
      onDismiss={() => props.setIsVisible(false)}
      containerStyle={{
        borderRadius: 10,
        backgroundColor: "white",
        width: "100%",
        alignSelf: "stretch",
        padding: 0,
        paddingTop: 3,
        margin: 0,
      }}
      visible={props.isVisible}
    >
      <View row spread paddingH-10 paddingV-15>
        <Button
          color="#05a8b6"
          style={styles.topBtn}
          iconSource={() => <CloseXIcon />}
          onPress={() => {
            props.setIsVisible(false);
          }}
        />
        <Button
          style={styles.topBtn}
          iconSource={() => <DropModalIcon />}
          onPress={() => {
            props.setIsVisible(false);
          }}
        />
        <View row>
          <Button
            style={styles.topBtn}
            iconSource={() => <PenIcon />}
            onPress={() => {
              console.log("selview");
            }}
          />
          <Button
            style={styles.topBtn}
            marginL-5
            iconSource={() => <BinIcon />}
            onPress={() => {
              deleteBrainDump(props.item.id);
              props.setIsVisible(false);
            }}
          />
        </View>
      </View>
      <View centerH>
        <Text text60R>{props.item.title} </Text>
      </View>
      <View style={styles.divider} />
      <View row marginH-20>
        <Entypo
          name="text"
          size={24}
          color="black"
          style={{ marginBottom: "auto" }}
        />
        <TextField
          textAlignVertical="top"
          multiline
          placeholder="Add description"
          numberOfLines={3}
          value={description}
          onChangeText={(value) => {
            setDescription(value);
          }}
        />
      </View>
      <View style={styles.divider} />
    </Dialog>
  );
};

const styles = StyleSheet.create({
  divider: { height: 1, backgroundColor: "#e4e4e4", marginVertical: 15 },
  gradient: {
    height: "25%",
    position: "absolute",
    bottom: 0,
    width: "100%",
  },
  buttonContainer: {
    position: "absolute",
    bottom: 25,
    width: "100%",
  },
  button: {
    backgroundColor: "rgb(253, 23, 117)",
    paddingVertical: 20,
  },
  topBtn: {
    backgroundColor: "white",
    color: "#05a8b6",
  },
  rotateSwitch: {
    marginLeft: 35,
    marginBottom: 10,
    marginTop: 25,
  },
});

export default MoveBrainDump;
