import { COLORS } from "@/constants/colors";
import { Film } from "@/types/film";
import { Link } from "expo-router";
import React from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";

const FilmItem: React.FC<{ item: Film }> = ({ item }) => {
  const id = item.url.split("/").filter(Boolean).pop();
  return (
    <Link href={`/films/${id}`} asChild>
      <TouchableOpacity>
        <View style={styles.filmItem}>
          <Text style={styles.title}>{item.title}</Text>
          <Text style={styles.details}>Episode: {item.episode_id}</Text>
          <Text style={styles.details}>Released: {item.release_date}</Text>
        </View>
      </TouchableOpacity>
    </Link>
  );
};

export default FilmItem;

const styles = StyleSheet.create({
  filmItem: {
    backgroundColor: COLORS.background,
    padding: 16,
    marginVertical: 8,
    marginHorizontal: 16,
    borderRadius: 8,
  },
  title: {
    fontSize: 18,
    fontWeight: "bold",
    color: COLORS.text,
    marginBottom: 8,
  },
  details: {
    fontSize: 14,
    color: "#fff",
  },
});
