import {
  LinkButton
} from "./chunk-7AV5EJJ5.js";
import {
  getCategoryChildren,
  getCategoryGallery,
  getCategoryIcon,
  getCategoryPath
} from "./chunk-LYYM7H7H.js";
import {
  useProductTableColumns
} from "./chunk-AAKR2CB4.js";
import "./chunk-G64YUZSL.js";
import {
  useProductTableQuery
} from "./chunk-BEPAXQMU.js";
import "./chunk-FWPGOIFA.js";
import "./chunk-DB6ANJBO.js";
import "./chunk-PHOCVOZ5.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 "./chunk-THHRRYRS.js";
import "./chunk-LRD242C7.js";
import "./chunk-52KJSIHS.js";
import "./chunk-WIYFXWRI.js";
import {
  Skeleton,
  TwoColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import "./chunk-QHQWEERJ.js";
import "./chunk-Y7QKP6QU.js";
import "./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 {
  categoriesQueryKeys,
  useProductCategory
} from "./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/categories/[id]/loader.tsx
import { getLinkQuery } from "@mercurjs/dashboard-shared";
var categoryDetailQuery = (id) => {
  const query = getLinkQuery("category");
  return {
    queryKey: categoriesQueryKeys.detail(id, query),
    queryFn: async () => fetchQuery(`/vendor/product-categories/${id}`, {
      method: "GET",
      query
    })
  };
};
var loader = async ({ params }) => {
  const id = params.id;
  const query = categoryDetailQuery(id);
  return queryClient.ensureQueryData(query);
};

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

// src/pages/categories/[id]/_components/category-general-section/category-general-section.tsx
import { Container, Heading, Text } from "@medusajs/ui";
import { DisplayExtensionZone, DisplayField } from "@mercurjs/dashboard-shared";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var GENERAL_FIELD_IDS = ["name", "description", "handle"];
var CategoryGeneralSection = ({
  category
}) => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsx(DisplayField, { model: "category", zone: "general", id: "name", data: category, children: /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx(Heading, { children: category.name }) }) }),
    /* @__PURE__ */ jsx(
      DisplayField,
      {
        model: "category",
        zone: "general",
        id: "description",
        data: category,
        children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 gap-3 px-6 py-4", children: [
          /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: t("fields.description") }),
          /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: category.description || "-" })
        ] })
      }
    ),
    /* @__PURE__ */ jsx(
      DisplayField,
      {
        model: "category",
        zone: "general",
        id: "handle",
        data: category,
        children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle grid grid-cols-2 gap-3 px-6 py-4", children: [
          /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: t("fields.handle") }),
          /* @__PURE__ */ jsxs(Text, { size: "small", leading: "compact", children: [
            "/",
            category.handle
          ] })
        ] })
      }
    ),
    /* @__PURE__ */ jsx(
      DisplayExtensionZone,
      {
        model: "category",
        zone: "general",
        data: category,
        builtInFieldIds: GENERAL_FIELD_IDS
      }
    )
  ] });
};

// src/pages/categories/[id]/_components/category-icon-section/category-icon-section.tsx
import { Container as Container2, Heading as Heading2, Text as Text2 } from "@medusajs/ui";
import { DisplayExtensionZone as DisplayExtensionZone2 } from "@mercurjs/dashboard-shared";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var CategoryIconSection = ({
  category
}) => {
  const { t } = useTranslation2();
  const icon = getCategoryIcon(category.media_images);
  return /* @__PURE__ */ jsxs2(Container2, { className: "divide-y p-0", "data-testid": "category-icon-section", children: [
    /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx2(Heading2, { children: t("categories.icon.label") }) }),
    /* @__PURE__ */ jsx2("div", { className: "px-6 py-4", children: icon ? /* @__PURE__ */ jsx2("div", { className: "bg-ui-bg-base shadow-elevation-card-rest relative aspect-square w-24 overflow-hidden rounded-[8px]", children: /* @__PURE__ */ jsx2(
      "img",
      {
        src: icon.url,
        alt: "",
        className: "size-full object-contain object-center p-2",
        "data-testid": "category-icon-section-image"
      }
    ) }) : /* @__PURE__ */ jsxs2("div", { className: "flex flex-col items-center justify-center gap-y-1 py-8", children: [
      /* @__PURE__ */ jsx2(
        Text2,
        {
          size: "small",
          leading: "compact",
          weight: "plus",
          className: "text-ui-fg-subtle",
          children: t("categories.icon.empty.header")
        }
      ),
      /* @__PURE__ */ jsx2(Text2, { size: "small", className: "text-ui-fg-muted", children: t("categories.icon.empty.description") })
    ] }) }),
    /* @__PURE__ */ jsx2(DisplayExtensionZone2, { model: "category", zone: "icon", data: category })
  ] });
};

// src/pages/categories/[id]/_components/category-media-section/category-media-section.tsx
import { ThumbnailBadge } from "@medusajs/icons";
import { DisplayExtensionZone as DisplayExtensionZone3, ListBadge } from "@mercurjs/dashboard-shared";
import { Container as Container3, Heading as Heading3, Text as Text3, Tooltip } from "@medusajs/ui";
import { useTranslation as useTranslation3 } from "react-i18next";
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
var CategoryMediaSection = ({
  category
}) => {
  const { t } = useTranslation3();
  const gallery = getCategoryGallery(category.media_images);
  return /* @__PURE__ */ jsxs3(Container3, { className: "divide-y p-0", "data-testid": "category-media-section", children: [
    /* @__PURE__ */ jsx3("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx3(Heading3, { children: t("categories.media.label") }) }),
    /* @__PURE__ */ jsx3("div", { className: "px-6 py-4", children: gallery.length > 0 ? /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-[repeat(auto-fill,minmax(96px,1fr))] gap-4", children: gallery.map((image) => /* @__PURE__ */ jsxs3(
      "div",
      {
        className: "shadow-elevation-card-rest relative aspect-square size-full overflow-hidden rounded-[8px]",
        "data-testid": `category-media-section-item-${image.id}`,
        children: [
          /* @__PURE__ */ jsx3(
            "img",
            {
              src: image.url,
              alt: "",
              className: "size-full object-cover object-center"
            }
          ),
          (image.is_thumbnail || image.is_banner) && /* @__PURE__ */ jsxs3("div", { className: "absolute left-2 top-2 flex items-center gap-x-1", children: [
            image.is_thumbnail && /* @__PURE__ */ jsx3(Tooltip, { content: t("categories.media.thumbnail"), children: /* @__PURE__ */ jsx3(ThumbnailBadge, {}) }),
            image.is_banner && /* @__PURE__ */ jsx3(Tooltip, { content: t("categories.media.banner"), children: /* @__PURE__ */ jsx3(ListBadge, {}) })
          ] })
        ]
      },
      image.id
    )) }) : /* @__PURE__ */ jsxs3("div", { className: "flex flex-col items-center justify-center gap-y-1 py-8", children: [
      /* @__PURE__ */ jsx3(
        Text3,
        {
          size: "small",
          leading: "compact",
          weight: "plus",
          className: "text-ui-fg-subtle",
          children: t("categories.media.empty.header")
        }
      ),
      /* @__PURE__ */ jsx3(Text3, { size: "small", className: "text-ui-fg-muted", children: t("categories.media.empty.description") })
    ] }) }),
    /* @__PURE__ */ jsx3(DisplayExtensionZone3, { model: "category", zone: "media", data: category })
  ] });
};

// src/pages/categories/[id]/_components/category-organize-section/category-organize-section.tsx
import { FolderIllustration, TriangleRightMini } from "@medusajs/icons";
import { Badge, Container as Container4, Heading as Heading4, Text as Text4, Tooltip as Tooltip2 } from "@medusajs/ui";
import { DisplayExtensionZone as DisplayExtensionZone4 } from "@mercurjs/dashboard-shared";
import { useMemo, useState } from "react";
import { useTranslation as useTranslation4 } from "react-i18next";
import { Link } from "react-router-dom";
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
var CategoryOrganizeSection = ({
  category
}) => {
  const { t } = useTranslation4();
  return /* @__PURE__ */ jsxs4(Container4, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx4(Heading4, { level: "h2", children: t("categories.organize.header") }) }),
    /* @__PURE__ */ jsxs4("div", { className: "text-ui-fg-subtle grid grid-cols-2 items-start gap-3 px-6 py-4", children: [
      /* @__PURE__ */ jsx4(Text4, { size: "small", leading: "compact", weight: "plus", children: t("categories.fields.path.label") }),
      /* @__PURE__ */ jsx4(PathDisplay, { category })
    ] }),
    /* @__PURE__ */ jsxs4("div", { className: "text-ui-fg-subtle grid grid-cols-2 items-start gap-3 px-6 py-4", children: [
      /* @__PURE__ */ jsx4(Text4, { size: "small", leading: "compact", weight: "plus", children: t("categories.fields.children.label") }),
      /* @__PURE__ */ jsx4(ChildrenDisplay, { category })
    ] }),
    /* @__PURE__ */ jsx4(DisplayExtensionZone4, { model: "category", zone: "organize", data: category })
  ] });
};
var PathDisplay = ({
  category
}) => {
  const [expanded, setExpanded] = useState(false);
  const { t } = useTranslation4();
  const {
    product_category: withParents,
    isLoading
  } = useProductCategory(category.id, {
    fields: "id,name,*parent_category"
  });
  const chips = useMemo(() => getCategoryPath(withParents), [withParents]);
  if (isLoading || !withParents) {
    return /* @__PURE__ */ jsx4(Skeleton, { className: "h-5 w-16" });
  }
  if (!chips.length) {
    return /* @__PURE__ */ jsx4(Text4, { size: "small", leading: "compact", children: "-" });
  }
  if (chips.length > 1 && !expanded) {
    return /* @__PURE__ */ jsxs4("div", { className: "grid grid-cols-[20px_1fr] items-start gap-x-2", children: [
      /* @__PURE__ */ jsx4(FolderIllustration, {}),
      /* @__PURE__ */ jsxs4("div", { className: "flex w-full items-center gap-x-0.5 overflow-hidden", children: [
        /* @__PURE__ */ jsx4(Tooltip2, { content: t("categories.fields.path.tooltip"), children: /* @__PURE__ */ jsx4(
          "button",
          {
            className: "outline-none",
            type: "button",
            onClick: () => setExpanded(true),
            children: /* @__PURE__ */ jsx4(Text4, { size: "xsmall", leading: "compact", weight: "plus", children: "..." })
          }
        ) }),
        /* @__PURE__ */ jsx4("div", { className: "flex size-[15px] shrink-0 items-center justify-center", children: /* @__PURE__ */ jsx4(TriangleRightMini, {}) }),
        /* @__PURE__ */ jsx4(
          Text4,
          {
            size: "xsmall",
            leading: "compact",
            weight: "plus",
            className: "truncate",
            children: chips[chips.length - 1].name
          }
        )
      ] })
    ] });
  }
  if (chips.length > 1 && expanded) {
    return /* @__PURE__ */ jsxs4("div", { className: "grid grid-cols-[20px_1fr] items-start gap-x-2", children: [
      /* @__PURE__ */ jsx4(FolderIllustration, {}),
      /* @__PURE__ */ jsx4("div", { className: "gap- flex flex-wrap items-center gap-x-0.5 gap-y-1", children: chips.map((chip, index) => {
        return /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-x-0.5", children: [
          index === chips.length - 1 ? /* @__PURE__ */ jsx4(Text4, { size: "xsmall", leading: "compact", weight: "plus", children: chip.name }) : /* @__PURE__ */ jsx4(
            LinkButton,
            {
              to: `/categories/${chip.id}`,
              className: "txt-compact-xsmall-plus text-ui-fg-subtle hover:text-ui-fg-base focus-visible:text-ui-fg-base",
              children: chip.name
            }
          ),
          index < chips.length - 1 && /* @__PURE__ */ jsx4(TriangleRightMini, {})
        ] }, chip.id);
      }) })
    ] });
  }
  return /* @__PURE__ */ jsx4("div", { className: "grid grid-cols-1 items-start gap-x-2", children: chips.map((chip, index) => /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-x-0.5", children: [
    /* @__PURE__ */ jsx4(Text4, { size: "xsmall", leading: "compact", weight: "plus", children: chip.name }),
    index < chips.length - 1 && /* @__PURE__ */ jsx4(TriangleRightMini, {})
  ] }, chip.id)) });
};
var ChildrenDisplay = ({
  category
}) => {
  const {
    product_category: withChildren,
    isLoading
  } = useProductCategory(category.id, {
    fields: "id,name,category_children"
  });
  const chips = useMemo(() => getCategoryChildren(withChildren), [withChildren]);
  if (isLoading || !withChildren) {
    return /* @__PURE__ */ jsx4(Skeleton, { className: "h-5 w-16" });
  }
  if (!chips.length) {
    return /* @__PURE__ */ jsx4(Text4, { size: "small", leading: "compact", children: "-" });
  }
  return /* @__PURE__ */ jsx4("div", { className: "flex w-full flex-wrap gap-1", children: chips.map((chip) => /* @__PURE__ */ jsx4(Badge, { size: "2xsmall", className: "max-w-full", asChild: true, children: /* @__PURE__ */ jsx4(Link, { to: `/categories/${chip.id}`, children: /* @__PURE__ */ jsx4("span", { className: "truncate", children: chip.name }) }) }, chip.id)) });
};

// src/pages/categories/[id]/_components/category-product-section/category-product-section.tsx
import { Container as Container5, Heading as Heading5 } from "@medusajs/ui";
import { DisplayExtensionZone as DisplayExtensionZone5 } from "@mercurjs/dashboard-shared";
import { keepPreviousData } from "@tanstack/react-query";
import { useMemo as useMemo2, useState as useState2 } from "react";
import { useTranslation as useTranslation5 } from "react-i18next";
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
var PAGE_SIZE = 10;
var CategoryProductSection = ({
  category
}) => {
  const { t } = useTranslation5();
  const [selection, setSelection] = useState2({});
  const { raw, searchParams } = useProductTableQuery({
    pageSize: PAGE_SIZE
  });
  const { products, count, isLoading } = useProducts(
    {
      ...searchParams,
      category_id: [category.id],
      fields: "*categories.id",
      limit: searchParams.limit,
      offset: searchParams.offset
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const columns = useColumns();
  const { table } = useDataTable({
    data: Array.isArray(products) ? products.map((p) => ({
      ...p,
      images: p.images ?? null
    })) : [],
    columns,
    count,
    getRowId: (original) => original.id,
    pageSize: PAGE_SIZE,
    enableRowSelection: true,
    enablePagination: true,
    rowSelection: {
      state: selection,
      updater: setSelection
    }
  });
  return /* @__PURE__ */ jsxs5(Container5, { className: "divide-y p-0", children: [
    /* @__PURE__ */ jsx5("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsx5(Heading5, { level: "h2", children: t("products.domain") }) }),
    /* @__PURE__ */ jsx5(
      _DataTable,
      {
        table,
        columns,
        orderBy: [
          { key: "title", label: t("fields.title") },
          {
            key: "created_at",
            label: t("fields.createdAt")
          },
          {
            key: "updated_at",
            label: t("fields.updatedAt")
          }
        ],
        pageSize: PAGE_SIZE,
        count,
        navigateTo: (row) => `/products/${row.id}`,
        isLoading,
        queryObject: raw,
        noRecords: {
          message: t("categories.products.list.noRecordsMessage")
        }
      }
    ),
    /* @__PURE__ */ jsx5(DisplayExtensionZone5, { model: "category", zone: "products", data: category })
  ] });
};
var useColumns = () => {
  const base = useProductTableColumns();
  return useMemo2(
    () => [
      // columnHelper.display({
      //   id: "select",
      //   header: ({ table }) => {
      //     return (
      //       <Checkbox
      //         checked={
      //           table.getIsSomePageRowsSelected()
      //             ? "indeterminate"
      //             : table.getIsAllPageRowsSelected()
      //         }
      //         onCheckedChange={(value) =>
      //           table.toggleAllPageRowsSelected(!!value)
      //         }
      //       />
      //     )
      //   },
      //   cell: ({ row }) => {
      //     return (
      //       <Checkbox
      //         checked={row.getIsSelected()}
      //         onCheckedChange={(value) => row.toggleSelected(!!value)}
      //         onClick={(e) => {
      //           e.stopPropagation()
      //         }}
      //       />
      //     )
      //   },
      // }),
      ...base
    ],
    [base]
  );
};

// src/pages/categories/[id]/category-detail-page.tsx
import { Fragment, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const { id } = useParams();
  const linkQuery = useLinkQuery("category", "+is_active,+is_internal");
  const {
    product_category,
    isLoading: categoryLoading,
    isError: categoryError,
    error
  } = useProductCategory(id, linkQuery);
  if (categoryLoading || !product_category) {
    return /* @__PURE__ */ jsx6(
      TwoColumnPageSkeleton,
      {
        mainSections: 4,
        sidebarSections: 1,
        showJSON: true,
        showMetadata: true
      }
    );
  }
  if (categoryError) {
    throw error;
  }
  return /* @__PURE__ */ jsx6(Fragment, { children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs6(TwoColumnPage, { data: product_category, children: [
    /* @__PURE__ */ jsx6(TwoColumnPage.Main, { children: /* @__PURE__ */ jsxs6(WidgetZone, { id: "categories.detail.main", data: product_category, children: [
      /* @__PURE__ */ jsx6(CategoryGeneralSection, { category: product_category }),
      /* @__PURE__ */ jsx6(CategoryMediaSection, { category: product_category }),
      /* @__PURE__ */ jsx6(CategoryIconSection, { category: product_category }),
      /* @__PURE__ */ jsx6(CategoryProductSection, { category: product_category })
    ] }) }),
    /* @__PURE__ */ jsx6(TwoColumnPage.Sidebar, { children: /* @__PURE__ */ jsx6(WidgetZone, { id: "categories.detail.side", data: product_category, children: /* @__PURE__ */ jsx6(CategoryOrganizeSection, { category: product_category }) }) })
  ] }) });
};
var CategoryDetailPage = Object.assign(Root, {
  Main: TwoColumnPage.Main,
  Sidebar: TwoColumnPage.Sidebar,
  MainGeneralSection: CategoryGeneralSection,
  MainMediaSection: CategoryMediaSection,
  MainIconSection: CategoryIconSection,
  MainProductSection: CategoryProductSection,
  SidebarOrganizeSection: CategoryOrganizeSection
});
export {
  CategoryDetailPage,
  loader
};
