import {
  useDeleteReturnReason,
  useReturnReasons
} from "./chunk-65HHU6D3.js";
import {
  useReturnReasonTableColumns
} from "./chunk-N335VHD3.js";
import "./chunk-EBZ5VZEO.js";
import "./chunk-4F5GP7J7.js";
import "./chunk-7TIZP4YG.js";
import "./chunk-GJM5XI3E.js";
import "./chunk-YNGA3GRX.js";
import {
  useReturnReasonTableQuery
} from "./chunk-BI2AYXZQ.js";
import "./chunk-MG4GKUJW.js";
import "./chunk-AYVH6Q5O.js";
import "./chunk-VOHEQ7B5.js";
import "./chunk-DY3XQPHC.js";
import "./chunk-GRH7C3QN.js";
import "./chunk-VKOE5J66.js";
import "./chunk-42R54Z2X.js";
import "./chunk-Y6S7K3YB.js";
import "./chunk-N3T24SEK.js";
import "./chunk-JHIMVLB2.js";
import "./chunk-HRUO43BZ.js";
import "./chunk-XBKWFLJG.js";
import "./chunk-HB3BP55W.js";
import "./chunk-SYNUA6LQ.js";
import "./chunk-5YZ3G5EZ.js";
import "./chunk-VW56KWO2.js";
import "./chunk-T35QBLG7.js";
import "./chunk-XCHKUSUU.js";
import "./chunk-JRTZWK77.js";
import "./chunk-AAKR2CB4.js";
import "./chunk-G64YUZSL.js";
import "./chunk-BEPAXQMU.js";
import "./chunk-FWPGOIFA.js";
import "./chunk-DB6ANJBO.js";
import "./chunk-PHOCVOZ5.js";
import "./chunk-IQPN4PZJ.js";
import {
  SingleColumnPage
} 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 "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import "./chunk-QHQWEERJ.js";
import "./chunk-Y7QKP6QU.js";
import "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import "./chunk-DTGEFKK4.js";
import "./chunk-NBMM2TZK.js";

// src/pages/settings/return-reasons/index.tsx
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/return-reasons/_components/return-reason-list-table.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import { Button, Container, Heading, Text } from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { createColumnHelper } from "@tanstack/react-table";
import { useMemo } from "react";
import { useTranslation as useTranslation2 } from "react-i18next";
import { Link } from "react-router-dom";

// src/pages/settings/return-reasons/_common/hooks/use-delete-return-reason-action.tsx
import { toast, usePrompt } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
var useDeleteReturnReasonAction = ({
  id,
  label
}) => {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const { mutateAsync } = useDeleteReturnReason(id);
  const handleDelete = async () => {
    const result = await prompt({
      title: t("general.areYouSure"),
      description: t("returnReasons.delete.confirmation", {
        label
      }),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!result) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast.success(t("returnReasons.delete.successToast", { label }));
      },
      onError: (e) => {
        toast.error(e.message);
      }
    });
  };
  return handleDelete;
};

// src/pages/settings/return-reasons/_components/return-reason-list-table.tsx
import { jsx, jsxs } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var ReturnReasonListTable = () => {
  const { t } = useTranslation2();
  const { searchParams, raw } = useReturnReasonTableQuery({
    pageSize: PAGE_SIZE
  });
  const { return_reasons, count, isPending, isError, error } = useReturnReasons(
    searchParams,
    {
      placeholderData: keepPreviousData
    }
  );
  const columns = useColumns();
  const { table } = useDataTable({
    data: return_reasons,
    columns,
    count,
    getRowId: (row) => row.id,
    pageSize: PAGE_SIZE
  });
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y px-0 py-0", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx(Heading, { children: t("returnReasons.domain") }),
        /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", size: "small", children: t("returnReasons.subtitle") })
      ] }),
      /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", asChild: true, children: /* @__PURE__ */ jsx(Link, { to: "create", children: t("actions.create") }) })
    ] }),
    /* @__PURE__ */ jsx(
      _DataTable,
      {
        table,
        queryObject: raw,
        count,
        isLoading: isPending,
        columns,
        pageSize: PAGE_SIZE,
        noHeader: true,
        pagination: true,
        search: true
      }
    )
  ] });
};
var ReturnReasonRowActions = ({
  returnReason
}) => {
  const { t } = useTranslation2();
  const handleDelete = useDeleteReturnReasonAction(returnReason);
  return /* @__PURE__ */ jsx(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(PencilSquare, {}),
              label: t("actions.edit"),
              to: `${returnReason.id}/edit`
            }
          ]
        },
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(Trash, {}),
              label: t("actions.delete"),
              onClick: handleDelete
            }
          ]
        }
      ]
    }
  );
};
var columnHelper = createColumnHelper();
var useColumns = () => {
  const base = useReturnReasonTableColumns();
  return useMemo(
    () => [
      ...base,
      columnHelper.display({
        id: "actions",
        cell: ({ row }) => /* @__PURE__ */ jsx(ReturnReasonRowActions, { returnReason: row.original })
      })
    ],
    [base]
  );
};

// src/pages/settings/return-reasons/index.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var ReturnReasonList = () => {
  return /* @__PURE__ */ jsx2(SingleColumnPage, { showMetadata: false, showJSON: false, hasOutlet: true, children: /* @__PURE__ */ jsx2(WidgetZone, { id: "return-reasons.list", children: /* @__PURE__ */ jsx2(ReturnReasonListTable, {}) }) });
};
var Component = ReturnReasonList;
export {
  Component
};
