import { Ionicons } from "@expo/vector-icons"; import { useRouter } from "expo-router"; import { useCallback, useState } from "react"; import { useTranslation } from "react-i18next"; import { ActivityIndicator, KeyboardAvoidingView, Platform, ScrollView, Switch, TextInput, TouchableOpacity, View, } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Button } from "@/components/Button"; import { Text } from "@/components/common/Text"; import { useCreateWatchlist } from "@/hooks/useWatchlistMutations"; import type { StreamystatsWatchlistAllowedItemType, StreamystatsWatchlistSortOrder, } from "@/utils/streamystats/types"; const ITEM_TYPES: Array<{ value: StreamystatsWatchlistAllowedItemType; label: string; }> = [ { value: null, label: "All Types" }, { value: "Movie", label: "Movies Only" }, { value: "Series", label: "Series Only" }, { value: "Episode", label: "Episodes Only" }, ]; const SORT_OPTIONS: Array<{ value: StreamystatsWatchlistSortOrder; label: string; }> = [ { value: "custom", label: "Custom Order" }, { value: "name", label: "Name" }, { value: "dateAdded", label: "Date Added" }, { value: "releaseDate", label: "Release Date" }, ]; export default function CreateWatchlistScreen() { const { t } = useTranslation(); const router = useRouter(); const insets = useSafeAreaInsets(); const createWatchlist = useCreateWatchlist(); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [isPublic, setIsPublic] = useState(false); const [allowedItemType, setAllowedItemType] = useState(null); const [defaultSortOrder, setDefaultSortOrder] = useState("custom"); const handleCreate = useCallback(async () => { if (!name.trim()) return; try { await createWatchlist.mutateAsync({ name: name.trim(), description: description.trim() || undefined, isPublic, allowedItemType, defaultSortOrder, }); router.back(); } catch { // Error handled by mutation } }, [ name, description, isPublic, allowedItemType, defaultSortOrder, createWatchlist, router, ]); return ( {/* Name */} {t("watchlists.name_label")} * {/* Description */} {t("watchlists.description_label")} {/* Public Toggle */} {t("watchlists.is_public_label")} {t("watchlists.is_public_description")} {/* Content Type */} {t("watchlists.allowed_type_label")} {ITEM_TYPES.map((type) => ( setAllowedItemType(type.value)} className={`px-4 py-2 rounded-lg ${allowedItemType === type.value ? "bg-purple-600" : "bg-neutral-800"}`} > {type.label} ))} {/* Sort Order */} {t("watchlists.sort_order_label")} {SORT_OPTIONS.map((sort) => ( setDefaultSortOrder(sort.value)} className={`px-4 py-2 rounded-lg ${defaultSortOrder === sort.value ? "bg-purple-600" : "bg-neutral-800"}`} > {sort.label} ))} {/* Create Button */} ); }