import {
  useDeleteProductTypeAction
} from "./chunk-33BERJSG.js";
import {
  useProductTableColumns
} from "./chunk-Z5I2Z6L3.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-KYPPQGGE.js";
import {
  SingleColumnPage
} from "./chunk-H6MYB7GB.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useProductTableFilters
} from "./chunk-LNAXUDW2.js";
import {
  useProductTableQuery
} from "./chunk-VVWB3GIK.js";
import {
  useProductType
} from "./chunk-46M463BR.js";
import {
  useProducts
} from "./chunk-5CK6XEFV.js";

// src/pages/product-types/product-type-detail/product-type-detail.tsx
import { Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";

// src/pages/product-types/product-type-detail/components/product-type-general-section/product-type-general-section.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { Container, Heading } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var ProductTypeGeneralSection = ({
  productType
}) => {
  const { t } = useTranslation();
  const handleDelete = useDeleteProductTypeAction(
    productType.id,
    productType.value
  );
  return /* @__PURE__ */ jsxs(Container, { className: "flex items-center justify-between", "data-testid": "product-type-general-section-container", children: [
    /* @__PURE__ */ jsx(Heading, { "data-testid": "product-type-general-section-heading", children: productType.value }),
    /* @__PURE__ */ jsx(
      ActionMenu,
      {
        groups: [
          {
            actions: [
              {
                label: t("actions.edit"),
                icon: /* @__PURE__ */ jsx(PencilSquare, {}),
                to: "edit"
              }
            ]
          },
          {
            actions: [
              {
                label: t("actions.delete"),
                icon: /* @__PURE__ */ jsx(Trash, {}),
                onClick: handleDelete
              }
            ]
          }
        ],
        "data-testid": "product-type-general-section-action-menu"
      }
    )
  ] });
};

// src/pages/product-types/product-type-detail/components/product-type-product-section/product-type-product-section.tsx
import { Container as Container2, Heading as Heading2 } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var ProductTypeProductSection = ({
  productType
}) => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useProductTableQuery({
    pageSize: PAGE_SIZE
  });
  const { products, count, isPending, isError, error } = useProducts({
    ...searchParams,
    type_id: [productType.id]
  });
  const filters = useProductTableFilters(["product_types"]);
  const columns = useProductTableColumns();
  const { table } = useDataTable({
    columns,
    data: products,
    count: products?.length || 0,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs2(Container2, { className: "divide-y p-0", "data-testid": "product-type-product-section-container", children: [
    /* @__PURE__ */ jsx2("div", { className: "px-6 py-4", "data-testid": "product-type-product-section-header", children: /* @__PURE__ */ jsx2(Heading2, { level: "h2", "data-testid": "product-type-product-section-heading", children: t("products.domain") }) }),
    /* @__PURE__ */ jsx2(
      _DataTable,
      {
        table,
        filters,
        isLoading: isPending,
        columns,
        count,
        pageSize: PAGE_SIZE,
        navigateTo: ({ original }) => `/products/${original.id}`,
        orderBy: [
          { key: "title", label: t("fields.title") },
          { key: "created_at", label: t("fields.createdAt") },
          { key: "updated_at", label: t("fields.updatedAt") }
        ],
        queryObject: raw,
        search: true,
        pagination: true,
        "data-testid": "product-type-product-section-table"
      }
    )
  ] });
};

// src/pages/product-types/product-type-detail/product-type-detail.tsx
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const { id } = useParams();
  const initialData = useLoaderData();
  const { product_type, isPending, isError, error } = useProductType(
    id,
    void 0,
    {
      initialData
    }
  );
  if (isPending || !product_type) {
    return /* @__PURE__ */ jsx3(SingleColumnPageSkeleton, { sections: 2, showJSON: true, showMetadata: true });
  }
  if (isError) {
    throw error;
  }
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx3(SingleColumnPage, { showJSON: true, showMetadata: true, data: product_type, children }) : /* @__PURE__ */ jsxs3(SingleColumnPage, { showJSON: true, showMetadata: true, data: product_type, children: [
    /* @__PURE__ */ jsx3(ProductTypeGeneralSection, { productType: product_type }),
    /* @__PURE__ */ jsx3(ProductTypeProductSection, { productType: product_type })
  ] });
};
var ProductTypeDetailPage = Object.assign(Root, {
  GeneralSection: ProductTypeGeneralSection,
  ProductSection: ProductTypeProductSection
});

export {
  ProductTypeDetailPage
};
