import {
  SectionRow
} from "./chunk-3XPXUIK3.js";
import {
  SingleColumnPage
} from "./chunk-H6MYB7GB.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useDeleteShippingProfile,
  useShippingProfile
} from "./chunk-N6SI4IIT.js";

// src/pages/shipping-profiles/shipping-profile-detail/shipping-profile-detail.tsx
import { Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";

// src/pages/shipping-profiles/shipping-profile-detail/components/shipping-profile-general-section/shipping-profile-general-section.tsx
import { Trash } from "@medusajs/icons";
import { Container, Heading, toast, usePrompt } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { jsx, jsxs } from "react/jsx-runtime";
var ShippingProfileGeneralSection = ({
  profile
}) => {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const navigate = useNavigate();
  const { mutateAsync } = useDeleteShippingProfile(profile.id);
  const handleDelete = async () => {
    const res = await prompt({
      title: t("shippingProfile.delete.title"),
      description: t("shippingProfile.delete.description", {
        name: profile.name
      }),
      verificationText: profile.name,
      verificationInstruction: t("general.typeToConfirm"),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast.success(
          t("shippingProfile.delete.successToast", {
            name: profile.name
          })
        );
        navigate("/settings/locations/shipping-profiles", { replace: true });
      },
      onError: (error) => {
        toast.error(error.message);
      }
    });
  };
  return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", "data-testid": "shipping-profile-general-section-container", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", "data-testid": "shipping-profile-general-section-header", children: [
      /* @__PURE__ */ jsx(Heading, { "data-testid": "shipping-profile-general-section-heading", children: profile.name }),
      /* @__PURE__ */ jsx(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  icon: /* @__PURE__ */ jsx(Trash, {}),
                  label: t("actions.delete"),
                  onClick: handleDelete
                }
              ]
            }
          ],
          "data-testid": "shipping-profile-general-section-action-menu"
        }
      )
    ] }),
    /* @__PURE__ */ jsx(SectionRow, { title: t("fields.type"), value: profile.type, "data-testid": "shipping-profile-general-section-type-row" })
  ] });
};

// src/pages/shipping-profiles/shipping-profile-detail/shipping-profile-detail.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const { shipping_profile_id } = useParams();
  const initialData = useLoaderData();
  const { shipping_profile, isLoading, isError, error } = useShippingProfile(
    shipping_profile_id,
    void 0,
    { initialData }
  );
  if (isLoading || !shipping_profile) {
    return /* @__PURE__ */ jsx2(SingleColumnPageSkeleton, { sections: 1, showJSON: true, showMetadata: true });
  }
  if (isError) {
    throw error;
  }
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx2(SingleColumnPage, { showMetadata: true, showJSON: true, data: shipping_profile, children }) : /* @__PURE__ */ jsx2(SingleColumnPage, { showMetadata: true, showJSON: true, data: shipping_profile, children: /* @__PURE__ */ jsx2(ShippingProfileGeneralSection, { profile: shipping_profile }) });
};
var ShippingProfileDetailPage = Object.assign(Root, {
  GeneralSection: ShippingProfileGeneralSection
});

export {
  ShippingProfileDetailPage
};
