"use client";

import { useQuery } from "@tanstack/react-query";
import { beautyBusinessApi } from "@/modules/beauty/services/beauty-business-api";
import { useTenantId } from "@/hooks/useTenantId";
import {
  PageHeader,
  DataTable,
  EmptyState,
  LoadingState,
  ErrorState,
} from "@/components/ds";

export default function WaitingListPage() {
  const { tenantId } = useTenantId();

  const listQ = useQuery({
    queryKey: ["beauty", tenantId, "waiting-list"],
    queryFn: () => beautyBusinessApi.waitingList.list(tenantId!),
    enabled: !!tenantId,
  });

  if (!tenantId || listQ.isLoading) return <LoadingState />;
  if (listQ.error) {
    return <ErrorState message={listQ.error.message} onRetry={() => listQ.refetch()} />;
  }

  return (
    <div>
      <PageHeader title="لیست انتظار" description="درخواست‌های در صف نوبت." />
      <DataTable
        columns={[
          { key: "code", header: "کد" },
          { key: "customer_ref", header: "مشتری" },
          { key: "requested_date", header: "تاریخ درخواست" },
          { key: "priority", header: "اولویت" },
          { key: "notes", header: "یادداشت" },
        ]}
        rows={(listQ.data ?? []) as unknown as Record<string, unknown>[]}
        empty={<EmptyState title="موردی در لیست انتظار نیست" />}
      />
    </div>
  );
}
