"use client"; import { useState } from "react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { api } from "@/lib/api"; export function SearchRequestModal({ open, onOpenChange, costs, }: { open: boolean; onOpenChange: (open: boolean) => void; costs: { movie: number; tv: number }; }) { const [query, setQuery] = useState(""); const [results, setResults] = useState([]); const [loading, setLoading] = useState(false); const search = async () => { setLoading(true); try { const res = await api.get( `/overseer/search?query=${encodeURIComponent(query)}`, ); setResults(res.data?.results || res.data || []); } catch { toast.error("Search failed"); } finally { setLoading(false); } }; const request = async (item: any, mediaType: string) => { try { await api.post("/overseer/request", { mediaType, mediaId: item.id || item.tmdbId, title: item.title || item.name, seasons: item.seasons, }); toast.success("Request sent"); onOpenChange(false); } catch (e: any) { toast.error(e?.response?.data?.error || "Request failed"); } }; return ( Request content Search and send request. Movie cost {costs.movie}. TV cost{" "} {costs.tv}.
setQuery(e.target.value)} placeholder="Search movie or show" />
{results.map((r) => (
{r.title || r.name}
{r.media_type || r.mediaType}
))}
); }