import {
  useRefundReasonTableColumns
} from "./chunk-LR4WE7QF.mjs";
import "./chunk-ATKJ6XLW.mjs";
import "./chunk-QMRGIWOP.mjs";
import "./chunk-UNTEPIJL.mjs";
import "./chunk-GSZPEFBC.mjs";
import "./chunk-I3VB6NM2.mjs";
import "./chunk-K44PQXQY.mjs";
import "./chunk-EWVOEKUL.mjs";
import "./chunk-5O7HGXFV.mjs";
import "./chunk-IR5DHEKS.mjs";
import "./chunk-DRHDNSJA.mjs";
import "./chunk-5LFJGD27.mjs";
import "./chunk-EJWRAUTW.mjs";
import "./chunk-NTEWUH4C.mjs";
import "./chunk-INE2QCSC.mjs";
import "./chunk-4AKNAVPX.mjs";
import "./chunk-V2CZ23VK.mjs";
import "./chunk-IQBAUTU5.mjs";
import "./chunk-ADOCJB6L.mjs";
import "./chunk-X6BAAGCL.mjs";
import "./chunk-P3UUX2T6.mjs";
import "./chunk-DK4WIVY6.mjs";
import {
  useRefundReasonTableQuery
} from "./chunk-EJUI5JDF.mjs";
import "./chunk-RIV7FKGN.mjs";
import "./chunk-TDK3JDOB.mjs";
import "./chunk-FHSC5X62.mjs";
import "./chunk-XR4GEMGR.mjs";
import "./chunk-WRSGHGAT.mjs";
import "./chunk-MOSRJHJ3.mjs";
import "./chunk-OMC5JCQH.mjs";
import "./chunk-UVGVVAR4.mjs";
import "./chunk-R65S6ZZV.mjs";
import {
  SingleColumnPage
} from "./chunk-GIZFNLKK.mjs";
import {
  DataTable
} from "./chunk-327JQRJK.mjs";
import "./chunk-C76H5USB.mjs";
import "./chunk-3BQAAPDR.mjs";
import "./chunk-MNXC6Q4F.mjs";
import "./chunk-DG7J63J2.mjs";
import "./chunk-PJU3RODH.mjs";
import {
  useExtension
} from "./chunk-C5P5PL3E.mjs";
import "./chunk-OZPB6JBL.mjs";
import "./chunk-OC7BQLYI.mjs";
import "./chunk-S4DMV3ZT.mjs";
import "./chunk-QJ63TWAK.mjs";
import {
  refundReasonsQueryKeys,
  useDeleteRefundReasonLazy,
  useRefundReasons
} from "./chunk-OW2UL5FI.mjs";
import "./chunk-5DUV4AET.mjs";
import "./chunk-FAB3VINY.mjs";
import "./chunk-Q7YBE4IP.mjs";
import "./chunk-HI6URQ7H.mjs";
import "./chunk-6CLQKVAU.mjs";
import "./chunk-KI7TOXBR.mjs";
import "./chunk-QBIQEVTU.mjs";
import "./chunk-WAXMT4IY.mjs";
import "./chunk-DYDGGABK.mjs";
import "./chunk-LGNTHZ5Y.mjs";
import "./chunk-CN7JXSGW.mjs";
import "./chunk-AO2USOOE.mjs";
import "./chunk-KWWLGCSY.mjs";
import "./chunk-5AFMB7XQ.mjs";
import "./chunk-5U6AZEO7.mjs";
import "./chunk-A63RZVX6.mjs";
import "./chunk-HBXV7ENS.mjs";
import "./chunk-ZBMENGLV.mjs";
import "./chunk-LGLPAUIO.mjs";
import "./chunk-CDORR33H.mjs";
import "./chunk-DE44HCDH.mjs";
import "./chunk-MUOBXNL6.mjs";
import "./chunk-BEQ5XTWH.mjs";
import "./chunk-HP2JH45P.mjs";
import "./chunk-VCSSQVPD.mjs";
import "./chunk-SQDIZZDW.mjs";
import "./chunk-LA2ILUXH.mjs";
import "./chunk-7AXHHXCX.mjs";
import {
  queryClient
} from "./chunk-FXYH54JP.mjs";
import "./chunk-774WSTCC.mjs";
import {
  sdk
} from "./chunk-NFEK63OE.mjs";
import "./chunk-QZ7TP4HQ.mjs";

// src/routes/refund-reasons/refund-reason-list/loader.ts
var refundReasonListQuery = () => ({
  queryKey: refundReasonsQueryKeys.list(),
  queryFn: async () => sdk.admin.refundReason.list()
});
var refundReasonListLoader = async () => {
  const query = refundReasonListQuery();
  return queryClient.getQueryData(query.queryKey) ?? await queryClient.fetchQuery(query);
};

// src/routes/refund-reasons/refund-reason-list/components/refund-reason-list-table/refund-reason-list-table.tsx
import { PencilSquare, Trash } from "@medusajs/icons";
import {
  Container,
  createDataTableColumnHelper,
  toast,
  usePrompt
} from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { useCallback, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { jsx } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var RefundReasonListTable = () => {
  const { t } = useTranslation();
  const { searchParams } = useRefundReasonTableQuery({
    pageSize: PAGE_SIZE
  });
  const { refund_reasons, count, isLoading, isError, error } = useRefundReasons(
    searchParams,
    {
      placeholderData: keepPreviousData
    }
  );
  const columns = useColumns();
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx(Container, { className: "divide-y px-0 py-0", children: /* @__PURE__ */ jsx(
    DataTable,
    {
      data: refund_reasons,
      columns,
      rowCount: count,
      pageSize: PAGE_SIZE,
      getRowId: (row) => row.id,
      heading: t("refundReasons.domain"),
      subHeading: t("refundReasons.subtitle"),
      emptyState: {
        empty: {
          heading: t("general.noRecordsMessage")
        },
        filtered: {
          heading: t("general.noRecordsMessage"),
          description: t("general.noRecordsMessageFiltered")
        }
      },
      actions: [
        {
          label: t("actions.create"),
          to: "create"
        }
      ],
      isLoading,
      enableSearch: true
    }
  ) });
};
var columnHelper = createDataTableColumnHelper();
var useColumns = () => {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const navigate = useNavigate();
  const base = useRefundReasonTableColumns();
  const { mutateAsync } = useDeleteRefundReasonLazy();
  const handleDelete = useCallback(
    async (refundReason) => {
      const confirm = await prompt({
        title: t("general.areYouSure"),
        description: t("refundReasons.delete.confirmation", {
          label: refundReason.label
        }),
        confirmText: t("actions.delete"),
        cancelText: t("actions.cancel")
      });
      if (!confirm) {
        return;
      }
      await mutateAsync(refundReason.id, {
        onSuccess: () => {
          toast.success(t("refundReasons.delete.successToast"));
        },
        onError: (e) => {
          toast.error(e.message);
        }
      });
    },
    [t, prompt, mutateAsync]
  );
  return useMemo(
    () => [
      ...base,
      columnHelper.action({
        actions: (ctx) => [
          [
            {
              icon: /* @__PURE__ */ jsx(PencilSquare, {}),
              label: t("actions.edit"),
              onClick: () => navigate(
                `/settings/refund-reasons/${ctx.row.original.id}/edit`
              )
            }
          ],
          [
            {
              icon: /* @__PURE__ */ jsx(Trash, {}),
              label: t("actions.delete"),
              onClick: () => handleDelete(ctx.row.original)
            }
          ]
        ]
      })
    ],
    [base, handleDelete, navigate, t]
  );
};

// src/routes/refund-reasons/refund-reason-list/refund-reason-list.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var RefundReasonList = () => {
  const { getWidgets } = useExtension();
  return /* @__PURE__ */ jsx2(
    SingleColumnPage,
    {
      showMetadata: false,
      showJSON: false,
      hasOutlet: true,
      widgets: {
        after: getWidgets("refund_reason.list.after"),
        before: getWidgets("refund_reason.list.before")
      },
      children: /* @__PURE__ */ jsx2(RefundReasonListTable, {})
    }
  );
};
export {
  RefundReasonList as Component,
  refundReasonListLoader as loader
};
