import {
  useDeleteProductTypeAction
} from "./chunk-MDFKI2FL.js";
import {
  useProductTypeTableColumns
} from "./chunk-EBZ5VZEO.js";
import {
  useProductTypeTableQuery
} from "./chunk-VOHEQ7B5.js";
import {
  useProductTypeTableFilters
} from "./chunk-2ZFELO2L.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useProductTypes
} from "./chunk-L2NJPDUD.js";

// src/pages/settings/product-types/product-type-list-page.tsx
import { Children as Children3 } from "react";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/product-types/_components/product-type-list-table.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";

// src/pages/settings/product-types/_components/product-type-list-header.tsx
import { Children } from "react";
import { useTranslation } from "react-i18next";
import { Heading, Text } from "@medusajs/ui";
import { jsx, jsxs } from "react/jsx-runtime";
var ProductTypeListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx(Heading, { children: t("productTypes.domain") }),
    /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: t("productTypes.subtitle") })
  ] });
};
var ProductTypeListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : null });
};
var ProductTypeListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx(ProductTypeListTitle, {}) });
};

// src/pages/settings/product-types/_components/product-type-list-data-table.tsx
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { useMemo } from "react";
import { useTranslation as useTranslation3 } from "react-i18next";

// src/pages/settings/product-types/_components/product-table-row-actions.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2 } from "react/jsx-runtime";
var ProductTypeRowActions = ({ productType }) => {
  const { t } = useTranslation2();
  const handleDelete = useDeleteProductTypeAction(productType.id, productType.value);
  return /* @__PURE__ */ jsx2(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              label: t("actions.edit"),
              icon: /* @__PURE__ */ jsx2(PencilSquare, {}),
              to: `/settings/product-types/${productType.id}/edit`
            }
          ]
        },
        {
          actions: [
            {
              label: t("actions.delete"),
              icon: /* @__PURE__ */ jsx2(Trash, {}),
              onClick: handleDelete
            }
          ]
        }
      ]
    }
  );
};

// src/pages/settings/product-types/_components/product-type-list-data-table.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ProductTypeListDataTable = () => {
  const { t } = useTranslation3();
  const { searchParams, raw } = useProductTypeTableQuery({
    pageSize: PAGE_SIZE
  });
  const { product_types, count, isLoading, isError, error } = useProductTypes(
    searchParams,
    {
      placeholderData: keepPreviousData
    }
  );
  const filters = useProductTypeTableFilters();
  const columns = useColumns();
  const { table } = useDataTable({
    columns,
    data: product_types,
    count,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx3(
    _DataTable,
    {
      table,
      filters,
      isLoading,
      columns,
      pageSize: PAGE_SIZE,
      count,
      orderBy: [
        { key: "value", label: t("fields.value") },
        {
          key: "created_at",
          label: t("fields.createdAt")
        },
        {
          key: "updated_at",
          label: t("fields.updatedAt")
        }
      ],
      navigateTo: ({ original }) => original.id,
      queryObject: raw,
      pagination: true,
      search: true
    }
  );
};
var columnHelper = createColumnHelper();
var useColumns = () => {
  const base = useProductTypeTableColumns();
  return useMemo(
    () => [
      ...base,
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx3(ProductTypeRowActions, { productType: row.original });
        }
      })
    ],
    [base]
  );
};

// src/pages/settings/product-types/_components/product-type-list-table.tsx
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
var ProductTypeListTable = ({ children }) => {
  return /* @__PURE__ */ jsx4(Container, { className: "divide-y p-0", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment, { children: [
    /* @__PURE__ */ jsx4(ProductTypeListHeader, {}),
    /* @__PURE__ */ jsx4(ProductTypeListDataTable, {})
  ] }) });
};

// src/pages/settings/product-types/product-type-list-page.tsx
import { jsx as jsx5 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx5(SingleColumnPage, { hasOutlet: true, children: /* @__PURE__ */ jsx5(WidgetZone, { id: "product-types.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx5(ProductTypeListTable, {}) }) });
};
var ProductTypeListPage = Object.assign(Root, {
  Table: ProductTypeListTable,
  Header: ProductTypeListHeader,
  HeaderTitle: ProductTypeListTitle,
  HeaderActions: ProductTypeListActions,
  DataTable: ProductTypeListDataTable
});

export {
  ProductTypeListPage
};
