import {
  useCollectionTableColumns
} from "./chunk-YNGA3GRX.js";
import {
  useCollectionTableQuery
} from "./chunk-BI2AYXZQ.js";
import {
  useCollectionTableFilters
} from "./chunk-HHD2VUED.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-7TQNE3E2.js";
import {
  useCollections
} from "./chunk-XKEYHWBS.js";

// src/pages/collections/collection-list-page.tsx
import { Children as Children3 } from "react";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/collections/_components/collection-list-table/collection-list-table.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";
import { Outlet } from "react-router-dom";

// src/pages/collections/_components/collection-list-table/collection-list-header.tsx
import { Children } from "react";
import { useTranslation } from "react-i18next";
import { Heading, Text } from "@medusajs/ui";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var CollectionListTitle = () => {
  const { t } = useTranslation();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx(Heading, { children: t("collections.domain") }),
    /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: t("collections.subtitle") })
  ] });
};
var CollectionListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center gap-x-2", children });
};
var CollectionListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(CollectionListTitle, {}),
    /* @__PURE__ */ jsx(CollectionListActions, {})
  ] }) });
};

// src/pages/collections/_components/collection-list-table/collection-list-data-table.tsx
import { useTranslation as useTranslation2 } from "react-i18next";
import { keepPreviousData } from "@tanstack/react-query";
import { useMemo } from "react";
import { useExtendableTable, useLinkQuery } from "@mercurjs/dashboard-shared";
import { jsx as jsx2 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var CollectionListDataTable = () => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useCollectionTableQuery({
    pageSize: PAGE_SIZE
  });
  const { collections, count, isError, error, isLoading } = useCollections(
    {
      ...searchParams,
      ...useLinkQuery("collection", "*products")
    },
    {
      placeholderData: keepPreviousData
    }
  );
  const baseFilters = useCollectionTableFilters();
  const { columns, filters: extFilters } = useColumns();
  const filters = useMemo(
    () => [...baseFilters, ...extFilters],
    [baseFilters, extFilters]
  );
  const { table } = useDataTable({
    data: collections ?? [],
    columns,
    count,
    enablePagination: true,
    getRowId: (row, index) => row.id ?? `${index}`,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(
    _DataTable,
    {
      table,
      columns,
      pageSize: PAGE_SIZE,
      count,
      filters,
      orderBy: [
        { key: "title", label: t("fields.title") },
        { key: "handle", label: t("fields.handle") },
        {
          key: "created_at",
          label: t("fields.createdAt")
        },
        {
          key: "updated_at",
          label: t("fields.updatedAt")
        }
      ],
      search: true,
      navigateTo: (row) => `/collections/${row.original.id}`,
      queryObject: raw,
      isLoading
    }
  );
};
var useColumns = () => {
  const base = useCollectionTableColumns();
  const { columns: extended, filters } = useExtendableTable({
    model: "collection",
    columns: base
  });
  const columns = useMemo(() => [...extended], [extended]);
  return { columns, filters };
};

// src/pages/collections/_components/collection-list-table/collection-list-table.tsx
import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
var CollectionListTable = ({ children }) => {
  return /* @__PURE__ */ jsxs2(Container, { className: "divide-y p-0", children: [
    Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment2, { children: [
      /* @__PURE__ */ jsx3(CollectionListHeader, {}),
      /* @__PURE__ */ jsx3(CollectionListDataTable, {})
    ] }),
    /* @__PURE__ */ jsx3(Outlet, {})
  ] });
};

// src/pages/collections/collection-list-page.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { children: /* @__PURE__ */ jsx4(WidgetZone, { id: "collections.list", children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(CollectionListTable, {}) }) });
};
var CollectionListPage = Object.assign(Root, {
  Table: CollectionListTable,
  Header: CollectionListHeader,
  HeaderTitle: CollectionListTitle,
  HeaderActions: CollectionListActions,
  DataTable: CollectionListDataTable
});

export {
  CollectionListPage
};
