"use client";
import { useState, useEffect } from "react";
import { createPortal } from "react-dom";
import { Loader2, Trash2, Phone, Instagram, Send, X } from "lucide-react";
import { type BookingStatus, type BookingFilter, BOOKING_STATUSES } from "./types";
export function LoadingSpinner() {
return (
Загрузка...
);
}
export function EmptyState({ total }: { total: number }) {
return (
{total === 0 ? "Пока нет записей" : "Нет записей по фильтру"}
);
}
// --- #1: Delete with confirmation ---
export function DeleteBtn({ onClick, name }: { onClick: () => void; name?: string }) {
const [confirming, setConfirming] = useState(false);
useEffect(() => {
if (!confirming) return;
function onKey(e: KeyboardEvent) { if (e.key === "Escape") setConfirming(false); }
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
}, [confirming]);
return (
<>
{confirming && createPortal(
setConfirming(false)}>
e.stopPropagation()}>
Удалить запись?
{name &&
{name}
}
Это действие нельзя отменить.
,
document.body
)}
>
);
}
export function ContactLinks({ phone, instagram, telegram }: { phone?: string; instagram?: string; telegram?: string }) {
return (
<>
{phone && (
{phone}
)}
{instagram && (
{instagram}
)}
{telegram && (
{telegram}
)}
>
);
}
export function FilterTabs({ filter, counts, total, onFilter }: {
filter: BookingFilter;
counts: Record;
total: number;
onFilter: (f: BookingFilter) => void;
}) {
return (
{BOOKING_STATUSES.map((s) => (
))}
);
}
export function StatusBadge({ status }: { status: BookingStatus }) {
const conf = BOOKING_STATUSES.find((s) => s.key === status) || BOOKING_STATUSES[0];
return (
{conf.label}
);
}
export function StatusActions({ status, onStatus }: { status: BookingStatus; onStatus: (s: BookingStatus) => void }) {
const actionBtn = (label: string, onClick: () => void, cls: string) => (
);
return (
{status === "new" && actionBtn("Связались →", () => onStatus("contacted"), "bg-blue-500/10 text-blue-400 border border-blue-500/30 hover:bg-blue-500/20")}
{status === "contacted" && (
<>
{actionBtn("Подтвердить", () => onStatus("confirmed"), "bg-emerald-500/10 text-emerald-400 border border-emerald-500/30 hover:bg-emerald-500/20")}
{actionBtn("Отказ", () => onStatus("declined"), "bg-red-500/10 text-red-400 border border-red-500/30 hover:bg-red-500/20")}
>
)}
{(status === "confirmed" || status === "declined") && actionBtn("Вернуть", () => onStatus("contacted"), "bg-neutral-800/50 text-neutral-500 border border-transparent hover:border-white/10 hover:text-neutral-300")}
);
}
export function BookingCard({ status, children }: { status: BookingStatus; children: React.ReactNode }) {
return (
{children}
);
}