import {
  useDeleteProductTypeAction
} from "./chunk-33BERJSG.js";
import {
  useProductTypeTableColumns
} from "./chunk-O5VKW5FL.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-KYPPQGGE.js";
import {
  SingleColumnPage
} from "./chunk-H6MYB7GB.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useProductTypeTableFilters
} from "./chunk-2ZFELO2L.js";
import {
  useProductTypeTableQuery
} from "./chunk-VOHEQ7B5.js";
import {
  useProductTypes
} from "./chunk-46M463BR.js";

// src/pages/product-types/product-type-list/product-type-list.tsx
import { Children as Children3 } from "react";

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

// src/pages/product-types/product-type-list/components/product-type-list-view/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 useTranslation2 } from "react-i18next";

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

// src/pages/product-types/product-type-list/components/product-type-list-view/product-type-list-data-table.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ProductTypeListDataTable = () => {
  const { t } = useTranslation2();
  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__ */ jsx2(
    _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,
      "data-testid": "product-type-list-table"
    }
  );
};
var columnHelper = createColumnHelper();
var useColumns = () => {
  const base = useProductTypeTableColumns();
  return useMemo(
    () => [
      ...base,
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx2(ProductTypeRowActions, { productType: row.original });
        }
      })
    ],
    [base]
  );
};

// src/pages/product-types/product-type-list/components/product-type-list-view/product-type-list-header.tsx
import { Children } from "react";
import { Button, Heading, Text } from "@medusajs/ui";
import { useTranslation as useTranslation3 } from "react-i18next";
import { Link } from "react-router-dom";
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
var ProductTypeListTitle = () => {
  const { t } = useTranslation3();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx3(Heading, { "data-testid": "product-type-list-table-heading", children: t("productTypes.domain") }),
    /* @__PURE__ */ jsx3(
      Text,
      {
        className: "text-ui-fg-subtle",
        size: "small",
        "data-testid": "product-type-list-table-subtitle",
        children: t("productTypes.subtitle")
      }
    )
  ] });
};
var ProductTypeListActions = ({
  children
}) => {
  const { t } = useTranslation3();
  return /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx3(
    Button,
    {
      size: "small",
      variant: "secondary",
      asChild: true,
      "data-testid": "product-type-list-table-create-button",
      children: /* @__PURE__ */ jsx3(Link, { to: "create", children: t("actions.create") })
    }
  ) });
};
var ProductTypeListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx3(
    "div",
    {
      className: "flex items-center justify-between px-6 py-4",
      "data-testid": "product-type-list-table-header",
      children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx3(ProductTypeListTitle, {}),
        /* @__PURE__ */ jsx3(ProductTypeListActions, {})
      ] })
    }
  );
};

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

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

export {
  ProductTypeListPage
};
