import {
  useReturnReasonTableColumns
} from "./chunk-EMOXVKR2.mjs";
import "./chunk-JM2CPUB2.mjs";
import "./chunk-QMRGIWOP.mjs";
import "./chunk-UNTEPIJL.mjs";
import "./chunk-ZJRFL6ZN.mjs";
import "./chunk-I3VB6NM2.mjs";
import "./chunk-XWO5BP42.mjs";
import "./chunk-NGCHJNVG.mjs";
import "./chunk-2RHYDUMJ.mjs";
import "./chunk-IR5DHEKS.mjs";
import "./chunk-MSDRGCRR.mjs";
import "./chunk-WG7UTTKY.mjs";
import "./chunk-EJWRAUTW.mjs";
import "./chunk-NTEWUH4C.mjs";
import "./chunk-INE2QCSC.mjs";
import "./chunk-UWXFR2PA.mjs";
import "./chunk-ZU3LA52A.mjs";
import "./chunk-IQBAUTU5.mjs";
import "./chunk-ADOCJB6L.mjs";
import "./chunk-X6BAAGCL.mjs";
import "./chunk-P3UUX2T6.mjs";
import "./chunk-DK4WIVY6.mjs";
import {
  useReturnReasonTableQuery
} from "./chunk-MFALVTRQ.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-BD7FUNND.mjs";
import "./chunk-R65S6ZZV.mjs";
import {
  SingleColumnPage
} from "./chunk-GIZFNLKK.mjs";
import {
  DataTable
} from "./chunk-LIG5YESF.mjs";
import "./chunk-C76H5USB.mjs";
import "./chunk-3BQAAPDR.mjs";
import {
  returnReasonsQueryKeys,
  useDeleteReturnReason,
  useReturnReasons
} from "./chunk-S5TCP5QZ.mjs";
import "./chunk-MNXC6Q4F.mjs";
import "./chunk-DG7J63J2.mjs";
import "./chunk-G4BWCU5P.mjs";
import {
  useExtension
} from "./chunk-C5P5PL3E.mjs";
import "./chunk-OZPB6JBL.mjs";
import "./chunk-OC7BQLYI.mjs";
import "./chunk-S4DMV3ZT.mjs";
import "./chunk-QJ63TWAK.mjs";
import "./chunk-3BF5SC66.mjs";
import {
  queryClient
} from "./chunk-FXYH54JP.mjs";
import "./chunk-774WSTCC.mjs";
import {
  sdk
} from "./chunk-NFEK63OE.mjs";
import "./chunk-QZ7TP4HQ.mjs";

// src/routes/return-reasons/return-reason-list/loader.ts
var returnReasonListQuery = (query) => ({
  queryKey: returnReasonsQueryKeys.list(query),
  queryFn: async () => sdk.admin.returnReason.list(query)
});
var returnReasonListLoader = async () => {
  const query = returnReasonListQuery();
  return queryClient.getQueryData(query.queryKey) ?? await queryClient.fetchQuery(query);
};

// src/routes/return-reasons/return-reason-list/components/return-reason-list-table/return-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 ReturnReasonListTable = () => {
  const { t } = useTranslation();
  const { searchParams } = useReturnReasonTableQuery({
    pageSize: PAGE_SIZE
  });
  const { return_reasons, count, isLoading, isError, error } = useReturnReasons(
    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: return_reasons,
      columns,
      rowCount: count,
      pageSize: PAGE_SIZE,
      getRowId: (row) => row.id,
      heading: t("returnReasons.domain"),
      subHeading: t("returnReasons.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 = useReturnReasonTableColumns();
  const { mutateAsync } = useDeleteReturnReason();
  const handleDelete = useCallback(
    async (returnReason) => {
      const confirm = await prompt({
        title: t("general.areYouSure"),
        description: t("returnReasons.delete.confirmation", {
          label: returnReason.label
        }),
        confirmText: t("actions.delete"),
        cancelText: t("actions.cancel")
      });
      if (!confirm) {
        return;
      }
      await mutateAsync(returnReason.id, {
        onSuccess: () => {
          toast.success(
            t("returnReasons.delete.successToast", {
              label: returnReason.label
            })
          );
        },
        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/return-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/return-reasons/return-reason-list/return-reason-list.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var ReturnReasonList = () => {
  const { getWidgets } = useExtension();
  return /* @__PURE__ */ jsx2(
    SingleColumnPage,
    {
      showMetadata: false,
      showJSON: false,
      hasOutlet: true,
      widgets: {
        after: getWidgets("return_reason.list.after"),
        before: getWidgets("return_reason.list.before")
      },
      children: /* @__PURE__ */ jsx2(ReturnReasonListTable, {})
    }
  );
};
export {
  ReturnReasonList as Component,
  returnReasonListLoader as loader
};
