import {
  usePayoutTableColumns
} from "./chunk-AFQS6E4N.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-KYPPQGGE.js";
import {
  SingleColumnPage
} from "./chunk-H6MYB7GB.js";
import {
  usePayoutTableQuery
} from "./chunk-GR6JUIRU.js";
import {
  usePayouts
} from "./chunk-LAPEZATU.js";

// src/pages/payouts/payout-list/payout-list.tsx
import { Children } from "react";
import { Container, Heading } from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var PayoutListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx(Heading, { level: "h2", children: t("payouts.domain") });
};
var PayoutListActions = ({ children }) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center gap-x-2", children: Children.count(children) > 0 ? children : null });
};
var PayoutListHeader = ({ children }) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(PayoutListTitle, {}),
    /* @__PURE__ */ jsx(PayoutListActions, {})
  ] }) });
};
var PayoutListDataTable = () => {
  const { t } = useTranslation();
  const { searchParams, raw } = usePayoutTableQuery({
    pageSize: PAGE_SIZE
  });
  const { payouts, count, isError, error, isLoading } = usePayouts(
    searchParams,
    {
      placeholderData: keepPreviousData
    }
  );
  const columns = usePayoutTableColumns();
  const { table } = useDataTable({
    data: payouts ?? [],
    columns,
    enablePagination: true,
    count: count ?? 0,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx(
    _DataTable,
    {
      columns,
      table,
      pagination: true,
      navigateTo: (row) => `/payouts/${row.original.id}`,
      count: count ?? 0,
      search: true,
      isLoading,
      pageSize: PAGE_SIZE,
      orderBy: [
        { key: "created_at", label: t("fields.createdAt") },
        { key: "updated_at", label: t("fields.updatedAt") }
      ],
      queryObject: raw,
      noRecords: {
        message: t("payouts.list.empty")
      }
    }
  );
};
var PayoutListTable = ({ children }) => {
  return /* @__PURE__ */ jsx(Container, { className: "divide-y p-0", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(PayoutListHeader, {}),
    /* @__PURE__ */ jsx(PayoutListDataTable, {})
  ] }) });
};
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx(SingleColumnPage, { children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx(PayoutListTable, {}) });
};
var PayoutListPage = Object.assign(Root, {
  Table: PayoutListTable,
  Header: PayoutListHeader,
  HeaderTitle: PayoutListTitle,
  HeaderActions: PayoutListActions,
  DataTable: PayoutListDataTable
});

export {
  PayoutListPage
};
