import {
  SectionRow
} from "./chunk-4TLP3TAA.js";
import {
  SingleColumnPage
} from "./chunk-YV6MK4PZ.js";
import {
  SingleColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import "./chunk-LAVHRER2.js";
import "./chunk-Y7QKP6QU.js";
import {
  shippingProfileQueryKeys,
  useDeleteShippingProfile,
  useShippingProfile
} from "./chunk-EPSDO2MJ.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import "./chunk-ZA2KFUFR.js";
import {
  fetchQuery
} from "./chunk-DTGEFKK4.js";
import "./chunk-NBMM2TZK.js";

// src/pages/settings/shipping-profiles/[id]/loader.ts
var shippingProfileQuery = (id) => ({
  queryKey: shippingProfileQueryKeys.detail(id),
  queryFn: async () => fetchQuery(`/vendor/shipping-profiles/${id}`, {
    method: "GET"
  })
});
var shippingProfileLoader = async ({ params }) => {
  const id = params.shipping_profile_id;
  const query = shippingProfileQuery(id);
  return queryClient.ensureQueryData(query);
};

// src/pages/settings/shipping-profiles/[id]/shipping-profile-detail-page.tsx
import { Children } from "react";
import { useLoaderData, useParams } from "react-router-dom";
import { WidgetZone } from "@mercurjs/dashboard-shared";

// src/pages/settings/shipping-profiles/[id]/_components/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", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
      /* @__PURE__ */ jsx(Heading, { children: profile.name }),
      /* @__PURE__ */ jsx(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  icon: /* @__PURE__ */ jsx(Trash, {}),
                  label: t("actions.delete"),
                  onClick: handleDelete
                }
              ]
            }
          ]
        }
      )
    ] }),
    /* @__PURE__ */ jsx(SectionRow, { title: t("fields.type"), value: profile.type })
  ] });
};

// src/pages/settings/shipping-profiles/[id]/shipping-profile-detail-page.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 });
  }
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx2(SingleColumnPage, { data: shipping_profile, children: Children.count(children) > 0 ? children : /* @__PURE__ */ jsx2(WidgetZone, { id: "shipping-profiles.detail.main", data: shipping_profile, children: /* @__PURE__ */ jsx2(ShippingProfileGeneralSection, { profile: shipping_profile }) }) });
};
var ShippingProfileDetailPage = Object.assign(Root, {
  GeneralSection: ShippingProfileGeneralSection
});
export {
  ShippingProfileDetailPage,
  shippingProfileLoader
};
