import {
  useDeleteShippingOptionTypeAction
} from "./chunk-VXPWOEUS.js";
import {
  DateCell
} from "./chunk-25LYVP3C.js";
import {
  TextCell
} from "./chunk-JHIMVLB2.js";
import {
  _DataTable,
  useDataTable
} from "./chunk-ULJ3OMWU.js";
import {
  SingleColumnPage
} from "./chunk-XIZLPYEE.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useDateTableFilters
} from "./chunk-26OOAKQ6.js";
import {
  useQueryParams
} from "./chunk-THHRRYRS.js";
import {
  useShippingOptionTypes
} from "./chunk-3MDRW5MA.js";

// src/pages/shipping-option-types/shipping-option-type-list/shipping-option-type-list.tsx
import { Children as Children3 } from "react";

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-view/shipping-option-type-list-view.tsx
import { Children as Children2 } from "react";
import { Container } from "@medusajs/ui";

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-view/shipping-option-type-list-data-table.tsx
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper as createColumnHelper2 } from "@tanstack/react-table";
import { useMemo as useMemo2 } from "react";
import { useTranslation as useTranslation3 } from "react-i18next";

// src/hooks/table/columns/use-shipping-option-type-table-columns.tsx
import { createColumnHelper } from "@tanstack/react-table";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { jsx } from "react/jsx-runtime";
var columnHelper = createColumnHelper();
var useShippingOptionTypeTableColumns = () => {
  const { t } = useTranslation();
  return useMemo(
    () => [
      columnHelper.accessor("label", {
        header: () => t("fields.label"),
        cell: ({ getValue }) => /* @__PURE__ */ jsx(TextCell, { text: getValue() })
      }),
      columnHelper.accessor("code", {
        header: () => t("fields.code"),
        cell: ({ getValue }) => /* @__PURE__ */ jsx(TextCell, { text: getValue() })
      }),
      columnHelper.accessor("description", {
        header: () => t("fields.description"),
        cell: ({ getValue }) => /* @__PURE__ */ jsx(TextCell, { text: getValue() })
      }),
      columnHelper.accessor("created_at", {
        header: () => t("fields.createdAt"),
        cell: ({ getValue }) => {
          return /* @__PURE__ */ jsx(DateCell, { date: getValue() });
        }
      }),
      columnHelper.accessor("updated_at", {
        header: () => t("fields.updatedAt"),
        cell: ({ getValue }) => {
          return /* @__PURE__ */ jsx(DateCell, { date: getValue() });
        }
      })
    ],
    [t]
  );
};

// src/hooks/table/filters/use-shipping-option-type-table-filters.tsx
var useShippingOptionTypeTableFilters = () => {
  return useDateTableFilters();
};

// src/hooks/table/query/use-shipping-option-type-table-query.tsx
var useShippingOptionTypeTableQuery = ({
  prefix,
  pageSize = 20
}) => {
  const queryObject = useQueryParams(
    ["offset", "q", "order", "created_at", "updated_at"],
    prefix
  );
  const { offset, q, order, created_at, updated_at } = queryObject;
  const searchParams = {
    limit: pageSize,
    offset: offset ? Number(offset) : 0,
    order,
    created_at: created_at ? JSON.parse(created_at) : void 0,
    updated_at: updated_at ? JSON.parse(updated_at) : void 0,
    q
  };
  return {
    searchParams,
    raw: queryObject
  };
};

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-table/shipping-option-type-table-row-actions.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2 } from "react/jsx-runtime";
var ShippingOptionTypeRowActions = ({
  shippingOptionType
}) => {
  const { t } = useTranslation2();
  const handleDelete = useDeleteShippingOptionTypeAction(
    shippingOptionType.id,
    shippingOptionType.label
  );
  return /* @__PURE__ */ jsx2(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              label: t("actions.edit"),
              icon: /* @__PURE__ */ jsx2(PencilSquare, {}),
              to: `/settings/locations/shipping-option-types/${shippingOptionType.id}/edit`
            }
          ]
        },
        {
          actions: [
            {
              label: t("actions.delete"),
              icon: /* @__PURE__ */ jsx2(Trash, {}),
              onClick: handleDelete
            }
          ]
        }
      ],
      "data-testid": `shipping-option-type-list-table-action-menu-${shippingOptionType.id}`
    }
  );
};

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-view/shipping-option-type-list-data-table.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ShippingOptionTypeListDataTable = () => {
  const { t } = useTranslation3();
  const { searchParams, raw } = useShippingOptionTypeTableQuery({
    pageSize: PAGE_SIZE
  });
  const { shipping_option_types, count, isLoading, isError, error } = useShippingOptionTypes(
    searchParams,
    {
      placeholderData: keepPreviousData
    }
  );
  const filters = useShippingOptionTypeTableFilters();
  const columns = useColumns();
  const { table } = useDataTable({
    columns,
    data: shipping_option_types,
    count,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx3(
    _DataTable,
    {
      table,
      filters,
      isLoading,
      columns,
      pageSize: PAGE_SIZE,
      count,
      orderBy: [
        { key: "label", label: t("fields.label") },
        { key: "code", label: t("fields.code") },
        { key: "description", label: t("fields.description") },
        { key: "created_at", label: t("fields.createdAt") },
        { key: "updated_at", label: t("fields.updatedAt") }
      ],
      navigateTo: ({ original }) => original.id,
      queryObject: raw,
      pagination: true,
      search: true,
      "data-testid": "shipping-option-type-list-table"
    }
  );
};
var columnHelper2 = createColumnHelper2();
var useColumns = () => {
  const base = useShippingOptionTypeTableColumns();
  return useMemo2(
    () => [
      ...base,
      columnHelper2.display({
        id: "actions",
        cell: ({ row }) => {
          return /* @__PURE__ */ jsx3(ShippingOptionTypeRowActions, { shippingOptionType: row.original });
        }
      })
    ],
    [base]
  );
};

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-view/shipping-option-type-list-header.tsx
import { Children } from "react";
import { Button, Heading, Text } from "@medusajs/ui";
import { useTranslation as useTranslation4 } from "react-i18next";
import { Link } from "react-router-dom";
import { Fragment, jsx as jsx4, jsxs } from "react/jsx-runtime";
var ShippingOptionTypeListTitle = () => {
  const { t } = useTranslation4();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx4(Heading, { "data-testid": "shipping-option-type-list-table-heading", children: t("shippingOptionTypes.domain") }),
    /* @__PURE__ */ jsx4(
      Text,
      {
        className: "text-ui-fg-subtle",
        size: "small",
        "data-testid": "shipping-option-type-list-table-subtitle",
        children: t("shippingOptionTypes.subtitle")
      }
    )
  ] });
};
var ShippingOptionTypeListActions = ({
  children
}) => {
  const { t } = useTranslation4();
  return /* @__PURE__ */ jsx4("div", { className: "flex items-center justify-center gap-x-2", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx4(
    Button,
    {
      size: "small",
      variant: "secondary",
      asChild: true,
      "data-testid": "shipping-option-type-list-table-create-button",
      children: /* @__PURE__ */ jsx4(Link, { to: "create", children: t("actions.create") })
    }
  ) });
};
var ShippingOptionTypeListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx4(
    "div",
    {
      className: "flex items-center justify-between px-6 py-4",
      "data-testid": "shipping-option-type-list-table-header",
      children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
        /* @__PURE__ */ jsx4(ShippingOptionTypeListTitle, {}),
        /* @__PURE__ */ jsx4(ShippingOptionTypeListActions, {})
      ] })
    }
  );
};

// src/pages/shipping-option-types/shipping-option-type-list/components/shipping-option-type-list-view/shipping-option-type-list-view.tsx
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
var ShippingOptionTypeListView = ({
  children
}) => {
  return /* @__PURE__ */ jsx5(Container, { className: "divide-y p-0", children: Children2.count(children) > 0 ? children : /* @__PURE__ */ jsxs2(Fragment2, { children: [
    /* @__PURE__ */ jsx5(ShippingOptionTypeListHeader, {}),
    /* @__PURE__ */ jsx5(ShippingOptionTypeListDataTable, {})
  ] }) });
};

// src/pages/shipping-option-types/shipping-option-type-list/shipping-option-type-list.tsx
import { jsx as jsx6 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx6(SingleColumnPage, { children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx6(ShippingOptionTypeListView, {}) });
};
var ShippingOptionTypeListPage = Object.assign(Root, {
  Table: ShippingOptionTypeListView,
  Header: ShippingOptionTypeListHeader,
  HeaderTitle: ShippingOptionTypeListTitle,
  HeaderActions: ShippingOptionTypeListActions,
  DataTable: ShippingOptionTypeListDataTable
});

export {
  ShippingOptionTypeListPage
};
