import {
  CreateCampaignSchema,
  DEFAULT_CAMPAIGN_VALUES
} from "./chunk-6MJMR6GU.mjs";
import "./chunk-F6ZOHZVB.mjs";
import {
  DeprecatedPercentageInput
} from "./chunk-KEQOAJC2.mjs";
import {
  AddCampaignPromotionFields
} from "./chunk-QIKZXRTL.mjs";
import "./chunk-DGF2UWBS.mjs";
import {
  RulesFormField
} from "./chunk-GIOHS6DI.mjs";
import "./chunk-3TZOFKX2.mjs";
import "./chunk-G6GMRNXC.mjs";
import {
  currencies,
  getCurrencySymbol
} from "./chunk-DK4WIVY6.mjs";
import "./chunk-IUCDCPJU.mjs";
import {
  KeyboundForm
} from "./chunk-6HTZNHPT.mjs";
import "./chunk-OV6YUU3D.mjs";
import {
  RouteFocusModal,
  useRouteModal
} from "./chunk-ULMMKZ3U.mjs";
import {
  useDocumentDirection
} from "./chunk-S4DMV3ZT.mjs";
import {
  Form
} from "./chunk-OBQI23QM.mjs";
import "./chunk-OW2UL5FI.mjs";
import "./chunk-5DUV4AET.mjs";
import "./chunk-FAB3VINY.mjs";
import "./chunk-Q7YBE4IP.mjs";
import "./chunk-HI6URQ7H.mjs";
import "./chunk-6CLQKVAU.mjs";
import "./chunk-KI7TOXBR.mjs";
import "./chunk-QBIQEVTU.mjs";
import "./chunk-WAXMT4IY.mjs";
import "./chunk-DYDGGABK.mjs";
import "./chunk-LGNTHZ5Y.mjs";
import "./chunk-CN7JXSGW.mjs";
import "./chunk-AO2USOOE.mjs";
import "./chunk-KWWLGCSY.mjs";
import "./chunk-5AFMB7XQ.mjs";
import "./chunk-5U6AZEO7.mjs";
import {
  useCreatePromotion
} from "./chunk-A63RZVX6.mjs";
import "./chunk-HBXV7ENS.mjs";
import "./chunk-ZBMENGLV.mjs";
import "./chunk-LGLPAUIO.mjs";
import "./chunk-CDORR33H.mjs";
import "./chunk-DE44HCDH.mjs";
import "./chunk-MUOBXNL6.mjs";
import "./chunk-BEQ5XTWH.mjs";
import "./chunk-HP2JH45P.mjs";
import "./chunk-VCSSQVPD.mjs";
import "./chunk-SQDIZZDW.mjs";
import "./chunk-LA2ILUXH.mjs";
import "./chunk-7AXHHXCX.mjs";
import "./chunk-FXYH54JP.mjs";
import "./chunk-774WSTCC.mjs";
import "./chunk-NFEK63OE.mjs";
import "./chunk-QZ7TP4HQ.mjs";

// src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx
import { zodResolver } from "@hookform/resolvers/zod";
import {
  Alert,
  Badge,
  Button,
  clx,
  CurrencyInput,
  Divider,
  Heading,
  Input,
  ProgressTabs,
  RadioGroup,
  Switch,
  Text,
  toast
} from "@medusajs/ui";
import { useEffect, useMemo, useState } from "react";
import { useForm, useWatch } from "react-hook-form";
import { Trans, useTranslation } from "react-i18next";

// src/routes/promotions/promotion-create/components/create-promotion-form/form-schema.ts
import { z } from "zod";
var RuleSchema = z.array(
  z.object({
    id: z.string().optional(),
    attribute: z.string().min(1, { message: "Required field" }),
    operator: z.string().min(1, { message: "Required field" }),
    values: z.union([
      z.number().min(1, { message: "Required field" }),
      z.string().min(1, { message: "Required field" }),
      z.array(z.string()).min(1, { message: "Required field" })
    ]),
    required: z.boolean().optional(),
    disguised: z.boolean().optional(),
    field_type: z.string().optional()
  })
);
var CreatePromotionSchema = z.object({
  template_id: z.string().optional(),
  campaign_id: z.string().optional(),
  campaign_choice: z.enum(["none", "existing", "new"]).optional(),
  is_automatic: z.string().toLowerCase(),
  code: z.string().min(1),
  type: z.enum(["buyget", "standard"]),
  status: z.enum(["draft", "active", "inactive"]),
  rules: RuleSchema,
  is_tax_inclusive: z.boolean().optional(),
  limit: z.number().int().min(1).nullable().optional(),
  application_method: z.object({
    allocation: z.enum(["each", "across", "once"]),
    value: z.number().min(0).or(z.string().min(1)),
    currency_code: z.string().optional(),
    max_quantity: z.number().optional().nullable(),
    target_rules: RuleSchema,
    buy_rules: RuleSchema,
    type: z.enum(["fixed", "percentage"]),
    target_type: z.enum(["order", "shipping_methods", "items"])
  }),
  campaign: CreateCampaignSchema.optional()
}).refine(
  (data) => {
    if (data.application_method.allocation === "across") {
      return true;
    }
    return (data.application_method.allocation === "each" || data.application_method.allocation === "once") && typeof data.application_method.max_quantity === "number";
  },
  {
    path: ["application_method.max_quantity"],
    message: `required field`
  }
);

// src/routes/promotions/promotion-create/components/create-promotion-form/templates.ts
var commonHiddenFields = ["type", "application_method.type"];
var amountOfOrderHiddenFields = [
  ...commonHiddenFields,
  "application_method.allocation"
];
var amountOfProductHiddenFields = [
  ...commonHiddenFields,
  "application_method.allocation.across"
];
var percentageOfOrderHiddenFields = [
  ...commonHiddenFields,
  "application_method.allocation",
  "is_tax_inclusive"
];
var percentageOfProductHiddenFields = [
  ...commonHiddenFields,
  "application_method.allocation.across",
  "is_tax_inclusive"
];
var buyGetHiddenFields = [
  ...commonHiddenFields,
  "application_method.value",
  "application_method.allocation",
  "is_tax_inclusive"
];
var freeShippingHiddenFields = [
  ...commonHiddenFields,
  "application_method.value",
  "application_method.allocation",
  "is_tax_inclusive"
];
var templates = [
  {
    id: "amount_off_products",
    type: "standard",
    title: "promotions.templates.amount_off_products.title",
    description: "promotions.templates.amount_off_products.description",
    hiddenFields: amountOfProductHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "standard",
      application_method: {
        allocation: "each",
        target_type: "items",
        type: "fixed"
      }
    }
  },
  {
    id: "amount_off_order",
    type: "standard",
    title: "promotions.templates.amount_off_order.title",
    description: "promotions.templates.amount_off_order.description",
    hiddenFields: amountOfOrderHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "standard",
      application_method: {
        allocation: "across",
        target_type: "order",
        type: "fixed"
      }
    }
  },
  {
    id: "percentage_off_product",
    type: "standard",
    title: "promotions.templates.percentage_off_product.title",
    description: "promotions.templates.percentage_off_product.description",
    hiddenFields: percentageOfProductHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "standard",
      application_method: {
        allocation: "each",
        target_type: "items",
        type: "percentage"
      }
    }
  },
  {
    id: "percentage_off_order",
    type: "standard",
    title: "promotions.templates.percentage_off_order.title",
    description: "promotions.templates.percentage_off_order.description",
    hiddenFields: percentageOfOrderHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "standard",
      application_method: {
        allocation: "across",
        target_type: "order",
        type: "percentage"
      }
    }
  },
  {
    id: "buy_get",
    type: "buy_get",
    title: "promotions.templates.buy_get.title",
    description: "promotions.templates.buy_get.description",
    hiddenFields: buyGetHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "buyget",
      application_method: {
        type: "percentage",
        value: 100,
        apply_to_quantity: 1,
        max_quantity: 1
      }
    }
  },
  {
    id: "shipping_discount",
    type: "standard",
    title: "promotions.templates.shipping_discount.title",
    description: "promotions.templates.shipping_discount.description",
    hiddenFields: freeShippingHiddenFields,
    defaults: {
      is_automatic: "false",
      type: "standard",
      application_method: {
        allocation: "across",
        target_type: "shipping_methods",
        type: "percentage",
        value: 100
      }
    }
  }
];

// src/routes/promotions/promotion-create/components/create-promotion-form/create-promotion-form.tsx
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var defaultValues = {
  campaign_id: void 0,
  template_id: templates[0].id,
  campaign_choice: "none",
  is_automatic: "false",
  code: "",
  type: "standard",
  status: "draft",
  rules: [],
  is_tax_inclusive: false,
  limit: void 0,
  application_method: {
    allocation: "each",
    type: "fixed",
    target_type: "items",
    max_quantity: 1,
    target_rules: [],
    buy_rules: []
  },
  campaign: void 0
};
var CreatePromotionForm = () => {
  const [tab, setTab] = useState("type" /* TYPE */);
  const [tabState, setTabState] = useState({
    ["type" /* TYPE */]: "in-progress",
    ["promotion" /* PROMOTION */]: "not-started",
    ["campaign" /* CAMPAIGN */]: "not-started"
  });
  const { t } = useTranslation();
  const { handleSuccess } = useRouteModal();
  const direction = useDocumentDirection();
  const form = useForm({
    defaultValues,
    resolver: zodResolver(CreatePromotionSchema)
  });
  const { setValue, reset, getValues } = form;
  const { mutateAsync: createPromotion } = useCreatePromotion();
  const handleSubmit = form.handleSubmit(
    async (data) => {
      const {
        campaign_choice: _campaignChoice,
        is_automatic,
        is_tax_inclusive,
        template_id: _templateId,
        application_method,
        rules,
        ...promotionData
      } = data;
      const {
        target_rules: targetRulesData = [],
        buy_rules: buyRulesData = [],
        ...applicationMethodData
      } = application_method;
      const disguisedRules = [
        ...targetRulesData.filter((r) => !!r.disguised),
        ...buyRulesData.filter((r) => !!r.disguised),
        ...rules.filter((r) => !!r.disguised)
      ];
      const applicationMethodRuleData = {};
      for (const rule of disguisedRules) {
        applicationMethodRuleData[rule.attribute] = rule.field_type === "number" ? parseInt(rule.values) : rule.values;
      }
      const buildRulesData = (rules2) => {
        return rules2.filter((r) => !r.disguised).map((rule) => ({
          operator: rule.operator,
          attribute: rule.attribute,
          values: rule.values
        }));
      };
      if (data.campaign) {
        data.campaign.budget.attribute = data.campaign.budget.attribute || null;
        data.campaign.budget.type = data.campaign.budget.attribute ? "use_by_attribute" : data.campaign.budget.type;
      }
      createPromotion(
        {
          ...promotionData,
          rules: buildRulesData(rules),
          application_method: {
            ...applicationMethodData,
            ...applicationMethodRuleData,
            value: parseFloat(applicationMethodData.value),
            target_rules: buildRulesData(targetRulesData),
            buy_rules: buildRulesData(buyRulesData)
          },
          is_tax_inclusive,
          is_automatic: is_automatic === "true"
        },
        {
          onSuccess: ({ promotion }) => {
            toast.success(
              t("promotions.toasts.promotionCreateSuccess", {
                code: promotion.code
              })
            );
            handleSuccess(`/promotions/${promotion.id}`);
          },
          onError: (e) => {
            toast.error(e.message);
          }
        }
      );
    },
    async (error) => {
      const { campaign: _campaign, ...rest } = error || {};
      const errorInPromotionTab = !!Object.keys(rest || {}).length;
      if (errorInPromotionTab) {
        toast.error(t("promotions.errors.promotionTabError"));
      }
    }
  );
  const handleTabChange = async (tab2) => {
    switch (tab2) {
      case "type" /* TYPE */:
        setTabState((prev) => ({
          ...prev,
          ["type" /* TYPE */]: "in-progress"
        }));
        setTab(tab2);
        break;
      case "promotion" /* PROMOTION */:
        setTabState((prev) => ({
          ...prev,
          ["type" /* TYPE */]: "completed",
          ["promotion" /* PROMOTION */]: "in-progress"
        }));
        setTab(tab2);
        break;
      case "campaign" /* CAMPAIGN */: {
        const valid = await form.trigger();
        if (!valid) {
          setTabState({
            ["type" /* TYPE */]: "completed",
            ["promotion" /* PROMOTION */]: "in-progress",
            ["campaign" /* CAMPAIGN */]: "not-started"
          });
          setTab("promotion" /* PROMOTION */);
          break;
        }
        setTabState((prev) => ({
          ...prev,
          ["promotion" /* PROMOTION */]: "completed",
          ["campaign" /* CAMPAIGN */]: "in-progress"
        }));
        setTab(tab2);
        break;
      }
    }
  };
  const handleContinue = async () => {
    switch (tab) {
      case "type" /* TYPE */:
        handleTabChange("promotion" /* PROMOTION */);
        break;
      case "promotion" /* PROMOTION */: {
        const valid = await form.trigger();
        if (valid) {
          handleTabChange("campaign" /* CAMPAIGN */);
        }
        break;
      }
      case "campaign" /* CAMPAIGN */:
        break;
    }
  };
  const watchTemplateId = useWatch({
    control: form.control,
    name: "template_id"
  });
  const currentTemplate = useMemo(() => {
    const currentTemplate2 = templates.find(
      (template) => template.id === watchTemplateId
    );
    if (!currentTemplate2) {
      return;
    }
    reset({ ...defaultValues, template_id: watchTemplateId });
    for (const [key, value] of Object.entries(currentTemplate2.defaults)) {
      if (typeof value === "object") {
        for (const [subKey, subValue] of Object.entries(value)) {
          setValue(`application_method.${subKey}`, subValue);
        }
      } else {
        setValue(key, value);
      }
    }
    if (currentTemplate2.defaults?.application_method?.allocation === "across") {
      setValue("application_method.max_quantity", null);
    }
    return currentTemplate2;
  }, [watchTemplateId, setValue, reset]);
  const watchValueType = useWatch({
    control: form.control,
    name: "application_method.type"
  });
  const isFixedValueType = watchValueType === "fixed";
  const watchAllocation = useWatch({
    control: form.control,
    name: "application_method.allocation"
  });
  useEffect(() => {
    if (watchAllocation === "across") {
      setValue("application_method.max_quantity", null);
    }
  }, [watchAllocation, setValue]);
  const watchType = useWatch({
    control: form.control,
    name: "type"
  });
  const isTypeStandard = watchType === "standard";
  const isTypeBuyGet = watchType === "buyget";
  const targetType = useWatch({
    control: form.control,
    name: "application_method.target_type"
  });
  const isTargetTypeOrder = targetType === "order";
  const watchCampaignChoice = useWatch({
    control: form.control,
    name: "campaign_choice"
  });
  useEffect(() => {
    const formData = getValues();
    if (watchCampaignChoice !== "existing") {
      setValue("campaign_id", void 0);
    }
    if (watchCampaignChoice !== "new") {
      setValue("campaign", void 0);
    }
    if (watchCampaignChoice === "new") {
      if (!formData.campaign || !formData.campaign?.budget?.type) {
        setValue("campaign", {
          ...DEFAULT_CAMPAIGN_VALUES,
          budget: {
            ...DEFAULT_CAMPAIGN_VALUES.budget,
            currency_code: formData.application_method.currency_code
          }
        });
      }
    }
  }, [watchCampaignChoice, getValues, setValue]);
  const watchRules = useWatch({
    control: form.control,
    name: "rules"
  });
  const watchCurrencyRule = watchRules.find(
    (rule) => rule.attribute === "currency_code"
  );
  if (watchCurrencyRule) {
    const formData = form.getValues();
    const currencyCode = formData.application_method.currency_code;
    const ruleValue = watchCurrencyRule.values;
    if (!Array.isArray(ruleValue) && currencyCode !== ruleValue) {
      form.setValue("application_method.currency_code", ruleValue);
    }
  }
  return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex h-full flex-col", onSubmit: handleSubmit, children: [
    /* @__PURE__ */ jsxs(
      ProgressTabs,
      {
        dir: direction,
        value: tab,
        onValueChange: (tab2) => handleTabChange(tab2),
        className: "flex h-full flex-col overflow-hidden",
        children: [
          /* @__PURE__ */ jsx(RouteFocusModal.Header, { children: /* @__PURE__ */ jsx("div", { className: "flex w-full items-center justify-between gap-x-4", children: /* @__PURE__ */ jsx("div", { className: "-my-2 w-full max-w-[600px] border-l", children: /* @__PURE__ */ jsxs(ProgressTabs.List, { className: "grid w-full grid-cols-3", children: [
            /* @__PURE__ */ jsx(
              ProgressTabs.Trigger,
              {
                className: "w-full",
                value: "type" /* TYPE */,
                status: tabState["type" /* TYPE */],
                children: t("promotions.tabs.template")
              }
            ),
            /* @__PURE__ */ jsx(
              ProgressTabs.Trigger,
              {
                className: "w-full",
                value: "promotion" /* PROMOTION */,
                status: tabState["promotion" /* PROMOTION */],
                children: t("promotions.tabs.details")
              }
            ),
            /* @__PURE__ */ jsx(
              ProgressTabs.Trigger,
              {
                className: "w-full",
                value: "campaign" /* CAMPAIGN */,
                status: tabState["campaign" /* CAMPAIGN */],
                children: t("promotions.tabs.campaign")
              }
            )
          ] }) }) }) }),
          /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "size-full overflow-hidden", children: [
            /* @__PURE__ */ jsx(
              ProgressTabs.Content,
              {
                value: "type" /* TYPE */,
                className: "size-full overflow-y-auto",
                children: /* @__PURE__ */ jsx("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsx("div", { className: "w-full max-w-[720px] py-16", children: /* @__PURE__ */ jsx(
                  Form.Field,
                  {
                    control: form.control,
                    name: "template_id",
                    render: ({ field }) => {
                      return /* @__PURE__ */ jsxs(Form.Item, { children: [
                        /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.fields.type") }),
                        /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
                          RadioGroup,
                          {
                            dir: direction,
                            className: "flex-col gap-y-3",
                            ...field,
                            onValueChange: field.onChange,
                            children: templates.map((template) => {
                              return /* @__PURE__ */ jsx(
                                RadioGroup.ChoiceBox,
                                {
                                  value: template.id,
                                  label: t(template.title),
                                  description: t(template.description)
                                },
                                template.id
                              );
                            })
                          },
                          "template_id"
                        ) }),
                        /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                      ] });
                    }
                  }
                ) }) })
              }
            ),
            /* @__PURE__ */ jsx(
              ProgressTabs.Content,
              {
                value: "promotion" /* PROMOTION */,
                className: "size-full overflow-y-auto",
                children: /* @__PURE__ */ jsx("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8 py-16", children: [
                  /* @__PURE__ */ jsxs(Heading, { level: "h1", className: "text-fg-base", children: [
                    t(`promotions.sections.details`),
                    currentTemplate?.title && /* @__PURE__ */ jsx(
                      Badge,
                      {
                        className: "ml-2 align-middle",
                        color: "grey",
                        size: "2xsmall",
                        rounded: "full",
                        children: t(currentTemplate.title)
                      }
                    )
                  ] }),
                  form.formState.errors.root && /* @__PURE__ */ jsx(
                    Alert,
                    {
                      variant: "error",
                      dismissible: false,
                      className: "text-balance",
                      children: form.formState.errors.root.message
                    }
                  ),
                  /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "is_automatic",
                      render: ({ field }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { children: [
                          /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.method.label") }),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
                            RadioGroup,
                            {
                              dir: direction,
                              className: "flex gap-y-3",
                              ...field,
                              value: field.value,
                              onValueChange: field.onChange,
                              children: [
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "false",
                                    label: t("promotions.form.method.code.title"),
                                    description: t(
                                      "promotions.form.method.code.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                ),
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "true",
                                    label: t(
                                      "promotions.form.method.automatic.title"
                                    ),
                                    description: t(
                                      "promotions.form.method.automatic.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                )
                              ]
                            }
                          ) }),
                          /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                        ] });
                      }
                    }
                  ),
                  /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "status",
                      render: ({ field }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { children: [
                          /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.status.label") }),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
                            RadioGroup,
                            {
                              dir: direction,
                              className: "flex gap-y-3",
                              ...field,
                              value: field.value,
                              onValueChange: field.onChange,
                              children: [
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "draft",
                                    label: t("promotions.form.status.draft.title"),
                                    description: t(
                                      "promotions.form.status.draft.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                ),
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "active",
                                    label: t("promotions.form.status.active.title"),
                                    description: t(
                                      "promotions.form.status.active.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                )
                              ]
                            }
                          ) }),
                          /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                        ] });
                      }
                    }
                  ),
                  /* @__PURE__ */ jsx("div", { className: "flex gap-y-4", children: /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "code",
                      render: ({ field }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { className: "basis-1/2", children: [
                          /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.code.title") }),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field, placeholder: "SUMMER15" }) }),
                          /* @__PURE__ */ jsx(
                            Text,
                            {
                              size: "small",
                              leading: "compact",
                              className: "text-ui-fg-subtle",
                              children: /* @__PURE__ */ jsx(
                                Trans,
                                {
                                  t,
                                  i18nKey: "promotions.form.code.description",
                                  components: [/* @__PURE__ */ jsx("br", {}, "break")]
                                }
                              )
                            }
                          )
                        ] });
                      }
                    }
                  ) }),
                  !currentTemplate?.hiddenFields?.includes(
                    "is_tax_inclusive"
                  ) && /* @__PURE__ */ jsxs(Fragment, { children: [
                    /* @__PURE__ */ jsx(Divider, {}),
                    /* @__PURE__ */ jsx("div", { className: "flex gap-x-2 gap-y-4", children: /* @__PURE__ */ jsx(
                      Form.Field,
                      {
                        control: form.control,
                        name: "is_tax_inclusive",
                        render: ({
                          field: { onChange, value, ...field }
                        }) => {
                          return /* @__PURE__ */ jsxs(Form.Item, { className: "basis-full", children: [
                            /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
                              /* @__PURE__ */ jsxs("div", { className: "block", children: [
                                /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.taxInclusive.title") }),
                                /* @__PURE__ */ jsx(Form.Hint, { className: "!mt-1", children: t(
                                  "promotions.form.taxInclusive.description"
                                ) })
                              ] }),
                              /* @__PURE__ */ jsx(Form.Control, { className: "mr-2 self-center", children: /* @__PURE__ */ jsx(
                                Switch,
                                {
                                  dir: "ltr",
                                  className: "mt-[2px] rtl:rotate-180",
                                  checked: !!value,
                                  onCheckedChange: onChange,
                                  ...field
                                }
                              ) })
                            ] }),
                            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                          ] });
                        }
                      }
                    ) })
                  ] }),
                  !currentTemplate?.hiddenFields?.includes("type") && /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "type",
                      render: ({ field }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { children: [
                          /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.fields.type") }),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
                            RadioGroup,
                            {
                              dir: direction,
                              className: "flex gap-y-3",
                              ...field,
                              onValueChange: field.onChange,
                              children: [
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "standard",
                                    label: t(
                                      "promotions.form.type.standard.title"
                                    ),
                                    description: t(
                                      "promotions.form.type.standard.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                ),
                                /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "buyget",
                                    label: t("promotions.form.type.buyget.title"),
                                    description: t(
                                      "promotions.form.type.buyget.description"
                                    ),
                                    className: clx("basis-1/2")
                                  }
                                )
                              ]
                            }
                          ) }),
                          /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                        ] });
                      }
                    }
                  ),
                  /* @__PURE__ */ jsx(Divider, {}),
                  /* @__PURE__ */ jsx(RulesFormField, { form, ruleType: "rules" }),
                  !currentTemplate?.hiddenFields?.includes(
                    "application_method.type"
                  ) && /* @__PURE__ */ jsxs(Fragment, { children: [
                    /* @__PURE__ */ jsx(Divider, {}),
                    /* @__PURE__ */ jsx(
                      Form.Field,
                      {
                        control: form.control,
                        name: "application_method.type",
                        render: ({ field }) => {
                          return /* @__PURE__ */ jsxs(Form.Item, { children: [
                            /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.fields.value_type") }),
                            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
                              RadioGroup,
                              {
                                dir: direction,
                                className: "flex gap-y-3",
                                ...field,
                                onValueChange: field.onChange,
                                children: [
                                  /* @__PURE__ */ jsx(
                                    RadioGroup.ChoiceBox,
                                    {
                                      value: "fixed",
                                      label: t(
                                        "promotions.form.value_type.fixed.title"
                                      ),
                                      description: t(
                                        "promotions.form.value_type.fixed.description"
                                      ),
                                      className: clx("basis-1/2")
                                    }
                                  ),
                                  /* @__PURE__ */ jsx(
                                    RadioGroup.ChoiceBox,
                                    {
                                      value: "percentage",
                                      label: t(
                                        "promotions.form.value_type.percentage.title"
                                      ),
                                      description: t(
                                        "promotions.form.value_type.percentage.description"
                                      ),
                                      className: clx("basis-1/2")
                                    }
                                  )
                                ]
                              }
                            ) }),
                            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                          ] });
                        }
                      }
                    )
                  ] }),
                  !currentTemplate?.hiddenFields?.includes(
                    "application_method.value"
                  ) && /* @__PURE__ */ jsxs(Fragment, { children: [
                    /* @__PURE__ */ jsx(Divider, {}),
                    /* @__PURE__ */ jsx(
                      Form.Field,
                      {
                        control: form.control,
                        name: "application_method.value",
                        render: ({ field: { onChange, value, ...field } }) => {
                          const currencyCode = form.getValues().application_method.currency_code;
                          const currencyInfo = currencies[currencyCode?.toUpperCase() || "USD"];
                          return /* @__PURE__ */ jsxs(Form.Item, { className: "basis-1/2", children: [
                            /* @__PURE__ */ jsx(
                              Form.Label,
                              {
                                tooltip: currencyCode || !isFixedValueType ? void 0 : t("promotions.fields.amount.tooltip"),
                                children: t("promotions.form.value.title")
                              }
                            ),
                            /* @__PURE__ */ jsx(Form.Control, { children: isFixedValueType ? /* @__PURE__ */ jsx(
                              CurrencyInput,
                              {
                                ...field,
                                min: 0,
                                code: currencyCode || "USD",
                                onValueChange: (_value, _name, values) => onChange(values?.value),
                                decimalScale: currencyInfo?.decimal_digits ?? 2,
                                decimalsLimit: currencyInfo?.decimal_digits ?? 2,
                                symbol: currencyCode ? getCurrencySymbol(currencyCode) : "$",
                                value,
                                disabled: !currencyCode
                              }
                            ) : /* @__PURE__ */ jsx(
                              DeprecatedPercentageInput,
                              {
                                className: "text-right",
                                min: 0,
                                max: 100,
                                ...field,
                                value,
                                onChange: (e) => {
                                  onChange(
                                    e.target.value === "" ? null : parseFloat(e.target.value)
                                  );
                                }
                              },
                              "amount"
                            ) }),
                            /* @__PURE__ */ jsx(
                              Text,
                              {
                                size: "small",
                                leading: "compact",
                                className: "text-ui-fg-subtle",
                                children: /* @__PURE__ */ jsx(
                                  Trans,
                                  {
                                    t,
                                    i18nKey: isFixedValueType ? "promotions.form.value_type.fixed.description" : "promotions.form.value_type.percentage.description",
                                    components: [/* @__PURE__ */ jsx("br", {}, "break")]
                                  }
                                )
                              }
                            ),
                            /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                          ] });
                        }
                      }
                    )
                  ] }),
                  (isTypeStandard && (watchAllocation === "each" || watchAllocation === "once") || isTypeBuyGet) && /* @__PURE__ */ jsxs(Fragment, { children: [
                    isTypeBuyGet && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Divider, {}) }),
                    /* @__PURE__ */ jsx(
                      Form.Field,
                      {
                        control: form.control,
                        name: "application_method.max_quantity",
                        render: () => {
                          return /* @__PURE__ */ jsxs(Form.Item, { className: "basis-1/2", children: [
                            /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.max_quantity.title") }),
                            /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
                              Input,
                              {
                                ...form.register(
                                  "application_method.max_quantity",
                                  { valueAsNumber: true }
                                ),
                                type: "number",
                                min: 1,
                                placeholder: "3"
                              }
                            ) }),
                            /* @__PURE__ */ jsx(
                              Text,
                              {
                                size: "small",
                                leading: "compact",
                                className: "text-ui-fg-subtle",
                                children: /* @__PURE__ */ jsx(
                                  Trans,
                                  {
                                    t,
                                    i18nKey: "promotions.form.max_quantity.description",
                                    components: [/* @__PURE__ */ jsx("br", {}, "break")]
                                  }
                                )
                              }
                            )
                          ] });
                        }
                      }
                    )
                  ] }),
                  isTypeStandard && !currentTemplate?.hiddenFields?.includes(
                    "application_method.allocation"
                  ) && /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "application_method.allocation",
                      render: ({ field }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { children: [
                          /* @__PURE__ */ jsx(
                            Form.Label,
                            {
                              tooltip: t(
                                "promotions.fields.allocationTooltip"
                              ),
                              children: t("promotions.fields.allocation")
                            }
                          ),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
                            RadioGroup,
                            {
                              dir: direction,
                              className: "flex gap-y-3",
                              ...field,
                              onValueChange: field.onChange,
                              children: [
                                !currentTemplate?.hiddenFields?.includes(
                                  "application_method.allocation.each"
                                ) && /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "each",
                                    label: t(
                                      "promotions.form.allocation.each.title"
                                    ),
                                    description: t(
                                      "promotions.form.allocation.each.description"
                                    ),
                                    className: clx("basis-1/3")
                                  }
                                ),
                                !currentTemplate?.hiddenFields?.includes(
                                  "application_method.allocation.across"
                                ) && /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "across",
                                    label: t(
                                      "promotions.form.allocation.across.title"
                                    ),
                                    description: t(
                                      "promotions.form.allocation.across.description"
                                    ),
                                    className: clx("basis-1/3")
                                  }
                                ),
                                !currentTemplate?.hiddenFields?.includes(
                                  "application_method.allocation.once"
                                ) && /* @__PURE__ */ jsx(
                                  RadioGroup.ChoiceBox,
                                  {
                                    value: "once",
                                    label: t(
                                      "promotions.form.allocation.once.title"
                                    ),
                                    description: t(
                                      "promotions.form.allocation.once.description"
                                    ),
                                    className: clx("basis-1/3")
                                  }
                                )
                              ]
                            }
                          ) }),
                          /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                        ] });
                      }
                    }
                  ),
                  !isTypeStandard && /* @__PURE__ */ jsxs(Fragment, { children: [
                    /* @__PURE__ */ jsx(Divider, {}),
                    /* @__PURE__ */ jsx(
                      RulesFormField,
                      {
                        form,
                        ruleType: "buy-rules",
                        scope: "application_method.buy_rules"
                      }
                    )
                  ] }),
                  !isTargetTypeOrder && /* @__PURE__ */ jsxs(Fragment, { children: [
                    /* @__PURE__ */ jsx(Divider, {}),
                    /* @__PURE__ */ jsx(
                      RulesFormField,
                      {
                        form,
                        ruleType: "target-rules",
                        scope: "application_method.target_rules"
                      }
                    )
                  ] }),
                  /* @__PURE__ */ jsx(Divider, {}),
                  /* @__PURE__ */ jsx(
                    Form.Field,
                    {
                      control: form.control,
                      name: "limit",
                      render: ({ field: { onChange, value, ...field } }) => {
                        return /* @__PURE__ */ jsxs(Form.Item, { className: "basis-1/2", children: [
                          /* @__PURE__ */ jsx(Form.Label, { children: t("promotions.form.limit.title") }),
                          /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
                            Input,
                            {
                              ...field,
                              type: "number",
                              min: 1,
                              value: value ?? "",
                              onChange: (e) => {
                                const val = e.target.value;
                                onChange(val === "" ? null : parseInt(val, 10));
                              },
                              placeholder: "100"
                            }
                          ) }),
                          /* @__PURE__ */ jsx(
                            Text,
                            {
                              size: "small",
                              leading: "compact",
                              className: "text-ui-fg-subtle",
                              children: t("promotions.form.limit.description")
                            }
                          ),
                          /* @__PURE__ */ jsx(Form.ErrorMessage, {})
                        ] });
                      }
                    }
                  )
                ] }) })
              }
            ),
            /* @__PURE__ */ jsx(
              ProgressTabs.Content,
              {
                value: "campaign" /* CAMPAIGN */,
                className: "size-full overflow-auto",
                children: /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsx("div", { className: "flex w-full max-w-[720px] flex-col gap-y-8 py-16", children: /* @__PURE__ */ jsx(AddCampaignPromotionFields, { form }) }) })
              }
            )
          ] })
        ]
      }
    ),
    /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
      /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: t("actions.cancel") }) }),
      tab === "campaign" /* CAMPAIGN */ ? /* @__PURE__ */ jsx(
        Button,
        {
          type: "submit",
          size: "small",
          isLoading: false,
          children: t("actions.save")
        },
        "save-btn"
      ) : /* @__PURE__ */ jsx(
        Button,
        {
          type: "button",
          onClick: handleContinue,
          size: "small",
          children: t("actions.continue")
        },
        "continue-btn"
      )
    ] }) })
  ] }) });
};

// src/routes/promotions/promotion-create/promotion-create.tsx
import { jsx as jsx2 } from "react/jsx-runtime";
var PromotionCreate = () => {
  return /* @__PURE__ */ jsx2(RouteFocusModal, { children: /* @__PURE__ */ jsx2(CreatePromotionForm, {}) });
};
export {
  PromotionCreate as Component
};
