import {
  ProductTagDetailBreadcrumb
} from "./chunk-XG76XXM2.js";
import "./chunk-N335VHD3.js";
import "./chunk-EBZ5VZEO.js";
import "./chunk-4F5GP7J7.js";
import "./chunk-7TIZP4YG.js";
import "./chunk-GJM5XI3E.js";
import "./chunk-YNGA3GRX.js";
import "./chunk-BI2AYXZQ.js";
import "./chunk-MG4GKUJW.js";
import "./chunk-AYVH6Q5O.js";
import "./chunk-VOHEQ7B5.js";
import "./chunk-DY3XQPHC.js";
import "./chunk-GRH7C3QN.js";
import "./chunk-VKOE5J66.js";
import "./chunk-42R54Z2X.js";
import "./chunk-Y6S7K3YB.js";
import "./chunk-N3T24SEK.js";
import "./chunk-JHIMVLB2.js";
import "./chunk-HRUO43BZ.js";
import "./chunk-HHD2VUED.js";
import "./chunk-2ZFELO2L.js";
import "./chunk-26OOAKQ6.js";
import "./chunk-S2WEYEQR.js";
import "./chunk-XBKWFLJG.js";
import "./chunk-5ALC4Z2H.js";
import "./chunk-ZC2ME3UB.js";
import "./chunk-CMHI2RPL.js";
import "./chunk-HB3BP55W.js";
import "./chunk-SYNUA6LQ.js";
import "./chunk-UAE6XBYL.js";
import "./chunk-5YZ3G5EZ.js";
import "./chunk-VW56KWO2.js";
import "./chunk-T35QBLG7.js";
import "./chunk-XCHKUSUU.js";
import "./chunk-JRTZWK77.js";
import {
  useProductTableColumns
} from "./chunk-AAKR2CB4.js";
import "./chunk-G64YUZSL.js";
import {
  useProductTableQuery
} from "./chunk-BEPAXQMU.js";
import "./chunk-FWPGOIFA.js";
import {
  useProductTableFilters
} from "./chunk-LFX6R456.js";
import "./chunk-DB6ANJBO.js";
import "./chunk-PHOCVOZ5.js";
import "./chunk-IQPN4PZJ.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import "./chunk-FQERBIVS.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import "./chunk-YN3FGNJM.js";
import "./chunk-KCHYLLVG.js";
import "./chunk-CVXKASWV.js";
import "./chunk-THHRRYRS.js";
import "./chunk-LRD242C7.js";
import "./chunk-52KJSIHS.js";
import "./chunk-WIYFXWRI.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import "./chunk-QHQWEERJ.js";
import "./chunk-Y7QKP6QU.js";
import {
  productTagsQueryKeys,
  useDeleteProductTag,
  useProductTag
} from "./chunk-RLRWDHME.js";
import "./chunk-K5324KIX.js";
import "./chunk-FV76G2D7.js";
import "./chunk-GHDLST2P.js";
import "./chunk-YVYYOBAE.js";
import "./chunk-L2NJPDUD.js";
import "./chunk-P7UBW2EI.js";
import "./chunk-MR6REQKT.js";
import "./chunk-EPSDO2MJ.js";
import "./chunk-BHEU34FL.js";
import "./chunk-W34KDYZA.js";
import "./chunk-II3CLUXA.js";
import "./chunk-XKEYHWBS.js";
import "./chunk-J2XUEO2E.js";
import "./chunk-656G74I2.js";
import "./chunk-VWPNMEOE.js";
import "./chunk-O72AIZUN.js";
import "./chunk-VUWAOX7H.js";
import "./chunk-5DKUSZQ7.js";
import "./chunk-DIAWPVYS.js";
import "./chunk-4U2BLH45.js";
import {
  useProducts
} from "./chunk-YAUGB4LD.js";
import "./chunk-A5DJIOHN.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import {
  fetchQuery
} from "./chunk-DTGEFKK4.js";
import "./chunk-NBMM2TZK.js";

// src/pages/settings/product-tags/[id]/loader.ts
var productTagDetailQuery = (id) => ({
  queryKey: productTagsQueryKeys.detail(id),
  queryFn: async () => fetchQuery(`/vendor/product-tags/${id}`, {
    method: "GET"
  })
});
var productTagLoader = async ({ params }) => {
  const id = params.id;
  const query = productTagDetailQuery(id);
  return queryClient.ensureQueryData(query);
};

// src/pages/settings/product-tags/[id]/product-tag-detail-page.tsx
import { Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/product-tags/[id]/_components/product-tag-general-section.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { Container, Heading } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";

// src/pages/settings/product-tags/_common/hooks/use-delete-product-tag-action.tsx
import { toast, usePrompt } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
var useDeleteProductTagAction = ({
  productTag
}) => {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const navigate = useNavigate();
  const { mutateAsync } = useDeleteProductTag(productTag.id);
  const handleDelete = async () => {
    const confirmed = await prompt({
      title: t("general.areYouSure"),
      description: t("productTags.delete.confirmation", {
        value: productTag.value
      }),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!confirmed) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast.success(
          t("productTags.delete.successToast", {
            value: productTag.value
          })
        );
        navigate("/settings/product-tags", {
          replace: true
        });
      },
      onError: (error) => {
        toast.error(error.message);
      }
    });
  };
  return handleDelete;
};

// src/pages/settings/product-tags/[id]/_components/product-tag-general-section.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var ProductTagGeneralSection = ({
  productTag
}) => {
  const { t } = useTranslation2();
  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/settings/product-tags/[id]/_components/product-tag-product-section.tsx
import { Container as Container2, Heading as Heading2 } from "@medusajs/ui";
import { useTranslation as useTranslation3 } 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 } = useTranslation3();
  const { searchParams, raw } = useProductTableQuery({
    pageSize: PAGE_SIZE,
    prefix: PREFIX
  });
  const { products, count, isPending, isError, error } = useProducts(
    {
      ...searchParams,
      fields: "*tags",
      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
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs2(Container2, { className: "divide-y px-0 py-0", children: [
    /* @__PURE__ */ jsx2("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx2(Heading2, { level: "h2", children: t("products.domain") }) }),
    /* @__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") }
        ]
      }
    )
  ] });
};

// src/pages/settings/product-tags/[id]/product-tag-detail-page.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 /* @__PURE__ */ jsx3(SingleColumnPage, { data: product_tag, children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs3(WidgetZone, { id: "product-tags.detail.main", 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 {
  ProductTagDetailBreadcrumb as Breadcrumb,
  ProductTagDetailPage,
  productTagLoader as loader
};
