import React, { useState } from 'react';
import { View, Text, Button, TextInput, StyleSheet } from 'react-native';
import { doc, updateDoc } from 'firebase/firestore';
import { db } from '../config/firebase';

function ProjectDetailsScreen({ route, navigation }: any) {
  const { project } = route.params;
  const [name, setName] = useState(project.name);
  const [status, setStatus] = useState(project.status);

  const updateProject = async () => {
    await updateDoc(doc(db, 'projects', project.id), { name, status });
    alert('Projekt frissítve');
    navigation.goBack();
  };

  const toggleStatus = () => {
    setStatus(status === 'aktív' ? 'lezárt' : 'aktív');
  };

  return (
    <View style={styles.container}>
      <TextInput style={styles.input} value={name} onChangeText={setName} />
      <Text>Státusz: {status}</Text>
      <Button title="Státusz váltás" onPress={toggleStatus} />
      <Button title="Mentés" onPress={updateProject} />
    </View>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, padding: 16 },
  input: { borderWidth: 1, padding: 8, marginBottom: 16, borderRadius: 4 },
});

export default ProjectDetailsScreen;
