import {
  ConditionalPriceForm,
  ConditionalPriceSchema,
  ShippingOptionPriceProvider,
  buildShippingOptionPriceRules,
  useShippingOptionPriceColumns
} from "./chunk-CEG375CR.js";
import {
  CONDITIONAL_PRICES_STACKED_MODAL_ID,
  ShippingOptionPriceType
} from "./chunk-LXSBG6LK.js";
import {
  formatProvider
} from "./chunk-VW56KWO2.js";
import {
  DataGrid
} from "./chunk-MWX5JCOM.js";
import {
  useComboboxData
} from "./chunk-AEFDAU3Y.js";
import {
  Combobox
} from "./chunk-AW77UWCZ.js";
import {
  castNumber
} from "./chunk-SMQT3ZNO.js";
import {
  TabbedForm,
  defineTabMeta,
  useTabbedForm
} from "./chunk-4LXBQTFN.js";
import {
  SwitchBox
} from "./chunk-2EME4AWX.js";
import {
  useDocumentDirection
} from "./chunk-Y7QKP6QU.js";
import {
  RouteFocusModal,
  StackedFocusModal,
  useRouteModal,
  useStackedModal
} from "./chunk-FWJLS7XD.js";
import {
  Form
} from "./chunk-3QSRE5LS.js";
import {
  useCreateShippingOptions
} from "./chunk-5TRY5IMZ.js";
import {
  useFulfillmentProviderOptions,
  useStockLocation
} from "./chunk-EPHVGD5Z.js";
import {
  useRegions
} from "./chunk-ESPLVOFC.js";
import {
  useStore
} from "./chunk-FXWKGNRV.js";
import {
  usePricePreferences
} from "./chunk-VDKOJ5WD.js";
import {
  sdk
} from "./chunk-ZBWL72TB.js";

// src/pages/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/schema.ts
import { z } from "zod";
var CreateShippingOptionDetailsSchema = z.object({
  name: z.string().min(1),
  price_type: z.nativeEnum(ShippingOptionPriceType),
  enabled_in_store: z.boolean(),
  shipping_profile_id: z.string().min(1),
  provider_id: z.string().min(1),
  fulfillment_option_id: z.string().min(1),
  shipping_option_type_id: z.string().min(1)
});
var ShippingOptionConditionalPriceSchema = z.object({
  conditional_region_prices: z.record(
    z.string(),
    z.array(ConditionalPriceSchema).optional()
  ),
  conditional_currency_prices: z.record(
    z.string(),
    z.array(ConditionalPriceSchema).optional()
  )
});
var CreateShippingOptionSchema = z.object({
  region_prices: z.record(z.string(), z.string().optional()),
  currency_prices: z.record(z.string(), z.string().optional())
}).merge(CreateShippingOptionDetailsSchema).merge(ShippingOptionConditionalPriceSchema);

// src/pages/locations/location-service-zone-shipping-option-create/location-service-zone-shipping-option-create.tsx
import { Children as Children2 } from "react";
import { useParams, useSearchParams } from "react-router-dom";

// src/pages/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx
import { zodResolver } from "@hookform/resolvers/zod";
import { toast } from "@medusajs/ui";
import { Children, useCallback, useMemo as useMemo2 } from "react";
import { useForm, useWatch as useWatch2 } from "react-hook-form";
import { useTranslation as useTranslation2 } from "react-i18next";

// src/pages/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-option-details-form.tsx
import { Divider, Heading, Input, RadioGroup, Select, Text } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
import { createElement } from "react";
var Root = ({
  isReturn = false,
  zone,
  locationId,
  fulfillmentProviderOptions,
  selectedProviderId,
  type
}) => {
  const { t } = useTranslation();
  const form = useTabbedForm();
  const direction = useDocumentDirection();
  const isPickup = type === "pickup" /* Pickup */;
  const shippingProfiles = useComboboxData({
    queryFn: (params) => sdk.admin.shippingProfiles.query(params),
    queryKey: ["shipping_profiles"],
    getOptions: (data) => data.shipping_profiles.map((profile) => ({
      label: profile.name,
      value: profile.id
    }))
  });
  const shippingOptionTypes = useComboboxData({
    queryFn: (params) => sdk.admin.shippingOptionTypes.query(params),
    queryKey: ["shipping_option_types"],
    getOptions: (data) => data.shipping_option_types.map((type2) => ({
      label: type2.label,
      value: type2.id
    }))
  });
  const fulfillmentProviders = useComboboxData({
    queryFn: (params) => sdk.admin.fulfillmentProviders.query({
      ...params,
      stock_location_id: locationId
    }),
    queryKey: ["fulfillment_providers"],
    getOptions: (data) => data.fulfillment_providers.map((provider) => ({
      label: formatProvider(provider.id),
      value: provider.id
    }))
  });
  return /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", "data-testid": "location-shipping-option-create-details-form", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8 px-6 py-16", children: [
    /* @__PURE__ */ jsxs("div", { "data-testid": "location-shipping-option-create-details-form-header-section", children: [
      /* @__PURE__ */ jsx(Heading, { "data-testid": "location-shipping-option-create-details-form-heading", children: t(
        `stockLocations.shippingOptions.create.${isPickup ? "pickup" : isReturn ? "returns" : "shipping"}.header`,
        { zone: zone.name }
      ) }),
      /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", "data-testid": "location-shipping-option-create-details-form-hint", children: t(
        `stockLocations.shippingOptions.create.${isReturn ? "returns" : isPickup ? "pickup" : "shipping"}.hint`
      ) })
    ] }),
    !isPickup && /* @__PURE__ */ jsx(
      Form.Field,
      {
        control: form.control,
        name: "price_type",
        render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-price-type-item", children: [
          /* @__PURE__ */ jsx(Form.Label, { "data-testid": "location-shipping-option-create-details-form-price-type-label", children: t("stockLocations.shippingOptions.fields.priceType.label") }),
          /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-price-type-control", children: /* @__PURE__ */ jsxs(
            RadioGroup,
            {
              dir: direction,
              className: "grid grid-cols-1 gap-4 md:grid-cols-2",
              ...field,
              onValueChange: field.onChange,
              "data-testid": "location-shipping-option-create-details-form-price-type-radio-group",
              children: [
                /* @__PURE__ */ jsx(
                  RadioGroup.ChoiceBox,
                  {
                    className: "flex-1",
                    value: "flat" /* FlatRate */,
                    label: t("stockLocations.shippingOptions.fields.priceType.options.fixed.label"),
                    description: t("stockLocations.shippingOptions.fields.priceType.options.fixed.hint"),
                    "data-testid": "location-shipping-option-create-details-form-price-type-flat-rate"
                  }
                ),
                /* @__PURE__ */ jsx(
                  RadioGroup.ChoiceBox,
                  {
                    className: "flex-1",
                    value: "calculated" /* Calculated */,
                    label: t("stockLocations.shippingOptions.fields.priceType.options.calculated.label"),
                    description: t("stockLocations.shippingOptions.fields.priceType.options.calculated.hint"),
                    "data-testid": "location-shipping-option-create-details-form-price-type-calculated"
                  }
                )
              ]
            }
          ) }),
          /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-price-type-error" })
        ] })
      }
    ),
    /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "name",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-name-item", children: [
            /* @__PURE__ */ jsx(Form.Label, { "data-testid": "location-shipping-option-create-details-form-name-label", children: t("fields.name") }),
            /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-name-control", children: /* @__PURE__ */ jsx(Input, { ...field, "data-testid": "location-shipping-option-create-details-form-name-input" }) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-name-error" })
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "shipping_profile_id",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-shipping-profile-item", children: [
            /* @__PURE__ */ jsx(Form.Label, { "data-testid": "location-shipping-option-create-details-form-shipping-profile-label", children: t("stockLocations.shippingOptions.fields.profile") }),
            /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-shipping-profile-control", children: /* @__PURE__ */ jsx(
              Combobox,
              {
                ...field,
                options: shippingProfiles.options,
                searchValue: shippingProfiles.searchValue,
                onSearchValueChange: shippingProfiles.onSearchValueChange,
                disabled: shippingProfiles.disabled,
                "data-testid": "location-shipping-option-create-details-form-shipping-profile-combobox"
              }
            ) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-shipping-profile-error" })
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "shipping_option_type_id",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-shipping-option-type-item", children: [
            /* @__PURE__ */ jsx(Form.Label, { "data-testid": "location-shipping-option-create-details-form-shipping-option-type-label", children: t("stockLocations.shippingOptions.fields.type") }),
            /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-shipping-option-type-control", children: /* @__PURE__ */ jsx(
              Combobox,
              {
                ...field,
                options: shippingOptionTypes.options,
                searchValue: shippingOptionTypes.searchValue,
                onSearchValueChange: shippingOptionTypes.onSearchValueChange,
                disabled: shippingOptionTypes.disabled,
                "data-testid": "location-shipping-option-create-details-form-shipping-option-type-combobox"
              }
            ) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-shipping-option-type-error" })
          ] })
        }
      )
    ] }),
    /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "provider_id",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-provider-item", children: [
            /* @__PURE__ */ jsx(
              Form.Label,
              {
                tooltip: t("stockLocations.fulfillmentProviders.shippingOptionsTooltip"),
                "data-testid": "location-shipping-option-create-details-form-provider-label",
                children: t("stockLocations.shippingOptions.fields.provider")
              }
            ),
            /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-provider-control", children: /* @__PURE__ */ jsx(
              Combobox,
              {
                ...field,
                onChange: (e) => {
                  field.onChange(e);
                  form.setValue("fulfillment_option_id", "");
                },
                options: fulfillmentProviders.options,
                searchValue: fulfillmentProviders.searchValue,
                onSearchValueChange: fulfillmentProviders.onSearchValueChange,
                disabled: fulfillmentProviders.disabled,
                "data-testid": "location-shipping-option-create-details-form-provider-combobox"
              }
            ) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-provider-error" })
          ] })
        }
      ),
      /* @__PURE__ */ jsx(
        Form.Field,
        {
          control: form.control,
          name: "fulfillment_option_id",
          render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { "data-testid": "location-shipping-option-create-details-form-fulfillment-option-item", children: [
            /* @__PURE__ */ jsx(Form.Label, { "data-testid": "location-shipping-option-create-details-form-fulfillment-option-label", children: t("stockLocations.shippingOptions.fields.fulfillmentOption") }),
            /* @__PURE__ */ jsx(Form.Control, { "data-testid": "location-shipping-option-create-details-form-fulfillment-option-control", children: /* @__PURE__ */ createElement(
              Select,
              {
                dir: direction,
                ...field,
                onValueChange: field.onChange,
                disabled: !selectedProviderId,
                key: selectedProviderId,
                "data-testid": "location-shipping-option-create-details-form-fulfillment-option-select"
              },
              /* @__PURE__ */ jsx(Select.Trigger, { ref: field.ref, "data-testid": "location-shipping-option-create-details-form-fulfillment-option-trigger", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
              /* @__PURE__ */ jsx(Select.Content, { "data-testid": "location-shipping-option-create-details-form-fulfillment-option-content", children: fulfillmentProviderOptions?.filter((fo) => !!fo.is_return === isReturn).map((option) => /* @__PURE__ */ jsx(Select.Item, { value: option.id, "data-testid": `location-shipping-option-create-details-form-fulfillment-option-option-${option.id}`, children: option.name || option.id }, option.id)) })
            ) }),
            /* @__PURE__ */ jsx(Form.ErrorMessage, { "data-testid": "location-shipping-option-create-details-form-fulfillment-option-error" })
          ] })
        }
      )
    ] }),
    /* @__PURE__ */ jsx(Divider, {}),
    /* @__PURE__ */ jsx(
      SwitchBox,
      {
        control: form.control,
        name: "enabled_in_store",
        label: t("stockLocations.shippingOptions.fields.enableInStore.label"),
        description: t("stockLocations.shippingOptions.fields.enableInStore.hint"),
        "data-testid": "location-shipping-option-create-details-form-enabled-in-store"
      }
    )
  ] }) });
};
Root._tabMeta = defineTabMeta({
  id: "details",
  labelKey: "stockLocations.shippingOptions.create.tabs.details",
  validationFields: [
    "name",
    "price_type",
    "enabled_in_store",
    "shipping_profile_id",
    "provider_id",
    "fulfillment_option_id",
    "shipping_option_type_id"
  ]
});
var CreateShippingOptionDetailsForm = Root;

// src/pages/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-prices-form.tsx
import { useEffect, useMemo, useState } from "react";
import { useWatch } from "react-hook-form";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
var Root2 = ({ type }) => {
  const isPickup = type === "pickup" /* Pickup */;
  const form = useTabbedForm();
  const { getIsOpen, setIsOpen } = useStackedModal();
  const [selectedPrice, setSelectedPrice] = useState(null);
  const onOpenConditionalPricesModal = (info) => {
    setIsOpen(CONDITIONAL_PRICES_STACKED_MODAL_ID, true);
    setSelectedPrice(info);
  };
  const onCloseConditionalPricesModal = () => {
    setIsOpen(CONDITIONAL_PRICES_STACKED_MODAL_ID, false);
    setSelectedPrice(null);
  };
  const {
    store,
    isLoading: isStoreLoading,
    isError: isStoreError,
    error: storeError
  } = useStore();
  const currencies = useMemo(
    () => store?.supported_currencies?.map((c) => c.currency_code) || [],
    [store]
  );
  const {
    regions,
    isLoading: isRegionsLoading,
    isError: isRegionsError,
    error: regionsError
  } = useRegions({
    fields: "id,name,currency_code",
    limit: 999
  });
  const { price_preferences: pricePreferences } = usePricePreferences({});
  const { setCloseOnEscape } = useRouteModal();
  const name = useWatch({ control: form.control, name: "name" });
  const columns = useShippingOptionPriceColumns({
    name,
    currencies,
    regions,
    pricePreferences
  });
  const isLoading = isStoreLoading || !store || isRegionsLoading || !regions;
  const data = useMemo(
    () => [[...currencies || [], ...regions || []]],
    [currencies, regions]
  );
  useEffect(() => {
    if (!isLoading && isPickup) {
      if (currencies.length > 0) {
        currencies.forEach((currency) => {
          form.setValue(`currency_prices.${currency}`, "0");
        });
      }
      if (regions.length > 0) {
        regions.forEach((region) => {
          form.setValue(`region_prices.${region.id}`, "0");
        });
      }
    }
  }, [
    isLoading,
    isPickup,
    currencies.length,
    regions.length,
    currencies,
    form,
    regions
  ]);
  if (isStoreError) {
    throw storeError;
  }
  if (isRegionsError) {
    throw regionsError;
  }
  return /* @__PURE__ */ jsx2(
    StackedFocusModal,
    {
      id: CONDITIONAL_PRICES_STACKED_MODAL_ID,
      onOpenChangeCallback: (open) => {
        if (!open) {
          setSelectedPrice(null);
        }
      },
      "data-testid": "location-shipping-option-create-prices-form",
      children: /* @__PURE__ */ jsx2(
        ShippingOptionPriceProvider,
        {
          onOpenConditionalPricesModal,
          onCloseConditionalPricesModal,
          children: /* @__PURE__ */ jsxs2("div", { className: "flex size-full flex-col divide-y overflow-hidden", "data-testid": "location-shipping-option-create-prices-form-container", children: [
            /* @__PURE__ */ jsx2(
              DataGrid,
              {
                isLoading,
                data,
                columns,
                state: form,
                onEditingChange: (editing) => setCloseOnEscape(!editing),
                disableInteractions: getIsOpen(CONDITIONAL_PRICES_STACKED_MODAL_ID),
                "data-testid": "location-shipping-option-create-prices-form-data-grid"
              }
            ),
            selectedPrice && /* @__PURE__ */ jsx2(ConditionalPriceForm, { info: selectedPrice, variant: "create" })
          ] })
        }
      )
    }
  );
};
Root2._tabMeta = defineTabMeta({
  id: "pricing",
  labelKey: "stockLocations.shippingOptions.create.tabs.prices",
  validationFields: ["region_prices", "currency_prices", "conditional_region_prices", "conditional_currency_prices"]
});
var CreateShippingOptionsPricesForm = Root2;

// src/pages/locations/location-service-zone-shipping-option-create/components/create-shipping-options-form/create-shipping-options-form.tsx
import { jsx as jsx3 } from "react/jsx-runtime";
function CreateShippingOptionsForm({
  zone,
  isReturn,
  locationId,
  type,
  children,
  schema,
  defaultValues: extraDefaults
}) {
  const { t } = useTranslation2();
  const { handleSuccess } = useRouteModal();
  const form = useForm({
    defaultValues: {
      name: "",
      price_type: "flat" /* FlatRate */,
      enabled_in_store: true,
      shipping_profile_id: "",
      provider_id: "",
      fulfillment_option_id: "",
      region_prices: {},
      currency_prices: {},
      conditional_region_prices: {},
      conditional_currency_prices: {},
      ...extraDefaults
    },
    resolver: zodResolver(schema ?? CreateShippingOptionSchema)
  });
  const selectedProviderId = useWatch2({
    control: form.control,
    name: "provider_id"
  });
  const { fulfillment_options: fulfillmentProviderOptions } = useFulfillmentProviderOptions(selectedProviderId, {
    enabled: !!selectedProviderId
  });
  const watchedPriceType = useWatch2({
    control: form.control,
    name: "price_type"
  });
  const isCalculatedPriceType = watchedPriceType === "calculated" /* Calculated */;
  const { mutateAsync, isPending: isLoading } = useCreateShippingOptions();
  const handleSubmit = form.handleSubmit(async (data) => {
    const currencyPrices = Object.entries(data.currency_prices).map(([code, value]) => {
      if (!value) {
        return void 0;
      }
      return {
        currency_code: code,
        amount: castNumber(value)
      };
    }).filter((p) => !!p);
    const regionPrices = Object.entries(data.region_prices).map(([region_id, value]) => {
      if (!value) {
        return void 0;
      }
      return {
        region_id,
        amount: castNumber(value)
      };
    }).filter((p) => !!p);
    const conditionalRegionPrices = Object.entries(
      data.conditional_region_prices
    ).flatMap(([region_id, value]) => {
      const prices = value?.map((rule) => ({
        region_id,
        amount: castNumber(rule.amount),
        rules: buildShippingOptionPriceRules(rule)
      })) || [];
      return prices?.filter(Boolean);
    });
    const conditionalCurrencyPrices = Object.entries(
      data.conditional_currency_prices
    ).flatMap(([currency_code, value]) => {
      const prices = value?.map((rule) => ({
        currency_code,
        amount: castNumber(rule.amount),
        rules: buildShippingOptionPriceRules(rule)
      })) || [];
      return prices?.filter(Boolean);
    });
    const allPrices = [
      ...currencyPrices,
      ...conditionalCurrencyPrices,
      ...regionPrices,
      ...conditionalRegionPrices
    ];
    const fulfillmentOptionData = fulfillmentProviderOptions?.find(
      (fo) => fo.id === data.fulfillment_option_id
    );
    await mutateAsync(
      {
        name: data.name,
        price_type: data.price_type,
        service_zone_id: zone.id,
        shipping_profile_id: data.shipping_profile_id,
        provider_id: data.provider_id,
        prices: allPrices,
        data: fulfillmentOptionData,
        rules: [
          {
            value: isReturn ? "true" : "false",
            attribute: "is_return",
            operator: "eq"
          },
          {
            value: data.enabled_in_store ? "true" : "false",
            attribute: "enabled_in_store",
            operator: "eq"
          }
        ],
        type_id: data.shipping_option_type_id
      },
      {
        onSuccess: ({ shipping_option }) => {
          toast.success(
            t(
              `stockLocations.shippingOptions.create.${isReturn ? "returns" : "shipping"}.successToast`,
              { name: shipping_option.name }
            )
          );
          handleSuccess(`/settings/locations/${locationId}`);
        },
        onError: (e) => {
          toast.error(e.message);
        }
      }
    );
  });
  const transformTabs = useCallback(
    (tabs) => {
      return tabs.map((tab) => {
        if (tab.id === "pricing") {
          return {
            ...tab,
            isVisible: () => !isCalculatedPriceType
          };
        }
        return tab;
      });
    },
    [isCalculatedPriceType]
  );
  const defaultTabs = useMemo2(
    () => [
      /* @__PURE__ */ jsx3(
        CreateShippingOptionDetailsForm,
        {
          zone,
          isReturn,
          type,
          locationId,
          fulfillmentProviderOptions: fulfillmentProviderOptions || [],
          selectedProviderId
        },
        "details"
      ),
      /* @__PURE__ */ jsx3(CreateShippingOptionsPricesForm, { type }, "pricing")
    ],
    [zone, isReturn, type, locationId, fulfillmentProviderOptions, selectedProviderId]
  );
  const hasCustomChildren = Children.count(children) > 0;
  return /* @__PURE__ */ jsx3(
    TabbedForm,
    {
      form,
      onSubmit: handleSubmit,
      isLoading,
      transformTabs,
      children: hasCustomChildren ? children : defaultTabs
    }
  );
}

// src/pages/locations/location-service-zone-shipping-option-create/constants.ts
var LOC_CREATE_SHIPPING_OPTION_FIELDS = "*fulfillment_sets,*fulfillment_sets.service_zones,*fulfillment_sets.service_zones.shipping_options";

// src/pages/locations/location-service-zone-shipping-option-create/location-service-zone-shipping-option-create.tsx
import { jsx as jsx4 } from "react/jsx-runtime";
var Root3 = ({ children }) => {
  const { location_id, fset_id, zone_id } = useParams();
  const [searchParams] = useSearchParams();
  const isReturn = searchParams.has("is_return");
  const { stock_location, isPending, isFetching, isError, error } = useStockLocation(location_id, {
    fields: LOC_CREATE_SHIPPING_OPTION_FIELDS
  });
  const fulfillmentSet = stock_location?.fulfillment_sets?.find(
    (f) => f.id === fset_id
  );
  if (!isPending && !isFetching && !fulfillmentSet) {
    throw new Response(
      JSON.stringify({ message: `Fulfillment set with ID ${fset_id} was not found` }),
      { status: 404, headers: { "Content-Type": "application/json" } }
    );
  }
  const zone = fulfillmentSet?.service_zones?.find((z2) => z2.id === zone_id);
  if (!isPending && !isFetching && !zone) {
    throw new Response(
      JSON.stringify({ message: `Service zone with ID ${zone_id} was not found` }),
      { status: 404, headers: { "Content-Type": "application/json" } }
    );
  }
  if (isError) {
    throw error;
  }
  return /* @__PURE__ */ jsx4(RouteFocusModal, { prev: `/settings/locations/${location_id}`, "data-testid": "location-shipping-option-create-modal", children: zone && (Children2.count(children) > 0 ? children : /* @__PURE__ */ jsx4(
    CreateShippingOptionsForm,
    {
      zone,
      isReturn,
      locationId: location_id,
      type: fulfillmentSet.type
    }
  )) });
};
var ShippingOptionCreatePage = Object.assign(Root3, {
  Form: CreateShippingOptionsForm,
  DetailsTab: CreateShippingOptionDetailsForm,
  PricingTab: CreateShippingOptionsPricesForm,
  Tab: TabbedForm.Tab
});
var LocationServiceZoneShippingOptionCreate = Root3;

export {
  CreateShippingOptionSchema,
  ShippingOptionCreatePage,
  LocationServiceZoneShippingOptionCreate
};
