import {
  usePayoutTableColumns
} from "./chunk-Y6S7K3YB.js";
import {
  usePayoutTableQuery
} from "./chunk-N3T24SEK.js";
import {
  usePayoutTableFilters
} from "./chunk-UAE6XBYL.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import {
  usePayouts
} from "./chunk-J2XUEO2E.js";

// src/pages/payouts/payout-list-page.tsx
import { Children as Children3 } from "react";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/payouts/_components/payout-list-table/payout-list-table.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";

// src/pages/payouts/_components/payout-list-table/payout-list-header.tsx
import { Children } from "react";
import { Heading } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx } from "react/jsx-runtime";
var PayoutListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx(Heading, { children: t("payouts.domain") });
};
var PayoutListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-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__ */ jsx(PayoutListTitle, {}) });
};

// src/pages/payouts/_components/payout-list-table/payout-list-data-table.tsx
import { useMemo } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
import { keepPreviousData } from "@tanstack/react-query";
import { useExtendableTable } from "@mercurjs/dashboard-shared";
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var PayoutListDataTable = () => {
  const { t } = useTranslation2();
  const { raw, searchParams } = usePayoutTableQuery({
    pageSize: PAGE_SIZE
  });
  const { payouts, count, isError, error, isLoading } = usePayouts(
    searchParams,
    {
      initialData: keepPreviousData
    }
  );
  const base = usePayoutTableColumns();
  const { columns, filters: extFilters } = useExtendableTable({
    model: "payout",
    columns: base
  });
  const baseFilters = usePayoutTableFilters();
  const filters = useMemo(
    () => [...baseFilters, ...extFilters],
    [baseFilters, extFilters]
  );
  const { table } = useDataTable({
    data: payouts ?? [],
    columns,
    enablePagination: true,
    count,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(
    _DataTable,
    {
      columns,
      table,
      pagination: true,
      filters,
      navigateTo: (row) => `/payouts/${row.original.id}`,
      count,
      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.noRecords")
      }
    }
  );
};

// src/pages/payouts/_components/payout-list-table/payout-list-table.tsx
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
var PayoutListTable = ({ children }) => {
  return /* @__PURE__ */ jsx3(Container, { className: "divide-y p-0", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx3(PayoutListHeader, {}),
    /* @__PURE__ */ jsx3(PayoutListDataTable, {})
  ] }) });
};

// src/pages/payouts/payout-list-page.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { children: /* @__PURE__ */ jsx4(WidgetZone, { id: "payouts.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(PayoutListTable, {}) }) });
};
var PayoutListPage = Object.assign(Root, {
  Table: PayoutListTable,
  Header: PayoutListHeader,
  HeaderTitle: PayoutListTitle,
  HeaderActions: PayoutListActions,
  DataTable: PayoutListDataTable
});

export {
  PayoutListPage
};
