import { AreaRiservataLayout } from "~/components/Layout";
import { LoadingPage } from "~/components/loading";
import type { NextPageWithLayout } from "~/pages/_app";
import { RefreshCcw } from "lucide-react";
import { api } from "~/utils/api";
import { Status500 } from "~/components/status-page";
import { AnnunciTable } from "~/components/tables/annunci-tables";

const Admin_Annunci: NextPageWithLayout = () => {
  const { data, isLoading, refetch } = api.annunci.getAnnunciList.useQuery();
  if (isLoading) return <LoadingPage />;
  if (!data) return <Status500 />;
  return (
    <div className="mx-1 flex-1 overflow-auto">
      <div className="mx-auto pt-4">
        <div className="mx-3 items-start justify-between md:flex">
          <div className="flex max-w-lg items-center gap-3">
            <h3 className="text-2xl font-bold">Annunci</h3>
            <button onClick={async () => await refetch()}>
              <RefreshCcw className="size-6" />
            </button>
          </div>
        </div>
        <AnnunciTable data={data} />
      </div>
    </div>
  );
};

export default Admin_Annunci;

Admin_Annunci.getLayout = function getLayout(page) {
  return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
};
