import {
  useOrderTableColumns
} from "./chunk-HRUO43BZ.js";
import {
  useOrderTableQuery
} from "./chunk-XBKWFLJG.js";
import {
  useOrderTableFilters
} from "./chunk-5ALC4Z2H.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import {
  useOrders
} from "./chunk-DIAWPVYS.js";

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

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

// src/pages/orders/_components/order-list-table/order-list-header.tsx
import { Children } from "react";
import { useTranslation } from "react-i18next";
import { Heading } from "@medusajs/ui";
import { jsx } from "react/jsx-runtime";
var OrderListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx(Heading, { children: t("orders.domain") });
};
var OrderListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : null });
};
var OrderListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx(OrderListTitle, {}) });
};

// src/pages/orders/_components/order-list-table/order-list-data-table.tsx
import { useMemo } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
import { useExtendableTable, useLinkQuery } from "@mercurjs/dashboard-shared";
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var OrderListDataTable = () => {
  const { t } = useTranslation2();
  const { raw, searchParams } = useOrderTableQuery({
    pageSize: PAGE_SIZE
  });
  const linkQuery = useLinkQuery(
    "order",
    [
      "id",
      "status",
      "created_at",
      "email",
      "display_id",
      "custom_display_id",
      "payment_status",
      "fulfillment_status",
      "total",
      "currency_code",
      "*customer",
      "*payment_collections"
    ].join(",")
  );
  const { orders, count, isError, error, isLoading } = useOrders({
    ...linkQuery,
    ...searchParams
  });
  const baseColumns = useOrderTableColumns({});
  const baseFilters = useOrderTableFilters();
  const { columns, filters: extFilters } = useExtendableTable({
    model: "order",
    columns: baseColumns
  });
  const filters = useMemo(
    () => [...baseFilters, ...extFilters],
    [baseFilters, extFilters]
  );
  const { table } = useDataTable({
    data: orders ?? [],
    columns,
    enablePagination: true,
    count,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(
    _DataTable,
    {
      columns,
      table,
      pagination: true,
      search: true,
      filters,
      navigateTo: (row) => `/orders/${row.original.id}`,
      count,
      isLoading,
      pageSize: PAGE_SIZE,
      orderBy: [
        {
          key: "display_id",
          label: t("orders.fields.displayId")
        },
        {
          key: "created_at",
          label: t("fields.createdAt")
        },
        {
          key: "updated_at",
          label: t("fields.updatedAt")
        }
      ],
      defaultOrderBy: "-display_id",
      queryObject: raw,
      noRecords: {
        message: t("orders.list.noRecordsMessage")
      }
    }
  );
};

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

// src/pages/orders/order-list-page.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { children: /* @__PURE__ */ jsx4(WidgetZone, { id: "orders.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(OrderListTable, {}) }) });
};
var OrderListPage = Object.assign(Root, {
  Table: OrderListTable,
  Header: OrderListHeader,
  HeaderTitle: OrderListTitle,
  HeaderActions: OrderListActions,
  DataTable: OrderListDataTable
});

export {
  OrderListPage
};
