import { jsx as a, jsxs as U } from "react/jsx-runtime";
import { a as Q } from "./index.CfQlFjZU.js";
import { n as E } from "./index.B0wX8xO7.js";
import { Q as O } from "./index.dWlEA7uO.js";
import { g as V } from "./index.CfM2L_w0.js";
import { useState as W, useEffect as Z, useMemo as z } from "react";
import { S as q } from "./shared.EdGf6tcG.js";
import { t as $ } from "./url.D3ItqZWD.js";
import { c as j } from "./digital-products.DJwTMysi.js";
import { B as P } from "./Button.CpTwUWVr.js";
import { R as ee } from "./Preloader.DgWknb4q.js";
import { a as R } from "./TextInput.63vMRxAK.js";
import { U as B } from "./Upload.X0oU32lw.js";
import { u as te } from "./ToastContext.k_CLoeOA.js";
import { a as oe } from "./TabBar.Dal6Y13v.js";
import { I as re } from "./ItemCreationTemplate.DZj_4KLv.js";
import "./ItemCreationContext.CFI6PyWk.js";
import { T as H } from "./Typography.a1p6WNM8.js";
import { a as ae } from "./ComboInput.C7taEbNO.js";
import { l as le } from "./lodash.xuulwbEa.js";
var M, G;
function ie() {
  return G || (G = 1, M = function() {
    var r = document.getSelection();
    if (!r.rangeCount)
      return function() {
      };
    for (var p = document.activeElement, y = [], m = 0; m < r.rangeCount; m++)
      y.push(r.getRangeAt(m));
    switch (p.tagName.toUpperCase()) {
      // .toUpperCase handles XHTML
      case "INPUT":
      case "TEXTAREA":
        p.blur();
        break;
      default:
        p = null;
        break;
    }
    return r.removeAllRanges(), function() {
      r.type === "Caret" && r.removeAllRanges(), r.rangeCount || y.forEach(function(b) {
        r.addRange(b);
      }), p && p.focus();
    };
  }), M;
}
var N, Y;
function ce() {
  if (Y) return N;
  Y = 1;
  var r = ie(), p = {
    "text/plain": "Text",
    "text/html": "Url",
    default: "Text"
  }, y = "Copy to clipboard: #{key}, Enter";
  function m(d) {
    var o = (/mac os x/i.test(navigator.userAgent) ? "⌘" : "Ctrl") + "+C";
    return d.replace(/#{\s*key\s*}/g, o);
  }
  function b(d, o) {
    var i, h, t, c, n, e, v = !1;
    o || (o = {}), i = o.debug || !1;
    try {
      t = r(), c = document.createRange(), n = document.getSelection(), e = document.createElement("span"), e.textContent = d, e.ariaHidden = "true", e.style.all = "unset", e.style.position = "fixed", e.style.top = 0, e.style.clip = "rect(0, 0, 0, 0)", e.style.whiteSpace = "pre", e.style.webkitUserSelect = "text", e.style.MozUserSelect = "text", e.style.msUserSelect = "text", e.style.userSelect = "text", e.addEventListener("copy", function(l) {
        if (l.stopPropagation(), o.format)
          if (l.preventDefault(), typeof l.clipboardData > "u") {
            i && console.warn("unable to use e.clipboardData"), i && console.warn("trying IE specific stuff"), window.clipboardData.clearData();
            var k = p[o.format] || p.default;
            window.clipboardData.setData(k, d);
          } else
            l.clipboardData.clearData(), l.clipboardData.setData(o.format, d);
        o.onCopy && (l.preventDefault(), o.onCopy(l.clipboardData));
      }), document.body.appendChild(e), c.selectNodeContents(e), n.addRange(c);
      var D = document.execCommand("copy");
      if (!D)
        throw new Error("copy command was unsuccessful");
      v = !0;
    } catch (l) {
      i && console.error("unable to copy using execCommand: ", l), i && console.warn("trying IE specific stuff");
      try {
        window.clipboardData.setData(o.format || "text", d), o.onCopy && o.onCopy(window.clipboardData), v = !0;
      } catch (k) {
        i && console.error("unable to copy using clipboardData: ", k), i && console.error("falling back to prompt"), h = m("message" in o ? o.message : y), window.prompt(h, d);
      }
    } finally {
      n && (typeof n.removeRange == "function" ? n.removeRange(c) : n.removeAllRanges()), e && document.body.removeChild(e), t();
    }
    return v;
  }
  return N = b, N;
}
var ne = ce();
const se = /* @__PURE__ */ V(ne), ue = "creator_header_4TsrC", pe = "creator_body_t21zq", me = "creator_optionalPricing_cm5l0", _ = { header: ue, body: pe, optionalPricing: me }, de = ({
  label: r,
  helper: p,
  onCurrencyChange: y,
  currencyOptions: m = [],
  isDropdownDisabled: b,
  isTextInputDisabled: d,
  errorMessage: o,
  defaultValue: i,
  onPricingInputKeyDown: h,
  onPricingInputPaste: t,
  onPricingInputWheel: c
}) => {
  const [n, e] = W({
    currency: i?.currency || "USD",
    price: i?.price
  });
  return Z(() => {
    i && e(i);
  }, [i]), {
    label: r,
    helper: p,
    currencyField: n,
    currencyOptions: m,
    isDropdownDisabled: b,
    isTextInputDisabled: d,
    errorMessage: o,
    handleCurrencyChange: (D) => {
      e(D), y(D);
    },
    onPricingInputKeyDown: h,
    onPricingInputPaste: t,
    onPricingInputWheel: c
  };
}, fe = ({
  currencyField: r,
  currencyOptions: p,
  handleCurrencyChange: y,
  errorMessage: m,
  label: b,
  helper: d,
  isDropdownDisabled: o,
  isTextInputDisabled: i,
  onPricingInputKeyDown: h,
  onPricingInputPaste: t,
  onPricingInputWheel: c
}) => /* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(
  ae,
  {
    label: b,
    hasError: !!m,
    helper: m || d,
    dropdownProps: {
      disabled: o,
      placeholder: "Select Currency",
      noLabel: !0,
      noHelper: !0,
      items: p,
      value: r.currency,
      removeItemOnReselect: !1,
      onClick: () => {
      },
      onChange: () => {
      },
      onSelect: (n) => {
        const e = le.isString(n[0]) ? n : n[0].value;
        y({ ...r, currency: e });
      }
    },
    textInputProps: {
      isDisabled: i,
      isError: !!m,
      value: r.price,
      type: "number",
      onWheel: c,
      onKeyDown: h,
      onPaste: t,
      onChange: (n) => {
        const { value: e } = n.target;
        /^\d*(\.\d{0,2})?$/.test(e) && y({
          ...r,
          //SB-1367: Setting maximum here as Stripe only support 8 digits and our price always consist of 2 dp
          price: e ? Math.min(parseFloat(e), 999999.99) : void 0
        });
      }
    }
  }
) }), K = Q(
  fe,
  de
), ye = ({
  previousPageUrl: r,
  preview: p,
  onPrevious: y,
  onDone: m,
  creatorDomain: b,
  allowedFileTypes: d = [],
  maxFileSize: o = "64mb",
  imageGallery: i,
  imageGalleryMaxFiles: h,
  onImageGalleryLimitReached: t,
  onImageGalleryAdd: c,
  onImageGalleryRemove: n,
  itemFile: e,
  onItemFileSelect: v,
  onItemFileRemoved: D,
  landingPage: l,
  setLandingPage: k,
  submitting: T,
  disableNext: S,
  errors: A,
  showPricingOptions: L = !1,
  onPricingInputKeyDown: C,
  onPricingInputPaste: u,
  onPricingInputWheel: I
}) => {
  const f = z(() => ({
    ...l,
    title: l?.title || "",
    description: l?.description || "",
    callToAction: l?.callToAction || "",
    customLink: l?.customLink || "",
    itemType: l?.itemType || "file",
    itemLink: l?.itemLink || ""
  }), [l]), { createToast: w } = te(), x = z(
    () => f.itemType === "file" ? 0 : 1,
    [f.itemType]
  ), g = z(
    () => `${b}/store/${$(f.customLink)}`,
    [b, f.customLink]
  ), s = (F) => {
    T || k({
      ...f,
      itemType: F === 0 ? "file" : "link"
    });
  }, X = () => {
    m({
      ...f,
      customLink: $(f.customLink)
    });
  }, J = () => {
    f.customLink && (se(`https://${g}`), w({
      text: "Landing page link copied successfully",
      semantic: "success",
      durationMs: 2e3
    }));
  };
  return {
    steps: [{ label: "Item" }, { label: "Landing Page" }],
    buttons: [
      { label: "Previous", semantic: q.SECONDARY, onClick: y },
      {
        label: "Done",
        semantic: q.PRIMARY,
        onClick: X,
        loading: T,
        disabled: S
      }
    ],
    previousPageUrl: r,
    preview: p,
    tabs: [{ label: "File" }, { label: "Link" }],
    selectedTab: x,
    onItemTypeChange: s,
    customLinkHelper: g,
    handleCopyLink: J,
    landingPage: f,
    setLandingPage: k,
    allowedFileTypes: d,
    maxFileSize: o,
    imageGallery: i,
    imageGalleryMaxFiles: h,
    onImageGalleryAdd: c,
    onImageGalleryRemove: n,
    onImageGalleryLimitReached: t,
    itemFile: e,
    onItemFileSelect: v,
    onItemFileRemoved: D,
    submitting: T,
    errors: A,
    showPricingOptions: L,
    onPricingInputKeyDown: C,
    onPricingInputPaste: u,
    onPricingInputWheel: I,
    onPreviousClicked: (F) => {
      F.preventDefault(), y();
    }
  };
}, be = ({
  steps: r,
  buttons: p,
  previousPageUrl: y,
  preview: m,
  tabs: b,
  selectedTab: d,
  onItemTypeChange: o,
  customLinkHelper: i,
  handleCopyLink: h,
  landingPage: t,
  setLandingPage: c,
  allowedFileTypes: n,
  maxFileSize: e,
  imageGallery: v,
  imageGalleryMaxFiles: D,
  onImageGalleryAdd: l,
  onImageGalleryRemove: k,
  onImageGalleryLimitReached: T,
  itemFile: S,
  onItemFileSelect: A,
  onItemFileRemoved: L,
  submitting: C,
  errors: u,
  onPreviousClicked: I,
  showPricingOptions: f,
  onPricingInputKeyDown: w,
  onPricingInputPaste: x,
  onPricingInputWheel: g
}) => /* @__PURE__ */ U(
  re,
  {
    steps: r,
    activeStepIndex: 1,
    title: f ? "Add Digital Product" : "Add Free Download",
    previousPageUrl: y,
    buttons: p,
    preview: m,
    onClickPrevious: I,
    children: [
      /* @__PURE__ */ U("div", { children: [
        /* @__PURE__ */ a(
          H,
          {
            variant: "header",
            size: "medium",
            component: "h2",
            className: _.header,
            children: "Customize landing page"
          }
        ),
        /* @__PURE__ */ U(H, { variant: "body", size: "small", className: _.body, children: [
          "Create a dedicated landing page with a custom URL to directly link to your ",
          f ? "digital product" : "free download",
          "."
        ] })
      ] }),
      /* @__PURE__ */ a(
        B,
        {
          allowMultipleFiles: !0,
          suggestedAllowedTypes: ["image/jpeg", "image/png"],
          onFilesAdd: l,
          onFilesRemove: k,
          files: v,
          maxFiles: D,
          label: "Image gallery",
          helper: u?.imageGallery || "Max image size 16mb",
          error: !!u?.imageGallery,
          placeholder: "Upload an image",
          disabled: C,
          onLimitReached: T
        }
      ),
      /* @__PURE__ */ a(
        R,
        {
          label: "Landing page title",
          value: t.title,
          onChange: (s) => c({
            ...t,
            title: s.target.value
          }),
          onBlur: (s) => {
            c({
              ...t,
              customLink: t.customLink || s.target.value
            });
          },
          helper: u?.title,
          isError: !!u?.title,
          isDisabled: C
        }
      ),
      /* @__PURE__ */ a(
        ee,
        {
          label: "Description",
          value: t.description,
          onChange: (s) => c({ ...t, description: s }),
          helper: u?.description,
          isError: !!u?.description,
          disabled: C
        }
      ),
      /* @__PURE__ */ a("div", { children: /* @__PURE__ */ a(
        oe,
        {
          tabs: b,
          selectedTab: d,
          onChangeSelectedTab: o
        }
      ) }),
      /* @__PURE__ */ a(
        E,
        {
          value: t.itemType === "file",
          then: /* @__PURE__ */ a(
            B,
            {
              label: "Upload file",
              helper: u?.itemFile || `Max file size ${e}`,
              suggestedAllowedTypes: n,
              onFileSelect: A,
              onFileRemove: L,
              file: S,
              disabled: C,
              error: !!u?.itemFile
            }
          ),
          otherwise: /* @__PURE__ */ a(
            R,
            {
              label: "Link",
              value: t.itemLink,
              onChange: (s) => c({ ...t, itemLink: s.target.value }),
              isDisabled: C,
              helper: u?.itemLink,
              isError: !!u?.itemLink
            }
          )
        }
      ),
      /* @__PURE__ */ a(
        E,
        {
          value: f,
          then: /* @__PURE__ */ a(
            K,
            {
              defaultValue: t.regularPrice,
              label: "Regular price",
              onCurrencyChange: (s) => {
                c({
                  ...t,
                  regularPrice: s,
                  discountedPrice: {
                    ...t.discountedPrice,
                    currency: s.currency
                  }
                });
              },
              isDropdownDisabled: C,
              isTextInputDisabled: C,
              currencyOptions: j,
              errorMessage: u?.regularPrice,
              onPricingInputKeyDown: w,
              onPricingInputPaste: x,
              onPricingInputWheel: g
            }
          )
        }
      ),
      /* @__PURE__ */ a(
        E,
        {
          value: f,
          then: /* @__PURE__ */ a("div", { className: _.optionalPricing, children: /* @__PURE__ */ a(
            K,
            {
              defaultValue: t.discountedPrice,
              label: "Discounted price",
              helper: "Optional",
              isDropdownDisabled: !0,
              isTextInputDisabled: C,
              onCurrencyChange: (s) => c({ ...t, discountedPrice: s }),
              onPricingInputKeyDown: w,
              onPricingInputPaste: x,
              onPricingInputWheel: g,
              currencyOptions: j
            }
          ) })
        }
      ),
      /* @__PURE__ */ a(
        E,
        {
          value: !f,
          then: /* @__PURE__ */ a(
            R,
            {
              label: "Call-to-action button",
              value: t.callToAction,
              onChange: (s) => c({ ...t, callToAction: s.target.value }),
              helper: u?.callToAction,
              isError: !!u?.callToAction,
              isDisabled: C,
              maxLength: 24
            }
          )
        }
      ),
      /* @__PURE__ */ a(
        R,
        {
          label: "Custom link",
          suffixIcon: /* @__PURE__ */ a(
            P,
            {
              label: "Copy link",
              size: "2xsmall",
              prefixIcon: /* @__PURE__ */ a(O, { size: 24 }),
              onClick: h
            }
          ),
          helper: u?.customLink || i,
          value: t.customLink,
          onChange: (s) => c({ ...t, customLink: s.target.value }),
          isDisabled: C,
          isError: !!u?.customLink
        }
      )
    ]
  }
), _e = Q(
  be,
  ye
);
export {
  _e as D
};
