import {
  ProductGeneralSection,
  ProductMediaSection
} from "./chunk-WN2NWWVO.js";
import {
  SectionRow
} from "./chunk-4TLP3TAA.js";
import {
  SidebarLink
} from "./chunk-4GPAS5GW.js";
import "./chunk-U2EI2ZLM.js";
import {
  TwoColumnPage
} 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 {
  useQueryParams
} from "./chunk-THHRRYRS.js";
import "./chunk-LRD242C7.js";
import {
  require_dist
} from "./chunk-52KJSIHS.js";
import {
  Thumbnail
} from "./chunk-WIYFXWRI.js";
import {
  TwoColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import "./chunk-QHQWEERJ.js";
import "./chunk-Y7QKP6QU.js";
import {
  useFeatureFlags
} 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 {
  useSalesChannels
} from "./chunk-4U2BLH45.js";
import {
  PRODUCT_DETAIL_QUERY
} from "./chunk-Q6SPIHFR.js";
import {
  productsQueryKeys,
  useCancelProductEdit,
  useDeleteVariantLazy,
  useProduct,
  useProductChange,
  useProductVariants,
  useRemoveAttributeFromProduct
} from "./chunk-YAUGB4LD.js";
import "./chunk-A5DJIOHN.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-DTGEFKK4.js";
import {
  __toESM
} from "./chunk-NBMM2TZK.js";

// src/pages/products/[id]/loader.tsx
import { getLinkQuery } from "@mercurjs/dashboard-shared";
var productDetailQueryWithLinks = () => getLinkQuery("product", PRODUCT_DETAIL_QUERY.fields);
var productDetailQuery = (id) => {
  const query = productDetailQueryWithLinks();
  return {
    queryKey: productsQueryKeys.detail(id, query),
    queryFn: async () => sdk.vendor.products.$id.query({
      $id: id,
      ...query
    })
  };
};
var loader = async ({ params }) => {
  const id = params.id;
  const query = productDetailQuery(id);
  const response = await queryClient.ensureQueryData({
    ...query,
    staleTime: 9e4
  });
  return response;
};

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

// src/pages/products/[id]/_components/product-active-edit-section/product-active-edit-section.tsx
var import_types = __toESM(require_dist(), 1);
import { Button, toast, usePrompt } from "@medusajs/ui";
import {
  ProductChangePanel
} from "@mercurjs/dashboard-shared";
import { useTranslation } from "react-i18next";
import { jsx } from "react/jsx-runtime";
var VARIANT_LOOKUP_FIELDS = "id,title,sku,*images";
var resolversFor = (productId) => ({
  getType: async (id) => {
    const { product_type } = await sdk.vendor.productTypes.$id.query({ $id: id });
    return product_type?.value ?? null;
  },
  getCollection: async (id) => {
    const { collection } = await sdk.vendor.collections.$id.query({ $id: id });
    return collection?.title ?? null;
  },
  getCategory: async (id) => {
    const { product_category } = await sdk.vendor.productCategories.$id.query({
      $id: id
    });
    return product_category?.name ?? null;
  },
  getTag: async (id) => {
    const { product_tag } = await sdk.vendor.productTags.$id.query({ $id: id });
    return product_tag?.value ?? null;
  },
  getAttribute: async (id) => {
    const { product_attribute } = await sdk.vendor.productAttributes.$id.query({
      $id: id
    });
    if (!product_attribute) return null;
    return {
      name: product_attribute.name ?? id,
      values: (product_attribute.values ?? []).map((v) => ({
        id: v.id,
        name: v.name ?? v.id
      }))
    };
  },
  getVariant: async (variantId) => {
    const { variant } = await sdk.vendor.products.$id.variants.$variantId.query({
      $id: productId,
      $variantId: variantId,
      fields: VARIANT_LOOKUP_FIELDS
    });
    return variant ?? null;
  }
});
var ProductActiveEditSection = ({
  product
}) => {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const { product_change, isError } = useProductChange(product.id, {
    retry: false
  });
  const { mutateAsync: cancelEdit, isPending: isCanceling } = useCancelProductEdit(product.id);
  if (isError || !product_change) {
    return null;
  }
  if (product_change.status !== import_types.ProductChangeStatus.PENDING) {
    return null;
  }
  const onCancel = async () => {
    const confirmed = await prompt({
      title: t("products.edits.panel.cancelTitle"),
      description: t("products.edits.panel.cancelDescription"),
      confirmText: t("actions.confirm"),
      cancelText: t("actions.cancel")
    });
    if (!confirmed) return;
    try {
      await cancelEdit();
      toast.success(t("products.edits.toast.canceledSuccessfully"));
    } catch (e) {
      toast.error(e.message);
    }
  };
  const panelProduct = {
    id: product.id,
    title: product.title,
    thumbnail: product.thumbnail,
    variants: product.variants,
    attributes: product.attributes
  };
  return /* @__PURE__ */ jsx(
    ProductChangePanel,
    {
      product: panelProduct,
      actions: product_change.actions ?? [],
      resolvers: resolversFor(product.id),
      footer: /* @__PURE__ */ jsx(
        Button,
        {
          size: "small",
          variant: "secondary",
          onClick: onCancel,
          disabled: isCanceling,
          isLoading: isCanceling,
          "data-testid": "product-active-edit-cancel-button",
          children: t("actions.cancel")
        }
      )
    }
  );
};

// src/pages/products/[id]/_components/product-organization-section/product-organization-section.tsx
import { PencilSquare } from "@medusajs/icons";
import { Badge, Container, Heading, Tooltip } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { Link } from "react-router-dom";
import { DisplayExtensionZone } from "@mercurjs/dashboard-shared";
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var ProductOrganizationSection = ({
  product
}) => {
  const { t } = useTranslation2();
  return /* @__PURE__ */ jsxs(
    Container,
    {
      className: "divide-y p-0",
      "data-testid": "product-organization-section",
      children: [
        /* @__PURE__ */ jsxs(
          "div",
          {
            className: "flex items-center justify-between px-6 py-4",
            "data-testid": "product-organization-header",
            children: [
              /* @__PURE__ */ jsx2(Heading, { level: "h2", "data-testid": "product-organization-title", children: t("products.organization.header") }),
              /* @__PURE__ */ jsx2(
                ActionMenu,
                {
                  groups: [
                    {
                      actions: [
                        {
                          label: t("actions.edit"),
                          to: "organization",
                          icon: /* @__PURE__ */ jsx2(PencilSquare, {})
                        }
                      ]
                    }
                  ],
                  "data-testid": "product-organization-action-menu"
                }
              )
            ]
          }
        ),
        /* @__PURE__ */ jsx2(
          SectionRow,
          {
            title: t("fields.category"),
            value: product.categories?.length ? product.categories.map((pcat) => /* @__PURE__ */ jsx2(
              OrganizationTag,
              {
                label: pcat.name,
                to: `/categories/${pcat.id}`
              },
              pcat.id
            )) : void 0,
            "data-testid": "product-categories-row"
          }
        ),
        /* @__PURE__ */ jsx2(
          SectionRow,
          {
            title: t("fields.collection"),
            value: product.collection ? /* @__PURE__ */ jsx2(
              OrganizationTag,
              {
                label: product.collection.title,
                to: `/collections/${product.collection.id}`
              }
            ) : void 0,
            "data-testid": "product-collection-row"
          }
        ),
        /* @__PURE__ */ jsx2(
          SectionRow,
          {
            title: t("fields.tags"),
            value: product.tags?.length ? product.tags.map((tag) => /* @__PURE__ */ jsx2(
              OrganizationTag,
              {
                label: tag.value,
                to: `/settings/product-tags/${tag.id}`
              },
              tag.id
            )) : void 0,
            "data-testid": "product-tags-row"
          }
        ),
        /* @__PURE__ */ jsx2(
          SectionRow,
          {
            title: t("fields.type"),
            value: product.type ? /* @__PURE__ */ jsx2(
              OrganizationTag,
              {
                label: product.type.value,
                to: `/settings/product-types/${product.type_id}`
              }
            ) : void 0,
            "data-testid": "product-type-row"
          }
        ),
        /* @__PURE__ */ jsx2(DisplayExtensionZone, { model: "product", zone: "organize", data: product })
      ]
    }
  );
};
var OrganizationTag = ({ label, to }) => {
  return /* @__PURE__ */ jsx2(Tooltip, { content: label, children: /* @__PURE__ */ jsx2(Badge, { size: "2xsmall", className: "block w-fit truncate", asChild: true, children: /* @__PURE__ */ jsx2(
    Link,
    {
      to,
      "data-testid": `organization-tag-${label.toLowerCase().replace(/\s+/g, "-")}`,
      children: label
    }
  ) }) });
};

// src/pages/products/[id]/_components/product-variant-section/product-variant-section.tsx
import { useCallback, useMemo } from "react";
import { PencilSquare as PencilSquare2, Trash } from "@medusajs/icons";
import {
  Badge as Badge2,
  Button as Button2,
  Container as Container2,
  Heading as Heading2,
  toast as toast2,
  Tooltip as Tooltip2,
  usePrompt as usePrompt2
} from "@medusajs/ui";
import { DisplayExtensionZone as DisplayExtensionZone2 } from "@mercurjs/dashboard-shared";
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { useTranslation as useTranslation3 } from "react-i18next";
import { Link as Link2, useNavigate, useSearchParams } from "react-router-dom";
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var PREFIX = "pv";
var ProductVariantSection = ({
  product
}) => {
  const { t } = useTranslation3();
  const { q, order, offset, created_at, updated_at } = useQueryParams(
    ["q", "order", "offset", "created_at", "updated_at"],
    PREFIX
  );
  const { variants, count, isLoading, isError, error } = useProductVariants(
    product.id,
    {
      q,
      order: order ? order : "variant_rank",
      offset: offset ? parseInt(offset) : void 0,
      limit: PAGE_SIZE,
      created_at: created_at ? JSON.parse(created_at) : void 0,
      updated_at: updated_at ? JSON.parse(updated_at) : void 0,
      fields: "title,sku,created_at,updated_at,*options,*options.option"
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const columns = useColumns(product);
  const filters = useFilters();
  const orderBy = useOrderBy();
  const { table } = useDataTable({
    data: variants ?? [],
    columns,
    count,
    pageSize: PAGE_SIZE,
    getRowId: (row) => row.id,
    prefix: PREFIX
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs2(Container2, { className: "divide-y p-0", "data-testid": "product-variant-section", children: [
    /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsx3(Heading2, { level: "h2", children: t("products.variants.header") }),
      /* @__PURE__ */ jsx3(
        Button2,
        {
          size: "small",
          variant: "secondary",
          asChild: true,
          "data-testid": "product-variants-create-button",
          children: /* @__PURE__ */ jsx3(Link2, { to: "variants/create", children: t("actions.create") })
        }
      )
    ] }),
    /* @__PURE__ */ jsx3(
      _DataTable,
      {
        table,
        columns,
        count,
        pageSize: PAGE_SIZE,
        filters,
        search: true,
        pagination: true,
        isLoading,
        orderBy,
        defaultOrderBy: "title",
        prefix: PREFIX,
        queryObject: { q, order, created_at, updated_at },
        navigateTo: (row) => `variants/${row.original.id}`,
        noRecords: {
          title: t("products.variants.empty.heading"),
          message: t("products.variants.empty.description")
        }
      }
    ),
    /* @__PURE__ */ jsx3(DisplayExtensionZone2, { model: "product", zone: "variants", data: product })
  ] });
};
var columnHelper = createColumnHelper();
var useColumns = (product) => {
  const { t } = useTranslation3();
  const navigate = useNavigate();
  const { mutateAsync } = useDeleteVariantLazy(product.id);
  const prompt = usePrompt2();
  const [searchParams] = useSearchParams();
  const tableSearchParams = useMemo(() => {
    const filtered = new URLSearchParams();
    for (const [key, value] of searchParams.entries()) {
      if (key.startsWith(`${PREFIX}_`)) {
        filtered.append(key, value);
      }
    }
    return filtered;
  }, [searchParams]);
  const handleDelete = useCallback(
    async (id, title) => {
      const res = await prompt({
        title: t("general.areYouSure"),
        description: t("products.deleteVariantWarning", {
          title
        }),
        confirmText: t("actions.delete"),
        cancelText: t("actions.cancel")
      });
      if (!res) {
        return;
      }
      await mutateAsync(
        { variantId: id },
        {
          onError: (error) => {
            toast2.error(error.message);
          }
        }
      );
    },
    [mutateAsync, prompt, t]
  );
  const attributeColumns = useMemo(() => {
    const variantAttributes = product?.attributes?.filter((attr) => attr.is_variant_axis);
    if (!variantAttributes?.length) {
      return [];
    }
    return variantAttributes.map((attribute) => {
      return columnHelper.display({
        id: `attribute-${attribute.id}`,
        header: attribute.name,
        cell: ({ row }) => {
          const variantOpt = row.original.options?.find(
            (opt) => opt.option?.title === attribute.name
          );
          if (!variantOpt?.value) {
            return /* @__PURE__ */ jsx3("span", { className: "text-ui-fg-muted", children: "-" });
          }
          return /* @__PURE__ */ jsx3(
            "div",
            {
              className: "flex flex-wrap items-center gap-1",
              "data-testid": `product-variant-attribute-${attribute.id}-${row.original.id}`,
              children: /* @__PURE__ */ jsx3(Tooltip2, { content: variantOpt.value, children: /* @__PURE__ */ jsx3(
                Badge2,
                {
                  size: "2xsmall",
                  title: variantOpt.value,
                  className: "inline-flex min-w-[20px] max-w-[140px] items-center justify-center overflow-hidden truncate",
                  "data-testid": `product-variant-attribute-badge-${attribute.id}-${row.original.id}-${variantOpt.value}`,
                  children: variantOpt.value
                }
              ) })
            }
          );
        }
      });
    });
  }, [product]);
  return useMemo(
    () => [
      columnHelper.accessor("title", {
        id: "title",
        header: t("fields.title"),
        cell: ({ getValue }) => {
          const value = getValue();
          return /* @__PURE__ */ jsxs2("div", { className: "flex h-full w-full max-w-[250px] items-center gap-x-3 overflow-hidden", children: [
            /* @__PURE__ */ jsx3("div", { className: "w-fit flex-shrink-0", children: /* @__PURE__ */ jsx3(Thumbnail, { src: product.thumbnail }) }),
            value ? /* @__PURE__ */ jsx3("span", { title: value, className: "truncate", children: value }) : /* @__PURE__ */ jsx3("span", { className: "text-ui-fg-muted", children: "-" })
          ] });
        }
      }),
      columnHelper.accessor("sku", {
        id: "sku",
        header: t("fields.sku"),
        cell: ({ getValue }) => {
          const value = getValue();
          return value ? value : /* @__PURE__ */ jsx3("span", { className: "text-ui-fg-muted", children: "-" });
        }
      }),
      ...attributeColumns,
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => /* @__PURE__ */ jsx3(
          ActionMenu,
          {
            groups: [
              {
                actions: [
                  {
                    icon: /* @__PURE__ */ jsx3(PencilSquare2, {}),
                    label: t("actions.edit"),
                    onClick: () => navigate(
                      `edit-variant?variant_id=${row.original.id}&${tableSearchParams.toString()}`,
                      {
                        state: {
                          restore_params: tableSearchParams.toString()
                        }
                      }
                    )
                  }
                ]
              },
              {
                actions: [
                  {
                    icon: /* @__PURE__ */ jsx3(Trash, {}),
                    label: t("actions.delete"),
                    onClick: () => handleDelete(row.original.id, row.original.title ?? "")
                  }
                ]
              }
            ]
          }
        )
      })
    ],
    [t, attributeColumns, navigate, handleDelete, tableSearchParams, product]
  );
};
var useFilters = () => {
  const { t } = useTranslation3();
  return useMemo(
    () => [
      { key: "created_at", label: t("fields.createdAt"), type: "date" },
      { key: "updated_at", label: t("fields.updatedAt"), type: "date" }
    ],
    [t]
  );
};
var useOrderBy = () => {
  const { t } = useTranslation3();
  return useMemo(
    () => [
      { key: "title", label: t("fields.title") },
      { key: "sku", label: t("fields.sku") }
    ],
    [t]
  );
};

// src/pages/products/[id]/_components/product-attribute-section/product-attribute-section.tsx
import {
  Plus,
  Trash as Trash2,
  Swatch,
  DropCap,
  InformationCircleSolid,
  PencilSquare as PencilSquare3
} from "@medusajs/icons";
import {
  Badge as Badge3,
  Container as Container3,
  Heading as Heading3,
  Text,
  toast as toast3,
  Tooltip as Tooltip3,
  usePrompt as usePrompt3
} from "@medusajs/ui";
import { DisplayExtensionZone as DisplayExtensionZone3 } from "@mercurjs/dashboard-shared";
import { useTranslation as useTranslation4 } from "react-i18next";
var import_types2 = __toESM(require_dist(), 1);
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
var AttributeActions = ({
  productId,
  attribute
}) => {
  const { t } = useTranslation4();
  const prompt = usePrompt3();
  const { feature_flags } = useFeatureFlags();
  const isProductRequestEnabled = !!feature_flags?.[import_types2.MercurFeatureFlags.PRODUCT_REQUEST];
  const { mutateAsync } = useRemoveAttributeFromProduct(productId, attribute.id);
  const handleDelete = async () => {
    const res = await prompt({
      title: t("general.areYouSure"),
      description: t("products.deleteAttributeWarning", {
        title: attribute.name
      }),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast3.success(
          isProductRequestEnabled ? t("products.edit.requestSuccessToast") : t("products.edit.attributes.deleteSuccessToast")
        );
      },
      onError: (error) => {
        toast3.error(error.message);
      }
    });
  };
  return /* @__PURE__ */ jsx4(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              label: t("actions.edit"),
              to: `attributes/${attribute.id}/edit`,
              icon: /* @__PURE__ */ jsx4(PencilSquare3, {})
            }
          ]
        },
        ...attribute.is_required ? [] : [
          {
            actions: [
              {
                label: t("actions.delete"),
                onClick: handleDelete,
                icon: /* @__PURE__ */ jsx4(Trash2, {})
              }
            ]
          }
        ]
      ]
    }
  );
};
var AttributeValue = ({
  attribute
}) => {
  const { t } = useTranslation4();
  const values = attribute.values?.map((v) => v.name) ?? [];
  if (["single_select", "multi_select"].includes(attribute.type)) {
    return /* @__PURE__ */ jsx4("div", { className: "flex flex-wrap gap-1", children: values.map((val) => /* @__PURE__ */ jsx4(
      Badge3,
      {
        size: "2xsmall",
        className: "flex min-w-[20px] items-center justify-center",
        children: val
      },
      val
    )) });
  }
  const textValue = attribute.type === "toggle" ? values.map((val) => val === "true" ? t("general.yes") : t("general.no")).join(", ") || "-" : values.join(", ") || "-";
  return /* @__PURE__ */ jsx4(Tooltip3, { content: /* @__PURE__ */ jsx4("span", { className: "break-all", children: textValue }), children: /* @__PURE__ */ jsx4(
    Text,
    {
      size: "small",
      leading: "compact",
      className: "line-clamp-3 min-w-0 break-words text-ui-fg-subtle",
      children: textValue
    }
  ) });
};
var AttributeGroup = ({
  icon,
  title,
  description,
  attributes,
  productId
}) => {
  const { t } = useTranslation4();
  if (!attributes.length) {
    return null;
  }
  return /* @__PURE__ */ jsxs3("div", { className: "flex flex-col gap-y-4 px-3 py-4", children: [
    /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-x-3 px-3", children: [
      /* @__PURE__ */ jsx4("div", { className: "text-ui-fg-muted flex h-8 w-8 items-center justify-center rounded-lg border border-ui-border-base bg-ui-bg-component", children: icon }),
      /* @__PURE__ */ jsxs3("div", { children: [
        /* @__PURE__ */ jsx4(Text, { size: "small", weight: "plus", leading: "compact", children: title }),
        /* @__PURE__ */ jsx4(Text, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: description })
      ] })
    ] }),
    /* @__PURE__ */ jsx4("div", { className: "flex flex-col gap-y-0", children: /* @__PURE__ */ jsx4("div", { className: "overflow-hidden rounded-xl border border-ui-border-base", children: attributes.map((attr, index) => {
      return /* @__PURE__ */ jsx4(
        "div",
        {
          className: index < attributes.length - 1 ? "border-b border-ui-border-base" : "",
          children: /* @__PURE__ */ jsxs3("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_28px] items-center gap-4 px-4 py-3 bg-ui-bg-component", children: [
            /* @__PURE__ */ jsxs3("div", { className: "flex items-center gap-x-2 text-ui-fg-subtle", children: [
              /* @__PURE__ */ jsx4(Text, { size: "small", weight: "plus", leading: "compact", children: attr.name }),
              attr.description && /* @__PURE__ */ jsx4(Tooltip3, { content: attr.description, children: /* @__PURE__ */ jsx4("span", { className: "text-ui-fg-muted flex items-center", children: /* @__PURE__ */ jsx4(InformationCircleSolid, {}) }) }),
              attr.is_required && /* @__PURE__ */ jsx4(Tooltip3, { content: t("products.attributeRequiredByMarketplace"), children: /* @__PURE__ */ jsx4("span", { className: "text-ui-fg-muted flex items-center", children: /* @__PURE__ */ jsx4(InformationCircleSolid, {}) }) })
            ] }),
            /* @__PURE__ */ jsx4(AttributeValue, { attribute: attr }),
            /* @__PURE__ */ jsx4(AttributeActions, { productId, attribute: attr })
          ] })
        },
        attr.id
      );
    }) }) })
  ] });
};
var ProductAttributeSection = ({
  product
}) => {
  const { t } = useTranslation4();
  const allAttributes = product.attributes ?? [];
  const variantAttributes = allAttributes.filter((a) => a.is_variant_axis);
  const infoAttributes = allAttributes.filter((a) => !a.is_variant_axis);
  const isEmpty = !variantAttributes.length && !infoAttributes.length;
  return /* @__PURE__ */ jsxs3(Container3, { className: "p-0", children: [
    /* @__PURE__ */ jsxs3(
      "div",
      {
        className: `flex items-center justify-between px-6 py-4${isEmpty ? "" : " border-b border-ui-border-base"}`,
        children: [
          /* @__PURE__ */ jsx4(Heading3, { level: "h2", children: t("products.attributes") }),
          /* @__PURE__ */ jsx4(
            ActionMenu,
            {
              groups: [
                {
                  actions: [
                    {
                      label: t("products.create.attributes.addExisting"),
                      to: "attributes/add",
                      icon: /* @__PURE__ */ jsx4(Plus, {})
                    },
                    {
                      label: t("products.create.attributes.createNew"),
                      to: "attributes/create",
                      icon: /* @__PURE__ */ jsx4(PencilSquare3, {})
                    }
                  ]
                }
              ]
            }
          )
        ]
      }
    ),
    variantAttributes.length > 0 && /* @__PURE__ */ jsx4(
      AttributeGroup,
      {
        icon: /* @__PURE__ */ jsx4(Swatch, {}),
        title: t("products.attributeVariations"),
        description: t("products.attributeVariantsDescription"),
        attributes: variantAttributes,
        productId: product.id
      }
    ),
    variantAttributes.length > 0 && infoAttributes.length > 0 && /* @__PURE__ */ jsx4("div", { className: "border-t border-dashed border-ui-border-base" }),
    infoAttributes.length > 0 && /* @__PURE__ */ jsx4(
      AttributeGroup,
      {
        icon: /* @__PURE__ */ jsx4(DropCap, {}),
        title: t("products.attributeProductInformation"),
        description: t("products.attributeProductInformationDescription"),
        attributes: infoAttributes,
        productId: product.id
      }
    ),
    /* @__PURE__ */ jsx4(DisplayExtensionZone3, { model: "product", zone: "attributes", data: product })
  ] });
};

// src/pages/products/[id]/_components/product-shipping-profile-section/product-shipping-profile-section.tsx
import { PencilSquare as PencilSquare4, ShoppingBag } from "@medusajs/icons";
import { Container as Container4, Heading as Heading4 } from "@medusajs/ui";
import { useTranslation as useTranslation5 } from "react-i18next";
import { DisplayExtensionZone as DisplayExtensionZone4 } from "@mercurjs/dashboard-shared";
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
var ProductShippingProfileSection = ({
  product
}) => {
  const { t } = useTranslation5();
  const shippingProfile = product.shipping_profile;
  return /* @__PURE__ */ jsxs4(Container4, { className: "p-0", children: [
    /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsx5(Heading4, { level: "h2", children: t("products.shippingProfile.header") }),
      /* @__PURE__ */ jsx5(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  label: t("actions.edit"),
                  to: "shipping-profile",
                  icon: /* @__PURE__ */ jsx5(PencilSquare4, {})
                }
              ]
            }
          ]
        }
      )
    ] }),
    shippingProfile && /* @__PURE__ */ jsx5(
      SidebarLink,
      {
        to: `/settings/locations/shipping-profiles/${shippingProfile.id}`,
        labelKey: shippingProfile.name,
        descriptionKey: shippingProfile.type,
        icon: /* @__PURE__ */ jsx5(ShoppingBag, {})
      }
    ),
    /* @__PURE__ */ jsx5(DisplayExtensionZone4, { model: "product", zone: "shipping-profile", data: product })
  ] });
};

// src/pages/products/[id]/_components/product-sales-channel-section/product-sales-channel-section.tsx
import { Channels, PencilSquare as PencilSquare5 } from "@medusajs/icons";
import { Container as Container5, Heading as Heading5, Text as Text2, Tooltip as Tooltip4 } from "@medusajs/ui";
import { Trans, useTranslation as useTranslation6 } from "react-i18next";
import { DisplayExtensionZone as DisplayExtensionZone5 } from "@mercurjs/dashboard-shared";
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
var ProductSalesChannelSection = ({
  product
}) => {
  const { count } = useSalesChannels();
  const { t } = useTranslation6();
  const availableInSalesChannels = product.sales_channels?.map((sc) => ({
    id: sc.id,
    name: sc.name
  })) ?? [];
  const firstChannels = availableInSalesChannels.slice(0, 3);
  const restChannels = availableInSalesChannels.slice(3);
  return /* @__PURE__ */ jsxs5(Container5, { className: "flex flex-col gap-y-4 px-6 py-4", children: [
    /* @__PURE__ */ jsxs5("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ jsx6(Heading5, { level: "h2", children: t("fields.sales_channels") }),
      /* @__PURE__ */ jsx6(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  label: t("actions.edit"),
                  to: "sales-channels",
                  icon: /* @__PURE__ */ jsx6(PencilSquare5, {})
                }
              ]
            }
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsxs5("div", { className: "grid grid-cols-[28px_1fr] items-center gap-x-3", children: [
      /* @__PURE__ */ jsx6("div", { className: "bg-ui-bg-base shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx6("div", { className: "bg-ui-bg-component flex size-6 items-center justify-center rounded-[4px]", children: /* @__PURE__ */ jsx6(Channels, { className: "text-ui-fg-subtle" }) }) }),
      availableInSalesChannels.length > 0 ? /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-x-1", children: [
        /* @__PURE__ */ jsx6(Text2, { size: "small", leading: "compact", children: firstChannels.map((sc) => sc.name).join(", ") }),
        restChannels.length > 0 && /* @__PURE__ */ jsx6(
          Tooltip4,
          {
            content: /* @__PURE__ */ jsx6("ul", { children: restChannels.map((sc) => /* @__PURE__ */ jsx6("li", { children: sc.name }, sc.id)) }),
            children: /* @__PURE__ */ jsx6(
              Text2,
              {
                size: "small",
                leading: "compact",
                className: "text-ui-fg-subtle",
                children: `+${restChannels.length}`
              }
            )
          }
        )
      ] }) : /* @__PURE__ */ jsx6(Text2, { size: "small", leading: "compact", className: "text-ui-fg-subtle", children: t("products.noSalesChannels") })
    ] }),
    /* @__PURE__ */ jsx6("div", { children: /* @__PURE__ */ jsx6(Text2, { className: "text-ui-fg-subtle", size: "small", leading: "compact", children: /* @__PURE__ */ jsx6(
      Trans,
      {
        i18nKey: "sales_channels.availableIn",
        values: {
          x: availableInSalesChannels.length,
          y: count ?? 0
        },
        components: [
          /* @__PURE__ */ jsx6(
            "span",
            {
              className: "text-ui-fg-base txt-compact-medium-plus"
            },
            "x"
          ),
          /* @__PURE__ */ jsx6(
            "span",
            {
              className: "text-ui-fg-base txt-compact-medium-plus"
            },
            "y"
          )
        ]
      }
    ) }) }),
    /* @__PURE__ */ jsx6(DisplayExtensionZone5, { model: "product", zone: "sales-channels", data: product })
  ] });
};

// src/pages/products/[id]/product-detail-page.tsx
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const initialData = useLoaderData();
  const { id } = useParams();
  const query = useLinkQuery("product", PRODUCT_DETAIL_QUERY.fields);
  const { product, isLoading, isError, error } = useProduct(id, query, {
    initialData
  });
  if (isLoading || !product) {
    return /* @__PURE__ */ jsx7(TwoColumnPageSkeleton, { mainSections: 4, sidebarSections: 3 });
  }
  if (isError) {
    throw error;
  }
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx7(TwoColumnPage, { data: product, "data-testid": "product-detail-page", children }) : /* @__PURE__ */ jsxs6(TwoColumnPage, { data: product, "data-testid": "product-detail-page", children: [
    /* @__PURE__ */ jsx7(TwoColumnPage.Main, { "data-testid": "product-detail-main", children: /* @__PURE__ */ jsxs6(WidgetZone, { id: "product.detail.main", data: product, children: [
      /* @__PURE__ */ jsx7(ProductActiveEditSection, { product }),
      /* @__PURE__ */ jsx7(ProductGeneralSection, { product }),
      /* @__PURE__ */ jsx7(ProductMediaSection, { product }),
      /* @__PURE__ */ jsx7(ProductVariantSection, { product })
    ] }) }),
    /* @__PURE__ */ jsx7(TwoColumnPage.Sidebar, { "data-testid": "product-detail-sidebar", children: /* @__PURE__ */ jsxs6(WidgetZone, { id: "product.detail.side", data: product, children: [
      /* @__PURE__ */ jsx7(ProductOrganizationSection, { product }),
      /* @__PURE__ */ jsx7(ProductAttributeSection, { product })
    ] }) })
  ] });
};
var ProductDetailPage = Object.assign(Root, {
  Main: TwoColumnPage.Main,
  Sidebar: TwoColumnPage.Sidebar,
  MainActiveEditSection: ProductActiveEditSection,
  MainGeneralSection: ProductGeneralSection,
  MainMediaSection: ProductMediaSection,
  MainVariantSection: ProductVariantSection,
  MainAttributeSection: ProductAttributeSection,
  SidebarShippingProfileSection: ProductShippingProfileSection,
  SidebarOrganizationSection: ProductOrganizationSection,
  SidebarSalesChannelSection: ProductSalesChannelSection
});
export {
  ProductDetailPage,
  loader,
  productDetailQueryWithLinks
};
