import {
  useDeleteProductTagAction
} from "./chunk-WRRMBJBQ.js";
import {
  useProductTagTableColumns
} from "./chunk-5A4JNOK3.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-KYPPQGGE.js";
import {
  SingleColumnPage
} from "./chunk-H6MYB7GB.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useProductTagTableFilters
} from "./chunk-KOURHC2N.js";
import {
  useProductTagTableQuery
} from "./chunk-HO7Z6MC3.js";
import {
  useProductTags
} from "./chunk-PBQ5M44A.js";

// src/pages/product-tags/product-tag-list/product-tag-list.tsx
import { Children as Children3 } from "react";

// src/pages/product-tags/product-tag-list/components/product-tag-list-view/product-tag-list-view.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";

// src/pages/product-tags/product-tag-list/components/product-tag-list-view/product-tag-list-data-table.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useLoaderData } from "react-router-dom";
import { jsx } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ProductTagListDataTable = () => {
  const { t } = useTranslation();
  const { searchParams, raw } = useProductTagTableQuery({
    pageSize: PAGE_SIZE
  });
  const initialData = useLoaderData();
  const { product_tags, count, isPending, isError, error } = useProductTags(
    searchParams,
    {
      initialData,
      placeholderData: keepPreviousData
    }
  );
  const columns = useColumns();
  const filters = useProductTagTableFilters();
  const { table } = useDataTable({
    data: product_tags,
    count,
    columns,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx(
    _DataTable,
    {
      table,
      filters,
      queryObject: raw,
      isLoading: isPending,
      columns,
      pageSize: PAGE_SIZE,
      count,
      navigateTo: (row) => row.original.id,
      search: true,
      pagination: true,
      orderBy: [
        { key: "value", label: t("fields.value") },
        { key: "created_at", label: t("fields.createdAt") },
        { key: "updated_at", label: t("fields.updatedAt") }
      ],
      "data-testid": "product-tag-list-table"
    }
  );
};
var ProductTagRowActions = ({
  productTag
}) => {
  const { t } = useTranslation();
  const handleDelete = useDeleteProductTagAction({ productTag });
  return /* @__PURE__ */ jsx(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(PencilSquare, {}),
              label: t("actions.edit"),
              to: `${productTag.id}/edit`
            }
          ]
        },
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(Trash, {}),
              label: t("actions.delete"),
              onClick: handleDelete
            }
          ]
        }
      ],
      "data-testid": `product-tag-list-table-action-menu-${productTag.id}`
    }
  );
};
var columnHelper = createColumnHelper();
var useColumns = () => {
  const base = useProductTagTableColumns();
  return useMemo(
    () => [
      ...base,
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => /* @__PURE__ */ jsx(ProductTagRowActions, { productTag: row.original })
      })
    ],
    [base]
  );
};

// src/pages/product-tags/product-tag-list/components/product-tag-list-view/product-tag-list-header.tsx
import { Children } from "react";
import { Button, Heading } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { Link } from "react-router-dom";
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
var ProductTagListTitle = () => {
  const { t } = useTranslation2();
  return /* @__PURE__ */ jsx2(Heading, { "data-testid": "product-tag-list-table-heading", children: t("productTags.domain") });
};
var ProductTagListActions = ({
  children
}) => {
  const { t } = useTranslation2();
  return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx2(
    Button,
    {
      variant: "secondary",
      size: "small",
      asChild: true,
      "data-testid": "product-tag-list-table-create-button",
      children: /* @__PURE__ */ jsx2(Link, { to: "create", children: t("actions.create") })
    }
  ) });
};
var ProductTagListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx2(
    "div",
    {
      className: "flex items-center justify-between px-6 py-4",
      "data-testid": "product-tag-list-table-header",
      children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx2(ProductTagListTitle, {}),
        /* @__PURE__ */ jsx2(ProductTagListActions, {})
      ] })
    }
  );
};

// src/pages/product-tags/product-tag-list/components/product-tag-list-view/product-tag-list-view.tsx
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var ProductTagListView = ({
  children
}) => {
  return /* @__PURE__ */ jsx3(Container, { className: "divide-y p-0", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment2, { children: [
    /* @__PURE__ */ jsx3(ProductTagListHeader, {}),
    /* @__PURE__ */ jsx3(ProductTagListDataTable, {})
  ] }) });
};

// src/pages/product-tags/product-tag-list/product-tag-list.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { showMetadata: false, showJSON: false, hasOutlet: true, children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(ProductTagListView, {}) });
};
var ProductTagListPage = Object.assign(Root, {
  Table: ProductTagListView,
  Header: ProductTagListHeader,
  HeaderTitle: ProductTagListTitle,
  HeaderActions: ProductTagListActions,
  DataTable: ProductTagListDataTable
});

export {
  ProductTagListPage
};
