"use client"; import { Archive, ArchiveRestore, EllipsisVertical, Globe, MapPin, Pencil, Plus, ShoppingBasket, Store, Utensils, } from "lucide-react"; import { useMemo, useState } from "react"; import { toast } from "sonner"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { tr } from "@/i18n/tr"; import { cn } from "@/lib/utils"; import { formatMoney } from "@/shared/format"; import { formatDistance, sortStores, STORE_SORTS, type StoreKind, type StoreSort, } from "@/shared/stores"; import { setStoreArchivedAction } from "../actions"; import type { StoreView } from "../service"; import { StoreFormDialog } from "./store-dialog"; const t = tr.stores; const KIND_ICON: Record = { market: Store, online: Globe, bazaar: ShoppingBasket, }; /** Zahmet çubuğu: 0–100, düzey etiketiyle (renk tek başına anlam taşımaz). */ function EffortMeter({ store }: { store: StoreView }) { return (
{t.effort}
{store.effort} · {t.effortLevels[store.effortLevel]}
); } /** /magazalar: sıralama (ad, en yakın, en uzak, en zahmetli), kartlar, ekle/düzenle/arşivle. */ export function StoresView({ stores, canWrite }: { stores: StoreView[]; canWrite: boolean }) { const [sort, setSort] = useState("name"); const [showArchived, setShowArchived] = useState(false); const [editing, setEditing] = useState(null); const [archiving, setArchiving] = useState(null); const visible = useMemo( () => sortStores( stores.filter((s) => showArchived || !s.archived), sort, ), [stores, sort, showArchived], ); const hasArchived = stores.some((s) => s.archived); async function setArchived(store: StoreView, archived: boolean) { const r = await setStoreArchivedAction(store.id, archived); if (r.ok) toast.success(archived ? t.toast.archived : t.toast.unarchived); else toast.error(r.error); } return (
{hasArchived ? ( ) : null} {canWrite ? ( ) : null}
{visible.length === 0 ? (

{t.empty}

) : (
    {visible.map((s) => { const Icon = KIND_ICON[s.kind]; return (
  • {s.name}

    {[t.kindShort[s.kind], s.branch].filter(Boolean).join(" · ")}

    {canWrite ? ( setEditing(s)}> {t.actions.edit} {s.archived ? ( setArchived(s, false)}> {t.actions.unarchive} ) : ( setArchiving(s)}> {t.actions.archive} )} ) : null}
    {s.kind === "online" ? ( {s.deliveryFeeMinor ? t.delivery(formatMoney(s.deliveryFeeMinor)) : t.freeDelivery} {s.deliveryFeeMinor && s.freeDeliveryMinMinor ? ` · ${t.freeDeliveryFrom(formatMoney(s.freeDeliveryMinMinor))}` : ""} ) : ( {s.distanceM !== null ? formatDistance(s.distanceM) : t.distanceUnknown} )} {t.fields.carry}: {s.carryDifficulty} · {t.carryLevels[s.carryDifficulty]}
    {s.archived ? {t.archived} : null} {s.mealCardAccepted ? ( {t.mealCardBadge}:{" "} {s.mealCardProviders.map((p) => tr.accounts.providers[p]).join(", ")} ) : null}
    {s.note ?

    {s.note}

    : null}
  • ); })}
)} {editing ? ( setEditing(null)} /> ) : null} !o && setArchiving(null)}> {t.archiveTitle} {archiving ? t.archiveDescription(archiving.label) : null} {tr.common.cancel}
); }