import {
  useOrderTableColumns
} from "./chunk-5O7HGXFV.mjs";
import {
  ConfigurableDataTable,
  createTableAdapter,
  orderColumnAdapter
} from "./chunk-OLKB5HXC.mjs";
import "./chunk-5LFJGD27.mjs";
import "./chunk-EJWRAUTW.mjs";
import "./chunk-NTEWUH4C.mjs";
import "./chunk-INE2QCSC.mjs";
import "./chunk-V2CZ23VK.mjs";
import "./chunk-IQBAUTU5.mjs";
import "./chunk-ADOCJB6L.mjs";
import "./chunk-X6BAAGCL.mjs";
import "./chunk-P3UUX2T6.mjs";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TWTWTDT.mjs";
import "./chunk-HQKGZADC.mjs";
import "./chunk-EMIHDNB7.mjs";
import "./chunk-DK4WIVY6.mjs";
import "./chunk-3C6WQ7NH.mjs";
import "./chunk-CBSCX7RE.mjs";
import "./chunk-LT4MVCA7.mjs";
import "./chunk-FUIT667Y.mjs";
import {
  useOrderTableQuery
} from "./chunk-UVGVVAR4.mjs";
import {
  useOrderTableFilters
} from "./chunk-AIJV4VQQ.mjs";
import "./chunk-W7625H47.mjs";
import "./chunk-DLZWPHHO.mjs";
import "./chunk-4DZUJIAL.mjs";
import "./chunk-Q6PYDJZC.mjs";
import "./chunk-XRM7PIRS.mjs";
import {
  SingleColumnPage
} from "./chunk-GIZFNLKK.mjs";
import {
  useDataTableDateFilters
} from "./chunk-V2OKIIO7.mjs";
import "./chunk-327JQRJK.mjs";
import "./chunk-C76H5USB.mjs";
import "./chunk-3BQAAPDR.mjs";
import "./chunk-MNXC6Q4F.mjs";
import "./chunk-DG7J63J2.mjs";
import {
  useFeatureFlag
} from "./chunk-PJU3RODH.mjs";
import {
  useExtension
} from "./chunk-C5P5PL3E.mjs";
import "./chunk-LPEUYMRK.mjs";
import "./chunk-OZPB6JBL.mjs";
import "./chunk-OC7BQLYI.mjs";
import "./chunk-S4DMV3ZT.mjs";
import "./chunk-QJ63TWAK.mjs";
import "./chunk-OW2UL5FI.mjs";
import "./chunk-5DUV4AET.mjs";
import "./chunk-FAB3VINY.mjs";
import "./chunk-Q7YBE4IP.mjs";
import "./chunk-HI6URQ7H.mjs";
import "./chunk-6CLQKVAU.mjs";
import "./chunk-KI7TOXBR.mjs";
import "./chunk-QBIQEVTU.mjs";
import "./chunk-WAXMT4IY.mjs";
import "./chunk-DYDGGABK.mjs";
import "./chunk-LGNTHZ5Y.mjs";
import "./chunk-CN7JXSGW.mjs";
import "./chunk-AO2USOOE.mjs";
import "./chunk-KWWLGCSY.mjs";
import "./chunk-5AFMB7XQ.mjs";
import "./chunk-5U6AZEO7.mjs";
import "./chunk-A63RZVX6.mjs";
import "./chunk-HBXV7ENS.mjs";
import {
  useOrders
} from "./chunk-ZBMENGLV.mjs";
import "./chunk-LGLPAUIO.mjs";
import "./chunk-CDORR33H.mjs";
import "./chunk-DE44HCDH.mjs";
import {
  useSalesChannels
} from "./chunk-MUOBXNL6.mjs";
import "./chunk-BEQ5XTWH.mjs";
import {
  useRegions
} from "./chunk-HP2JH45P.mjs";
import "./chunk-VCSSQVPD.mjs";
import "./chunk-SQDIZZDW.mjs";
import "./chunk-LA2ILUXH.mjs";
import "./chunk-7AXHHXCX.mjs";
import "./chunk-FXYH54JP.mjs";
import "./chunk-774WSTCC.mjs";
import "./chunk-NFEK63OE.mjs";
import "./chunk-QZ7TP4HQ.mjs";

// src/routes/orders/order-list/components/order-list-table/order-list-table.tsx
import { Button, Container, Heading } from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { Link, Outlet, useLocation } from "react-router-dom";

// src/routes/orders/order-list/const.ts
var DEFAULT_PROPERTIES = [
  "id",
  "status",
  "created_at",
  "email",
  "display_id",
  "custom_display_id",
  "payment_status",
  "fulfillment_status",
  "total",
  "currency_code"
];
var DEFAULT_RELATIONS = [
  "*customer",
  "*sales_channel",
  "*payment_collections"
];
var DEFAULT_FIELDS = `${DEFAULT_PROPERTIES.join(
  ","
)},${DEFAULT_RELATIONS.join(",")}`;

// src/routes/orders/order-list/components/order-list-table/order-list-table.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var OrderListTable = () => {
  const { t } = useTranslation();
  const location = useLocation();
  const { searchParams, raw } = useOrderTableQuery({
    pageSize: PAGE_SIZE
  });
  const { orders, count, isError, error, isLoading } = useOrders(
    {
      fields: DEFAULT_FIELDS,
      ...searchParams
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const filters = useOrderTableFilters();
  const columns = useOrderTableColumns({});
  const { table } = useDataTable({
    data: orders ?? [],
    columns,
    enablePagination: true,
    count,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsx(Heading, { children: t("orders.domain") }),
      /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: `export${location.search}`, children: t("actions.export") }) })
    ] }),
    /* @__PURE__ */ jsx(
      _DataTable,
      {
        columns,
        table,
        pagination: true,
        navigateTo: (row) => `/orders/${row.original.id}`,
        filters,
        count,
        search: true,
        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") }
        ],
        queryObject: raw,
        noRecords: {
          message: t("orders.list.noRecordsMessage")
        }
      }
    ),
    /* @__PURE__ */ jsx(Outlet, {})
  ] });
};

// src/routes/orders/order-list/components/order-list-table/configurable-order-list-table.tsx
import { useTranslation as useTranslation3 } from "react-i18next";
import { Outlet as Outlet2, useLocation as useLocation2 } from "react-router-dom";

// src/routes/orders/order-list/components/order-list-table/order-table-adapter.tsx
import { useMemo } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
import { createDataTableFilterHelper } from "@medusajs/ui";
function createOrderTableAdapter() {
  return createTableAdapter({
    entity: "orders",
    queryPrefix: "o",
    pageSize: 20,
    columnAdapter: orderColumnAdapter,
    useData: (fields, params) => {
      const { orders, count, isError, error, isLoading } = useOrders(
        {
          fields,
          ...params
        },
        {
          placeholderData: (previousData, previousQuery) => {
            const prevFields = (
              // @ts-ignore not sure what the expected type here is
              previousQuery?.[previousQuery?.length - 1]?.query?.fields
            );
            if (prevFields && prevFields !== fields) {
              return void 0;
            }
            return previousData;
          }
        }
      );
      return {
        data: orders,
        count,
        isLoading,
        isError,
        error
      };
    },
    getRowHref: (row) => `/orders/${row.id}`,
    emptyState: {
      empty: {
        heading: "No orders found"
      }
    }
  });
}
var filterHelper = createDataTableFilterHelper();
var useOrderTableFilters2 = () => {
  const { t } = useTranslation2();
  const dateFilters = useDataTableDateFilters();
  const { regions } = useRegions({
    limit: 1e3,
    fields: "id,name"
  });
  const { sales_channels } = useSalesChannels({
    limit: 1e3,
    fields: "id,name"
  });
  return useMemo(() => {
    const filters = [
      filterHelper.accessor("total", {
        label: t("fields.total"),
        type: "number"
      }),
      ...dateFilters
    ];
    if (regions?.length) {
      filters.push(
        filterHelper.accessor("region_id", {
          label: t("fields.region"),
          type: "multiselect",
          searchable: true,
          options: regions.map((r) => ({
            label: r.name,
            value: r.id
          }))
        })
      );
    }
    if (sales_channels?.length) {
      filters.push(
        filterHelper.accessor("sales_channel_id", {
          label: t("fields.salesChannel"),
          type: "multiselect",
          searchable: true,
          options: sales_channels.map((s) => ({
            label: s.name,
            value: s.id
          }))
        })
      );
    }
    return filters;
  }, [regions, sales_channels, dateFilters, t]);
};
function useOrderTableAdapter() {
  const filters = useOrderTableFilters2();
  const adapter = createOrderTableAdapter();
  return {
    ...adapter,
    filters,
    queryPrefix: "o"
  };
}

// src/routes/orders/order-list/components/order-list-table/configurable-order-list-table.tsx
import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var ConfigurableOrderListTable = () => {
  const { t } = useTranslation3();
  const location = useLocation2();
  const adapter = useOrderTableAdapter();
  return /* @__PURE__ */ jsxs2(Fragment, { children: [
    /* @__PURE__ */ jsx2(
      ConfigurableDataTable,
      {
        adapter,
        heading: t("orders.domain"),
        actions: [
          { label: t("actions.export"), to: `export${location.search}` }
        ]
      }
    ),
    /* @__PURE__ */ jsx2(Outlet2, {})
  ] });
};

// src/routes/orders/order-list/order-list.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var OrderList = () => {
  const { getWidgets } = useExtension();
  const isViewConfigEnabled = useFeatureFlag("view_configurations");
  return /* @__PURE__ */ jsx3(
    SingleColumnPage,
    {
      widgets: {
        after: getWidgets("order.list.after"),
        before: getWidgets("order.list.before")
      },
      hasOutlet: false,
      children: isViewConfigEnabled ? /* @__PURE__ */ jsx3(ConfigurableOrderListTable, {}) : /* @__PURE__ */ jsx3(OrderListTable, {})
    }
  );
};
export {
  OrderList as Component
};
