import { useState } from "react" import { useTranslation } from "react-i18next" import { VisuallyHidden } from "radix-ui" import { Drawer, DrawerContent, DrawerTitle } from "@/components/ui/drawer" import { Button } from "@/components/ui/button" import { ReviewFormFields } from "@/components/review-form-fields" import { SearchOverlay } from "@/components/search-overlay" import type { MovieSelection } from "@/components/search-overlay" import { useLogReview } from "@/hooks/use-diary" import { toast } from "sonner" import { posterUrl } from "@/lib/api/client" import { hapticMedium } from "@/lib/haptics" type LogSheetProps = { open: boolean onOpenChange: (open: boolean) => void } export function LogSheet({ open, onOpenChange }: LogSheetProps) { const { t } = useTranslation() const [movie, setMovie] = useState(null) const [rating, setRating] = useState(0) const [comment, setComment] = useState("") const [watchedAt, setWatchedAt] = useState(new Date()) const [watchMedium, setWatchMedium] = useState() const logMutation = useLogReview() function reset() { setMovie(null) setRating(0) setComment("") setWatchedAt(new Date()) setWatchMedium(undefined) } function handleClose() { onOpenChange(false) reset() } function handleSubmit() { if (!movie || !rating) return logMutation.mutate( { external_metadata_id: movie.external_metadata_id, manual_title: movie.title, manual_release_year: movie.release_year, manual_director: movie.director, rating, comment: comment || undefined, watched_at: watchedAt.toISOString().replace("Z", "").split(".")[0]!, watch_medium: watchMedium, }, { onSuccess: () => { hapticMedium() toast.success(t("logReview.logged", { title: movie.title })) handleClose() }, }, ) } if (open && !movie) { return setMovie(m)} /> } return ( !o && handleClose()}> {t("logReview.title")}
{movie && ( <>
{movie.poster_path && }

{movie.title}

{movie.release_year}{movie.director && ` ยท ${movie.director}`}

{movie.genres.length > 0 &&

{movie.genres.join(", ")}

}
)}
) }