"use client"; import { useState, useMemo } from "react"; import StopTableClient from "@/components/admin/StopTableClient"; import StopsCalendarClient from "@/components/admin/StopsCalendarClient"; import { AdminSearchInput, AdminFilterTabs } from "@/components/admin/design-system"; export type StopStatusFilter = "all" | "active" | "inactive" | "draft"; export type StopsViewMode = "calendar" | "table"; export type StopForView = { id: string; city: string; state: string; date: string; time: string; location: string; active: boolean; brand_id: string; status?: string; address?: string | null; zip?: string | null; cutoff_time?: string | null; brands: { name: string } | { name: string }[]; }; type Props = { stops: StopForView[]; }; export default function StopsViewClient({ stops }: Props) { const [view, setView] = useState("calendar"); const [search, setSearch] = useState(""); const [statusFilter, setStatusFilter] = useState("all"); // Apply shared filter so both views agree on what's visible const filtered = useMemo(() => { const q = search.trim().toLowerCase(); return stops.filter((s) => { const matchesSearch = !q || s.city.toLowerCase().includes(q) || s.state.toLowerCase().includes(q) || s.location.toLowerCase().includes(q); const isDraft = s.status === "draft"; const matchesStatus = statusFilter === "all" || (statusFilter === "active" && s.active && !isDraft) || (statusFilter === "inactive" && !s.active && !isDraft) || (statusFilter === "draft" && isDraft); return matchesSearch && matchesStatus; }); }, [stops, search, statusFilter]); const counts = useMemo( () => ({ all: stops.length, active: stops.filter((s) => s.active && s.status !== "draft").length, inactive: stops.filter((s) => !s.active && s.status !== "draft").length, draft: stops.filter((s) => s.status === "draft").length, }), [stops] ); const tabs = [ { value: "all", label: "All", count: counts.all }, { value: "active", label: "Active", count: counts.active }, { value: "inactive", label: "Inactive", count: counts.inactive }, { value: "draft", label: "Draft", count: counts.draft }, ]; return ( <> {/* Filter / search / view-toggle bar — shared across both views */}
setStatusFilter(v as StopStatusFilter)} tabs={tabs} size="sm" showCounts /> setSearch(e.target.value)} onClear={() => setSearch("")} showClear className="flex-1 min-w-48 max-w-72" /> {filtered.length} {filtered.length === 1 ? "stop" : "stops"}
{view === "calendar" ? ( ) : ( )} ); }