import {
  useRefundReasonTableColumns
} from "./chunk-5A4JNOK3.js";
import {
  SingleColumnPage
} from "./chunk-XIZLPYEE.js";
import {
  DataTable
} from "./chunk-UQITHKTH.js";
import {
  useRefundReasonTableQuery
} from "./chunk-NNI6QKKZ.js";
import {
  useDeleteRefundReasonLazy,
  useRefundReasons
} from "./chunk-3MDRW5MA.js";

// src/pages/refund-reasons/refund-reason-list/refund-reason-list.tsx
import { Children as Children3 } from "react";

// src/pages/refund-reasons/refund-reason-list/components/refund-reason-list-table/refund-reason-list-table.tsx
import { Children as Children2 } from "react";

// src/pages/refund-reasons/refund-reason-list/components/refund-reason-list-table/refund-reason-list-data-table.tsx
import { useCallback, useMemo } from "react";
import { PencilSquare, Trash } from "@medusajs/icons";
import {
  Container,
  createDataTableColumnHelper,
  toast,
  usePrompt
} from "@medusajs/ui";
import { keepPreviousData } from "@tanstack/react-query";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { jsx } from "react/jsx-runtime";
var PAGE_SIZE = 20;
var RefundReasonListDataTable = () => {
  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/pages/refund-reasons/refund-reason-list/components/refund-reason-list-table/refund-reason-list-header.tsx
import { Children } from "react";
import { Heading, Text } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
var RefundReasonListTitle = () => {
  const { t } = useTranslation2();
  return /* @__PURE__ */ jsxs("div", { children: [
    /* @__PURE__ */ jsx2(Heading, { children: t("refundReasons.domain") }),
    /* @__PURE__ */ jsx2(Text, { className: "text-ui-fg-subtle", size: "small", children: t("refundReasons.subtitle") })
  ] });
};
var RefundReasonListActions = ({
  children
}) => {
  return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-center gap-x-2", children });
};
var RefundReasonListHeader = ({
  children
}) => {
  return /* @__PURE__ */ jsx2("div", { className: "flex items-center justify-between px-6 py-4", children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx2(RefundReasonListTitle, {}),
    /* @__PURE__ */ jsx2(RefundReasonListActions, {})
  ] }) });
};

// src/pages/refund-reasons/refund-reason-list/components/refund-reason-list-table/refund-reason-list-table.tsx
import { Fragment as Fragment2, jsx as jsx3 } from "react/jsx-runtime";
var RefundReasonListTable = ({ children }) => {
  return Children2.count(children) > 0 ? /* @__PURE__ */ jsx3(Fragment2, { children }) : /* @__PURE__ */ jsx3(RefundReasonListDataTable, {});
};

// src/pages/refund-reasons/refund-reason-list/refund-reason-list.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  return /* @__PURE__ */ jsx4(SingleColumnPage, { showMetadata: false, showJSON: false, hasOutlet: true, children: Children3.count(children) > 0 ? children : /* @__PURE__ */ jsx4(RefundReasonListTable, {}) });
};
var RefundReasonList = Object.assign(Root, {
  Table: RefundReasonListTable,
  Header: RefundReasonListHeader,
  HeaderTitle: RefundReasonListTitle,
  HeaderActions: RefundReasonListActions,
  DataTable: RefundReasonListDataTable
});

export {
  RefundReasonList
};
