// ── AI Assistant: Job Selector Component ── // Dropdown that fetches and displays job categories from the API. // Allows the user to pick a job, then triggers a Facebook search. "use client" import { useState, useEffect } from "react" import { Briefcase, ChevronDown, Loader2, Search } from "lucide-react" /** A job category returned from the API */ interface Job { job_title: string keywords: string[] industry: string description: string } interface JobSelectorProps { /** Called when a job is selected or cleared (null) */ onSelect: (job: Job | null) => void /** Called when the user clicks the "Search Facebook" button */ onSearch?: (job: Job) => void /** Whether a search is currently in progress */ searching?: boolean } /** * JobSelector — dropdown to pick a job category and initiate a Facebook search. * Fetches available jobs on mount and provides a "Search Facebook" CTA once a job is selected. */ export function JobSelector({ onSelect, onSearch, searching }: JobSelectorProps) { const [jobs, setJobs] = useState([]) const [loading, setLoading] = useState(true) const [open, setOpen] = useState(false) const [selected, setSelected] = useState(null) // ── Fetch available job categories on mount ── useEffect(() => { fetch("/api/ai/jobs") .then((r) => r.json()) .then((data) => setJobs(data.jobs || [])) .catch(() => setJobs([])) .finally(() => setLoading(false)) }, []) // ── Select a job, close dropdown, notify parent ── const handleSelect = (job: Job) => { setSelected(job) setOpen(false) onSelect(job) } return (
{/* ── Dropdown trigger button ── */} {/* ── Dropdown menu — visible when open ── */} {open && ( <> {/* Backdrop to close on click outside */}
setOpen(false)} />
{jobs.map((job, i) => ( ))} {jobs.length === 0 && !loading && (
No job categories loaded
)}
)} {/* ── "Search Facebook" CTA — shown only when a job is selected ── */} {selected && onSearch && ( )}
) }