import {
  ListSummary
} from "./chunk-4F5GP7J7.js";
import {
  formatProvider
} from "./chunk-VW56KWO2.js";
import {
  isOptionEnabledInStore,
  isReturnOption
} from "./chunk-HC25LNX7.js";
import {
  LinkButton
} from "./chunk-7AV5EJJ5.js";
import {
  IconAvatar
} from "./chunk-U2EI2ZLM.js";
import {
  getFormattedAddress
} from "./chunk-W6Y3PPU5.js";
import {
  countries
} from "./chunk-JRTZWK77.js";
import {
  TwoColumnPage
} from "./chunk-V5J73NPW.js";
import {
  NoRecords
} from "./chunk-3EF54XFY.js";
import {
  TwoColumnPageSkeleton
} from "./chunk-INNFZYX2.js";
import {
  ActionMenu
} from "./chunk-BDGZ4EQO.js";
import {
  useDeleteFulfillmentServiceZone,
  useDeleteFulfillmentSet
} from "./chunk-TPPONKYW.js";
import {
  useDeleteShippingOption
} from "./chunk-O4STPJR2.js";
import {
  useCreateStockLocationFulfillmentSet,
  useDeleteStockLocation,
  useFulfillmentProviders,
  useStockLocation
} from "./chunk-OFKUNYQJ.js";
import {
  useSalesChannels
} from "./chunk-N4JU7GWK.js";

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

// src/pages/locations/location-detail/components/location-general-section/location-general-section.tsx
import {
  ArchiveBox,
  CurrencyDollar,
  Map,
  PencilSquare,
  Plus,
  Trash,
  TriangleDownMini
} from "@medusajs/icons";
import {
  Badge,
  Container,
  Divider,
  Heading,
  IconButton,
  StatusBadge,
  Text,
  toast,
  usePrompt
} from "@medusajs/ui";
import { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var LocationGeneralSection = ({
  location
}) => {
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx(Container, { className: "p-0", "data-testid": "location-general-section-container", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", "data-testid": "location-general-section-header", children: [
      /* @__PURE__ */ jsxs("div", { "data-testid": "location-general-section-info", children: [
        /* @__PURE__ */ jsx(Heading, { "data-testid": "location-general-section-heading", children: location.name }),
        /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle txt-small", "data-testid": "location-general-section-address", children: getFormattedAddress({ address: location.address }).join(", ") })
      ] }),
      /* @__PURE__ */ jsx(Actions, { location })
    ] }) }),
    /* @__PURE__ */ jsx(
      FulfillmentSet,
      {
        locationId: location.id,
        locationName: location.name,
        type: "pickup" /* Pickup */,
        fulfillmentSet: location.fulfillment_sets?.find(
          (f) => f.type === "pickup" /* Pickup */
        )
      }
    ),
    /* @__PURE__ */ jsx(
      FulfillmentSet,
      {
        locationId: location.id,
        locationName: location.name,
        type: "shipping" /* Shipping */,
        fulfillmentSet: location.fulfillment_sets?.find(
          (f) => f.type === "shipping" /* Shipping */
        )
      }
    )
  ] });
};
function ShippingOption({
  option,
  fulfillmentSetId,
  locationId
}) {
  const prompt = usePrompt();
  const { t } = useTranslation();
  const isStoreOption = isOptionEnabledInStore(option);
  const { mutateAsync } = useDeleteShippingOption(option.id);
  const handleDelete = async () => {
    const res = await prompt({
      title: t("general.areYouSure"),
      description: t("stockLocations.shippingOptions.delete.confirmation", {
        name: option.name
      }),
      verificationInstruction: t("general.typeToConfirm"),
      verificationText: option.name,
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast.success(
          t("stockLocations.shippingOptions.delete.successToast", {
            name: option.name
          })
        );
      },
      onError: (e) => {
        toast.error(e.message);
      }
    });
  };
  return /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-3 py-2", "data-testid": `location-shipping-option-${option.id}`, children: [
    /* @__PURE__ */ jsx("div", { className: "flex-1", "data-testid": `location-shipping-option-name-${option.id}`, children: /* @__PURE__ */ jsxs(Text, { size: "small", weight: "plus", children: [
      option.name,
      " - ",
      option.shipping_profile.name,
      " (",
      formatProvider(option.provider_id),
      ")"
    ] }) }),
    /* @__PURE__ */ jsx(
      Badge,
      {
        className: "mr-4",
        color: isStoreOption ? "grey" : "purple",
        size: "2xsmall",
        rounded: "full",
        "data-testid": `location-shipping-option-badge-${option.id}`,
        children: isStoreOption ? t("general.store") : t("general.admin")
      }
    ),
    /* @__PURE__ */ jsx(
      ActionMenu,
      {
        groups: [
          {
            actions: [
              {
                icon: /* @__PURE__ */ jsx(PencilSquare, {}),
                label: t("stockLocations.shippingOptions.edit.action"),
                to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${option.service_zone_id}/shipping-option/${option.id}/edit`
              },
              {
                label: t("stockLocations.shippingOptions.pricing.action"),
                icon: /* @__PURE__ */ jsx(CurrencyDollar, {}),
                disabled: option.price_type === "calculated" /* Calculated */,
                to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${option.service_zone_id}/shipping-option/${option.id}/pricing`
              }
            ]
          },
          {
            actions: [
              {
                label: t("actions.delete"),
                icon: /* @__PURE__ */ jsx(Trash, {}),
                onClick: handleDelete
              }
            ]
          }
        ],
        "data-testid": `location-shipping-option-action-menu-${option.id}`
      }
    )
  ] });
}
function ServiceZoneOptions({
  zone,
  locationId,
  fulfillmentSetId,
  type
}) {
  const { t } = useTranslation();
  const shippingOptions = zone.shipping_options.filter(
    (o) => !isReturnOption(o)
  );
  const returnOptions = zone.shipping_options.filter((o) => isReturnOption(o));
  return /* @__PURE__ */ jsxs("div", { "data-testid": `location-service-zone-options-${zone.id}`, children: [
    /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4 px-6 py-4", "data-testid": `location-service-zone-shipping-options-${zone.id}`, children: [
      /* @__PURE__ */ jsxs("div", { className: "item-center flex justify-between", "data-testid": `location-service-zone-shipping-options-header-${zone.id}`, children: [
        /* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle txt-small self-center font-medium", "data-testid": `location-service-zone-shipping-options-label-${zone.id}`, children: t(`stockLocations.shippingOptions.create.${type}.label`) }),
        /* @__PURE__ */ jsx(
          LinkButton,
          {
            to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${zone.id}/shipping-option/create`,
            "data-testid": `location-service-zone-shipping-options-create-button-${zone.id}`,
            children: t("stockLocations.shippingOptions.create.action")
          }
        )
      ] }),
      !!shippingOptions.length && /* @__PURE__ */ jsx("div", { className: "shadow-elevation-card-rest bg-ui-bg-subtle grid divide-y rounded-md", "data-testid": `location-service-zone-shipping-options-list-${zone.id}`, children: shippingOptions.map((o) => /* @__PURE__ */ jsx(
        ShippingOption,
        {
          option: o,
          locationId,
          fulfillmentSetId
        },
        o.id
      )) })
    ] }),
    /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
    /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4 px-6 py-4", "data-testid": `location-service-zone-return-options-${zone.id}`, children: [
      /* @__PURE__ */ jsxs("div", { className: "item-center flex justify-between", "data-testid": `location-service-zone-return-options-header-${zone.id}`, children: [
        /* @__PURE__ */ jsx("span", { className: "text-ui-fg-subtle txt-small self-center font-medium", "data-testid": `location-service-zone-return-options-label-${zone.id}`, children: t("stockLocations.shippingOptions.create.returns.label") }),
        /* @__PURE__ */ jsx(
          LinkButton,
          {
            to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${zone.id}/shipping-option/create?is_return`,
            "data-testid": `location-service-zone-return-options-create-button-${zone.id}`,
            children: t("stockLocations.shippingOptions.create.action")
          }
        )
      ] }),
      !!returnOptions.length && /* @__PURE__ */ jsx("div", { className: "shadow-elevation-card-rest bg-ui-bg-subtle grid divide-y rounded-md", "data-testid": `location-service-zone-return-options-list-${zone.id}`, children: returnOptions.map((o) => /* @__PURE__ */ jsx(
        ShippingOption,
        {
          option: o,
          locationId,
          fulfillmentSetId
        },
        o.id
      )) })
    ] })
  ] });
}
function ServiceZone({
  zone,
  locationId,
  fulfillmentSetId,
  type
}) {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const [open, setOpen] = useState(true);
  const { mutateAsync: deleteZone } = useDeleteFulfillmentServiceZone(
    fulfillmentSetId,
    zone.id
  );
  const handleDelete = async () => {
    const res = await prompt({
      title: t("general.areYouSure"),
      description: t("stockLocations.serviceZones.delete.confirmation", {
        name: zone.name
      }),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await deleteZone(void 0, {
      onError: (e) => {
        toast.error(e.message);
      },
      onSuccess: () => {
        toast.success(
          t("stockLocations.serviceZones.delete.successToast", {
            name: zone.name
          })
        );
      }
    });
  };
  const countries2 = useMemo(() => {
    const countryGeoZones = zone.geo_zones.filter((g) => g.type === "country");
    const countries3 = countryGeoZones.map(
      ({ country_code }) => countries.find((c) => c.iso_2 === country_code)
    ).filter((c) => !!c);
    if (process.env.NODE_ENV === "development" && countryGeoZones.length !== countries3.length) {
      console.warn(
        "Some countries are missing in the static countries list",
        countryGeoZones.filter((g) => !countries3.find((c) => c.iso_2 === g.country_code)).map((g) => g.country_code)
      );
    }
    return countries3.sort((c1, c2) => c1.name.localeCompare(c2.name));
  }, [zone.geo_zones]);
  const [shippingOptionsCount, returnOptionsCount] = useMemo(() => {
    const options = zone.shipping_options;
    const optionsCount = options.filter((o) => !isReturnOption(o)).length;
    const returnOptionsCount2 = options.filter(isReturnOption).length;
    return [optionsCount, returnOptionsCount2];
  }, [zone.shipping_options]);
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col", "data-testid": `location-service-zone-${zone.id}`, children: [
    /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center justify-between gap-x-4 px-6 py-4", "data-testid": `location-service-zone-header-${zone.id}`, children: [
      /* @__PURE__ */ jsx(IconAvatar, { "data-testid": `location-service-zone-icon-${zone.id}`, children: /* @__PURE__ */ jsx(Map, {}) }),
      /* @__PURE__ */ jsxs("div", { className: "grow-1 flex flex-1 flex-col", "data-testid": `location-service-zone-info-${zone.id}`, children: [
        /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", "data-testid": `location-service-zone-name-${zone.id}`, children: zone.name }),
        /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", "data-testid": `location-service-zone-details-${zone.id}`, children: [
          /* @__PURE__ */ jsx(
            ListSummary,
            {
              variant: "base",
              list: countries2.map((c) => c.display_name),
              inline: true,
              n: 1,
              "data-testid": `location-service-zone-countries-${zone.id}`
            }
          ),
          /* @__PURE__ */ jsx("span", { children: "\xB7" }),
          /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle txt-small", "data-testid": `location-service-zone-shipping-count-${zone.id}`, children: t(`stockLocations.shippingOptions.fields.count.${type}`, {
            count: shippingOptionsCount
          }) }),
          /* @__PURE__ */ jsx("span", { children: "\xB7" }),
          /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle txt-small", "data-testid": `location-service-zone-return-count-${zone.id}`, children: t("stockLocations.shippingOptions.fields.count.returns", {
            count: returnOptionsCount
          }) })
        ] })
      ] }),
      /* @__PURE__ */ jsxs("div", { className: "flex grow-0 items-center gap-4", "data-testid": `location-service-zone-actions-${zone.id}`, children: [
        /* @__PURE__ */ jsx(
          IconButton,
          {
            size: "small",
            onClick: () => setOpen((s) => !s),
            variant: "transparent",
            "data-testid": `location-service-zone-toggle-button-${zone.id}`,
            children: /* @__PURE__ */ jsx(
              TriangleDownMini,
              {
                style: {
                  transform: `rotate(${!open ? 0 : 180}deg)`,
                  transition: ".2s transform ease-in-out"
                }
              }
            )
          }
        ),
        /* @__PURE__ */ jsx(
          ActionMenu,
          {
            groups: [
              {
                actions: [
                  {
                    label: t("actions.edit"),
                    icon: /* @__PURE__ */ jsx(PencilSquare, {}),
                    to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${zone.id}/edit`
                  },
                  {
                    label: t("stockLocations.serviceZones.manageAreas.action"),
                    icon: /* @__PURE__ */ jsx(Map, {}),
                    to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSetId}/service-zone/${zone.id}/areas`
                  }
                ]
              },
              {
                actions: [
                  {
                    label: t("actions.delete"),
                    icon: /* @__PURE__ */ jsx(Trash, {}),
                    onClick: handleDelete
                  }
                ]
              }
            ],
            "data-testid": `location-service-zone-action-menu-${zone.id}`
          }
        )
      ] })
    ] }),
    open && /* @__PURE__ */ jsx(
      ServiceZoneOptions,
      {
        fulfillmentSetId,
        locationId,
        type,
        zone
      }
    )
  ] });
}
function FulfillmentSet(props) {
  const { t } = useTranslation();
  const prompt = usePrompt();
  const { fulfillmentSet, locationName, locationId, type } = props;
  const fulfillmentSetExists = !!fulfillmentSet;
  const hasServiceZones = !!fulfillmentSet?.service_zones.length;
  const { mutateAsync: createFulfillmentSet } = useCreateStockLocationFulfillmentSet(locationId);
  const { mutateAsync: deleteFulfillmentSet } = useDeleteFulfillmentSet(
    fulfillmentSet?.id ?? ""
  );
  const handleCreate = async () => {
    await createFulfillmentSet(
      {
        name: `${locationName} ${type === "pickup" /* Pickup */ ? "pick up" : type}`,
        type
      },
      {
        onSuccess: () => {
          toast.success(t(`stockLocations.fulfillmentSets.enable.${type}`));
        },
        onError: (e) => {
          toast.error(e.message);
        }
      }
    );
  };
  const handleDelete = async () => {
    const res = await prompt({
      title: t("general.areYouSure"),
      description: t(`stockLocations.fulfillmentSets.disable.confirmation`, {
        name: fulfillmentSet?.name
      }),
      confirmText: t("actions.disable"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await deleteFulfillmentSet(void 0, {
      onSuccess: () => {
        toast.success(t(`stockLocations.fulfillmentSets.disable.${type}`));
      },
      onError: (e) => {
        toast.error(e.message);
      }
    });
  };
  const groups = fulfillmentSet ? [
    {
      actions: [
        {
          icon: /* @__PURE__ */ jsx(Plus, {}),
          label: t("stockLocations.serviceZones.create.action"),
          to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSet.id}/service-zones/create`
        }
      ]
    },
    {
      actions: [
        {
          icon: /* @__PURE__ */ jsx(Trash, {}),
          label: t("actions.disable"),
          onClick: handleDelete
        }
      ]
    }
  ] : [
    {
      actions: [
        {
          icon: /* @__PURE__ */ jsx(Plus, {}),
          label: t("actions.enable"),
          onClick: handleCreate
        }
      ]
    }
  ];
  return /* @__PURE__ */ jsx(Container, { className: "p-0", "data-testid": `location-fulfillment-set-${type}`, children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col divide-y", children: [
    /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", "data-testid": `location-fulfillment-set-header-${type}`, children: [
      /* @__PURE__ */ jsx(Heading, { level: "h2", "data-testid": `location-fulfillment-set-heading-${type}`, children: t(`stockLocations.fulfillmentSets.${type}.header`) }),
      /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", "data-testid": `location-fulfillment-set-actions-${type}`, children: [
        /* @__PURE__ */ jsx(StatusBadge, { color: fulfillmentSetExists ? "green" : "grey", "data-testid": `location-fulfillment-set-status-badge-${type}`, children: t(
          fulfillmentSetExists ? "statuses.enabled" : "statuses.disabled"
        ) }),
        /* @__PURE__ */ jsx(ActionMenu, { groups, "data-testid": `location-fulfillment-set-action-menu-${type}` })
      ] })
    ] }),
    fulfillmentSetExists && !hasServiceZones && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-8 pt-6", "data-testid": `location-fulfillment-set-empty-${type}`, children: /* @__PURE__ */ jsx(
      NoRecords,
      {
        message: t("stockLocations.serviceZones.fields.noRecords"),
        className: "h-fit",
        action: {
          to: `/settings/locations/${locationId}/fulfillment-set/${fulfillmentSet.id}/service-zones/create`,
          label: t("stockLocations.serviceZones.create.action")
        }
      }
    ) }),
    hasServiceZones && /* @__PURE__ */ jsx("div", { className: "flex flex-col divide-y", "data-testid": `location-fulfillment-set-service-zones-${type}`, children: fulfillmentSet?.service_zones.map((zone) => /* @__PURE__ */ jsx(
      ServiceZone,
      {
        zone,
        type,
        locationId,
        fulfillmentSetId: fulfillmentSet.id
      },
      zone.id
    )) })
  ] }) });
}
var Actions = ({ location }) => {
  const navigate = useNavigate();
  const { t } = useTranslation();
  const { mutateAsync } = useDeleteStockLocation(location.id);
  const prompt = usePrompt();
  const handleDelete = async () => {
    const res = await prompt({
      title: t("general.areYouSure"),
      description: t("stockLocations.delete.confirmation", {
        name: location.name
      }),
      verificationText: location.name,
      verificationInstruction: t("general.typeToConfirm"),
      confirmText: t("actions.delete"),
      cancelText: t("actions.cancel")
    });
    if (!res) {
      return;
    }
    await mutateAsync(void 0, {
      onSuccess: () => {
        toast.success(
          t("stockLocations.create.successToast", {
            name: location.name
          })
        );
        navigate("/settings/locations", { replace: true });
      },
      onError: (e) => {
        toast.error(e.message);
      }
    });
  };
  return /* @__PURE__ */ jsx(
    ActionMenu,
    {
      groups: [
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(PencilSquare, {}),
              label: t("actions.edit"),
              to: `edit`
            },
            {
              icon: /* @__PURE__ */ jsx(ArchiveBox, {}),
              label: t("stockLocations.edit.viewInventory"),
              to: `/inventory?location_id=${location.id}`
            }
          ]
        },
        {
          actions: [
            {
              icon: /* @__PURE__ */ jsx(Trash, {}),
              label: t("actions.delete"),
              onClick: handleDelete
            }
          ]
        }
      ],
      "data-testid": "location-general-section-action-menu"
    }
  );
};

// src/pages/locations/location-detail/components/location-sales-channels-section/locations-sales-channels-section.tsx
import { Channels, PencilSquare as PencilSquare2 } from "@medusajs/icons";
import { Container as Container2, Heading as Heading2, Text as Text2 } from "@medusajs/ui";
import { useTranslation as useTranslation2 } from "react-i18next";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
function LocationsSalesChannelsSection({
  location
}) {
  const { t } = useTranslation2();
  const { count } = useSalesChannels({ limit: 1, fields: "id" });
  const hasConnectedChannels = !!location.sales_channels?.length;
  return /* @__PURE__ */ jsxs2(Container2, { className: "flex flex-col px-6 py-4", "data-testid": "location-sales-channels-section-container", children: [
    /* @__PURE__ */ jsxs2("div", { className: "flex items-center justify-between", "data-testid": "location-sales-channels-section-header", children: [
      /* @__PURE__ */ jsx2(Heading2, { level: "h2", "data-testid": "location-sales-channels-section-heading", children: t("stockLocations.salesChannels.header") }),
      /* @__PURE__ */ jsx2(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  label: t("actions.edit"),
                  to: "sales-channels",
                  icon: /* @__PURE__ */ jsx2(PencilSquare2, {})
                }
              ]
            }
          ],
          "data-testid": "location-sales-channels-section-action-menu"
        }
      )
    ] }),
    hasConnectedChannels ? /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-y-4 pt-4", "data-testid": "location-sales-channels-section-content", children: [
      /* @__PURE__ */ jsxs2("div", { className: "grid grid-cols-[28px_1fr] items-center gap-x-3", "data-testid": "location-sales-channels-section-list", children: [
        /* @__PURE__ */ jsx2(IconAvatar, { "data-testid": "location-sales-channels-section-icon", children: /* @__PURE__ */ jsx2(Channels, { className: "text-ui-fg-subtle" }) }),
        /* @__PURE__ */ jsx2(
          ListSummary,
          {
            n: 3,
            className: "text-ui-fg-base",
            inline: true,
            list: location.sales_channels?.map((sc) => sc.name) ?? [],
            "data-testid": "location-sales-channels-section-summary"
          }
        )
      ] }),
      /* @__PURE__ */ jsx2(Text2, { className: "text-ui-fg-subtle", size: "small", leading: "compact", "data-testid": "location-sales-channels-section-description", children: t("stockLocations.salesChannels.connectedTo", {
        count: location.sales_channels?.length,
        total: count
      }) })
    ] }) : /* @__PURE__ */ jsx2(
      NoRecords,
      {
        className: "h-fit pb-2 pt-6",
        action: {
          label: t("stockLocations.salesChannels.action"),
          to: "sales-channels"
        },
        message: t("stockLocations.salesChannels.noChannels"),
        "data-testid": "location-sales-channels-section-no-records"
      }
    )
  ] });
}
var locations_sales_channels_section_default = LocationsSalesChannelsSection;

// src/pages/locations/location-detail/components/location-fulfillment-providers-section/location-fulfillment-providers-section.tsx
import { HandTruck, PencilSquare as PencilSquare3 } from "@medusajs/icons";
import { Container as Container3, Heading as Heading3 } from "@medusajs/ui";
import { Fragment as Fragment2 } from "react";
import { useTranslation as useTranslation3 } from "react-i18next";
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
function LocationsFulfillmentProvidersSection({
  location
}) {
  const { t } = useTranslation3();
  const { fulfillment_providers } = useFulfillmentProviders({
    stock_location_id: location.id,
    fields: "id",
    is_enabled: true
  });
  return /* @__PURE__ */ jsxs3(Container3, { className: "flex flex-col px-6 py-4", "data-testid": "location-fulfillment-providers-section-container", children: [
    /* @__PURE__ */ jsxs3("div", { className: "flex items-center justify-between", "data-testid": "location-fulfillment-providers-section-header", children: [
      /* @__PURE__ */ jsx3(Heading3, { level: "h2", "data-testid": "location-fulfillment-providers-section-heading", children: t("stockLocations.fulfillmentProviders.header") }),
      /* @__PURE__ */ jsx3(
        ActionMenu,
        {
          groups: [
            {
              actions: [
                {
                  label: t("actions.edit"),
                  to: "fulfillment-providers",
                  icon: /* @__PURE__ */ jsx3(PencilSquare3, {})
                }
              ]
            }
          ],
          "data-testid": "location-fulfillment-providers-section-action-menu"
        }
      )
    ] }),
    fulfillment_providers?.length ? /* @__PURE__ */ jsx3("div", { className: "flex flex-col gap-y-4 pt-4", "data-testid": "location-fulfillment-providers-section-content", children: /* @__PURE__ */ jsx3("div", { className: "grid grid-cols-[28px_1fr] items-center gap-x-3 gap-y-3", "data-testid": "location-fulfillment-providers-section-list", children: fulfillment_providers?.map((fulfillmentProvider) => {
      return /* @__PURE__ */ jsxs3(Fragment2, { children: [
        /* @__PURE__ */ jsx3(IconAvatar, { "data-testid": `location-fulfillment-providers-section-provider-icon-${fulfillmentProvider.id}`, children: /* @__PURE__ */ jsx3(HandTruck, { className: "text-ui-fg-subtle" }) }),
        /* @__PURE__ */ jsx3("div", { className: "txt-compact-small", "data-testid": `location-fulfillment-providers-section-provider-name-${fulfillmentProvider.id}`, children: formatProvider(fulfillmentProvider.id) })
      ] }, fulfillmentProvider.id);
    }) }) }) : /* @__PURE__ */ jsx3(
      NoRecords,
      {
        className: "h-fit pb-2 pt-6 text-center",
        action: {
          label: t("stockLocations.fulfillmentProviders.action"),
          to: "fulfillment-providers"
        },
        message: t("stockLocations.fulfillmentProviders.noProviders"),
        "data-testid": "location-fulfillment-providers-section-no-records"
      }
    )
  ] });
}
var location_fulfillment_providers_section_default = LocationsFulfillmentProvidersSection;

// src/pages/locations/location-detail/constants.ts
var LOCATION_DETAILS_FIELD = "name,*sales_channels,*address,fulfillment_sets.type,fulfillment_sets.name,*fulfillment_sets.service_zones.geo_zones,*fulfillment_sets.service_zones,*fulfillment_sets.service_zones.shipping_options,*fulfillment_sets.service_zones.shipping_options.rules,*fulfillment_sets.service_zones.shipping_options.shipping_profile,*fulfillment_providers";

// src/pages/locations/location-detail/location-detail.tsx
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
var Root = ({ children }) => {
  const initialData = useLoaderData();
  const { location_id } = useParams();
  const {
    stock_location: location,
    isPending: isLoading,
    isError,
    error
  } = useStockLocation(
    location_id,
    { fields: LOCATION_DETAILS_FIELD },
    { initialData }
  );
  if (isLoading || !location) {
    return /* @__PURE__ */ jsx4(TwoColumnPageSkeleton, { mainSections: 3, sidebarSections: 2, showJSON: true });
  }
  if (isError) {
    throw error;
  }
  return Children.count(children) > 0 ? /* @__PURE__ */ jsx4(
    TwoColumnPage,
    {
      data: location,
      showJSON: true,
      hasOutlet: true,
      "data-testid": "location-detail-page",
      children
    }
  ) : /* @__PURE__ */ jsxs4(
    TwoColumnPage,
    {
      data: location,
      showJSON: true,
      hasOutlet: true,
      "data-testid": "location-detail-page",
      children: [
        /* @__PURE__ */ jsx4(TwoColumnPage.Main, { "data-testid": "location-detail-main", children: /* @__PURE__ */ jsx4(LocationGeneralSection, { location }) }),
        /* @__PURE__ */ jsxs4(TwoColumnPage.Sidebar, { "data-testid": "location-detail-sidebar", children: [
          /* @__PURE__ */ jsx4(locations_sales_channels_section_default, { location }),
          /* @__PURE__ */ jsx4(location_fulfillment_providers_section_default, { location })
        ] })
      ]
    }
  );
};
var LocationDetailPage = Object.assign(Root, {
  Main: TwoColumnPage.Main,
  Sidebar: TwoColumnPage.Sidebar,
  MainGeneralSection: LocationGeneralSection,
  SidebarSalesChannelsSection: locations_sales_channels_section_default,
  SidebarFulfillmentProvidersSection: location_fulfillment_providers_section_default
});

export {
  LOCATION_DETAILS_FIELD,
  LocationDetailPage
};
