import { Suspense } from "react";
import DynamicFilter from "@/components/generic-filter";
import { TopupsTable } from "@/components/topups-table";

export default async function Topups({
  searchParams,
}: {
  searchParams: Promise<{
    query: string;
    page: number;
    sortBy: string;
    status: string;
  }>;
}) {
  const query = (await searchParams)?.query || "";

  return (
    <div>
      <div className="flex justify-between items-center border rounded-md border-dashed font-bold title-bg py-4 px-2 mb-4">
        <h3 className="text-sarLinkOrange text-2xl">My Topups</h3>
      </div>
      <div
        id="topup-filters"
        className=" pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
      >
        <DynamicFilter
          inputs={[
            {
              label: "Status",
              name: "status",
              type: "radio-group",
              options: [
                {
                  label: "All",
                  value: "",
                },
                {
                  label: "Pending",
                  value: "PENDING",
                },
                {
                  label: "Cancelled",
                  value: "CANCELLED",
                },
                {
                  label: "Paid",
                  value: "PAID",
                },
              ],
            },
            {
              label: "Topup Expiry",
              name: "is_expired",
              type: "radio-group",
              options: [
                {
                  label: "All",
                  value: "",
                },
                {
                  label: "Expired",
                  value: "true",
                },
                {
                  label: "Not Expired",
                  value: "false",
                },
              ],
            },
            {
              label: "Topup Amount",
              name: "amount",
              type: "dual-range-slider",
              min: 0,
              max: 1000,
              step: 10,
            },
          ]}
        />
      </div>
      <Suspense key={query} fallback={"loading...."}>
        <TopupsTable searchParams={searchParams} />
      </Suspense>
    </div>
  );
}
