import {
  useCustomerTableColumns
} from "./chunk-GJM5XI3E.js";
import {
  useCustomerTableQuery
} from "./chunk-GRH7C3QN.js";
import {
  useCustomerTableFilters
} from "./chunk-ZC2ME3UB.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import {
  useCustomers
} from "./chunk-II3CLUXA.js";

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

// src/pages/customers/_components/customer-list-table/customer-list-table.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";
import { Outlet } from "react-router-dom";

// src/pages/customers/_components/customer-list-table/customer-list-header.tsx
import { Children } from "react";
import { useTranslation } from "react-i18next";
import { Heading } from "@medusajs/ui";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var CustomerListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsx(Heading, { children: t("customers.domain") });
};
var CustomerListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : null });
};
var CustomerListHeader = ({
  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(CustomerListTitle, {}),
    /* @__PURE__ */ jsx(CustomerListActions, {})
  ] }) });
};

// src/pages/customers/_components/customer-list-table/customer-list-data-table.tsx
import { keepPreviousData } from "@tanstack/react-query";
import { useExtendableTable, useLinkQuery } from "@mercurjs/dashboard-shared";
import { useMemo } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var CustomerListDataTable = () => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useCustomerTableQuery({
    pageSize: PAGE_SIZE
  });
  const linkQuery = useLinkQuery("customer");
  const { customers, count, isLoading, isError, error } = useCustomers(
    {
      ...searchParams,
      ...linkQuery
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const baseFilters = useCustomerTableFilters();
  const { columns, filters: extFilters } = useColumns();
  const filters = useMemo(
    () => [...baseFilters, ...extFilters],
    [baseFilters, extFilters]
  );
  const { table } = useDataTable({
    data: customers ?? [],
    columns,
    count,
    enablePagination: true,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(
    _DataTable,
    {
      table,
      columns,
      pageSize: PAGE_SIZE,
      count,
      filters,
      orderBy: [
        { key: "email", label: t("fields.email") },
        {
          key: "first_name",
          label: t("fields.firstName")
        },
        { key: "last_name", label: t("fields.lastName") },
        {
          key: "has_account",
          label: t("customers.hasAccount")
        },
        {
          key: "created_at",
          label: t("fields.createdAt")
        },
        {
          key: "updated_at",
          label: t("fields.updatedAt")
        }
      ],
      defaultOrderBy: "-created_at",
      isLoading,
      navigateTo: (row) => row.original.id,
      queryObject: raw,
      search: true,
      noRecords: {
        message: t("customers.list.noRecordsMessage")
      }
    }
  );
};
var useColumns = () => {
  const base = useCustomerTableColumns();
  const { columns, filters } = useExtendableTable({
    model: "customer",
    columns: base
  });
  return { columns: useMemo(() => [...columns], [columns]), filters };
};

// src/pages/customers/_components/customer-list-table/customer-list-table.tsx
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var CustomerListTable = ({ children }) => {
  return /* @__PURE__ */ jsxs2(Container, { className: "divide-y p-0", children: [
    Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment2, { children: [
      /* @__PURE__ */ jsx3(CustomerListHeader, {}),
      /* @__PURE__ */ jsx3(CustomerListDataTable, {})
    ] }),
    /* @__PURE__ */ jsx3(Outlet, {})
  ] });
};

// src/pages/customers/customer-list-page.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { children: /* @__PURE__ */ jsx4(WidgetZone, { id: "customers.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(CustomerListTable, {}) }) });
};
var CustomerListPage = Object.assign(Root, {
  Table: CustomerListTable,
  Header: CustomerListHeader,
  HeaderTitle: CustomerListTitle,
  HeaderActions: CustomerListActions,
  DataTable: CustomerListDataTable
});

export {
  CustomerListPage
};
