import {
  useDeleteProductTagAction
} from "./chunk-TIMWFAPD.js";
import {
  useProductTableColumns
} from "./chunk-Z5I2Z6L3.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-ULJ3OMWU.js";
import {
  SingleColumnPage
} from "./chunk-XIZLPYEE.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useProductTableFilters
} from "./chunk-WSR2ZXAJ.js";
import {
  useProductTableQuery
} from "./chunk-VVWB3GIK.js";
import {
  useProductTag
} from "./chunk-3MDRW5MA.js";
import {
  useProducts
} from "./chunk-BA2HXHTW.js";

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

// src/pages/product-tags/product-tag-detail/components/product-tag-general-section/product-tag-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 ProductTagGeneralSection = ({
  productTag
}) => {
  const { t } = useTranslation();
  const handleDelete = useDeleteProductTagAction({ productTag });
  return /* @__PURE__ */ jsxs(Container, { className: "flex items-center justify-between", "data-testid": "product-tag-general-section-container", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1.5", "data-testid": "product-tag-general-section-heading-container", children: [
      /* @__PURE__ */ jsx("span", { className: "text-ui-fg-muted h1-core", children: "#" }),
      /* @__PURE__ */ jsx(Heading, { "data-testid": "product-tag-general-section-heading", children: productTag.value })
    ] }),
    /* @__PURE__ */ jsx(
      ActionMenu,
      {
        groups: [
          {
            actions: [
              {
                icon: /* @__PURE__ */ jsx(PencilSquare, {}),
                label: t("actions.edit"),
                to: "edit"
              }
            ]
          },
          {
            actions: [
              {
                icon: /* @__PURE__ */ jsx(Trash, {}),
                label: t("actions.delete"),
                onClick: handleDelete
              }
            ]
          }
        ],
        "data-testid": "product-tag-general-section-action-menu"
      }
    )
  ] });
};

// src/pages/product-tags/product-tag-detail/components/product-tag-product-section/product-tag-product-section.tsx
import { ExclamationCircle } from "@medusajs/icons";
import { Container as Container2, Heading as Heading2, Text } 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 PREFIX = "pt";
var ProductTagProductSection = ({
  productTag
}) => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useProductTableQuery({
    pageSize: PAGE_SIZE,
    prefix: PREFIX
  });
  const { products, count, isPending, isError, error } = useProducts({
    ...searchParams,
    tag_id: productTag.id
  });
  const filters = useProductTableFilters(["product_tags"]);
  const columns = useProductTableColumns();
  const { table } = useDataTable({
    data: products,
    count,
    columns,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE,
    prefix: PREFIX
  });
  return /* @__PURE__ */ jsxs2(Container2, { className: "divide-y px-0 py-0", "data-testid": "product-tag-product-section-container", children: [
    /* @__PURE__ */ jsx2("div", { className: "px-6 py-4", "data-testid": "product-tag-product-section-header", children: /* @__PURE__ */ jsx2(Heading2, { level: "h2", "data-testid": "product-tag-product-section-heading", children: t("products.domain") }) }),
    isError ? /* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-x-2 px-6 py-4", "data-testid": "product-tag-product-section-error", children: [
      /* @__PURE__ */ jsx2(ExclamationCircle, { className: "text-ui-fg-subtle" }),
      /* @__PURE__ */ jsx2(Text, { size: "small", className: "text-ui-fg-subtle", children: error?.message || t("general.error") })
    ] }) : /* @__PURE__ */ jsx2(
      _DataTable,
      {
        table,
        filters,
        queryObject: raw,
        isLoading: isPending,
        columns,
        pageSize: PAGE_SIZE,
        count,
        navigateTo: (row) => `/products/${row.original.id}`,
        search: true,
        pagination: true,
        orderBy: [
          { key: "title", label: t("fields.title") },
          { key: "status", label: t("fields.status") },
          { key: "created_at", label: t("fields.createdAt") },
          { key: "updated_at", label: t("fields.updatedAt") }
        ],
        "data-testid": "product-tag-product-section-table"
      }
    )
  ] });
};

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

export {
  ProductTagDetailPage
};
