@lockerverse/react 0.2.97 → 0.2.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"host-callback.js","names":[],"sources":["../src/accent-contrast.ts","../src/custom-fields.tsx","../src/form-skeleton.tsx","../src/contact-validation.ts","../src/phone.ts","../src/host-callback.ts"],"sourcesContent":["const HEX_COLOR = /^#([\\da-f]{3}|[\\da-f]{6})$/i;\nconst UNPREFIXED_HEX_COLOR = /^([\\da-f]{3}|[\\da-f]{6})$/i;\n\nexport function normalizeAccentColor(color: string) {\n const trimmedColor = color.trim();\n return UNPREFIXED_HEX_COLOR.test(trimmedColor)\n ? `#${trimmedColor}`\n : trimmedColor;\n}\n\nfunction parseHexColor(color: string) {\n const match = HEX_COLOR.exec(normalizeAccentColor(color));\n if (!match) {\n return;\n }\n const [, value] = match;\n if (!value) {\n return;\n }\n const expanded =\n value.length === 3\n ? Array.from(value, (character) => `${character}${character}`).join(\"\")\n : value;\n return [0, 2, 4].map((offset) =>\n Number.parseInt(expanded.slice(offset, offset + 2), 16)\n );\n}\n\nfunction relativeLuminance([red, green, blue]: number[]) {\n const [linearRed = 0, linearGreen = 0, linearBlue = 0] = [\n red,\n green,\n blue,\n ].map((channel = 0) => {\n const normalized = channel / 255;\n return normalized <= 0.040_45\n ? normalized / 12.92\n : ((normalized + 0.055) / 1.055) ** 2.4;\n });\n return 0.2126 * linearRed + 0.7152 * linearGreen + 0.0722 * linearBlue;\n}\n\nexport function getAccentContrast(color: string) {\n const parsed = parseHexColor(color);\n if (!parsed) {\n return;\n }\n const luminance = relativeLuminance(parsed);\n const blackContrast = (luminance + 0.05) / 0.05;\n const whiteContrast = 1.05 / (luminance + 0.05);\n return blackContrast >= whiteContrast ? \"#000\" : \"#fff\";\n}\n","import type {\n LockerverseBooleanCustomField,\n LockerverseCustomField,\n LockerverseCustomFieldAnswer,\n LockerverseMultiOptionCustomField,\n LockerverseSingleOptionCustomField,\n} from \"@lockerverse/sdk/checkout\";\nimport {\n array,\n minLength,\n nonEmpty,\n pipe,\n safeParse,\n string,\n trim,\n} from \"valibot\";\n\nexport type CustomFieldValues = Record<string, boolean | string | string[]>;\n\nfunction createCustomFieldValue(field: LockerverseCustomField) {\n if (field.type === \"checkbox\") {\n return false;\n }\n if (field.type === \"checkboxes\" || field.type === \"multi_select\") {\n return [];\n }\n return \"\";\n}\n\nexport function createCustomFieldValues(fields: LockerverseCustomField[]) {\n const values: CustomFieldValues = {};\n for (const field of fields) {\n values[field.id] = createCustomFieldValue(field);\n }\n return values;\n}\n\nfunction getStringValue(value: CustomFieldValues[string] | undefined) {\n const result = safeParse(string(), value);\n return result.success ? result.output : \"\";\n}\n\nexport function buildCustomFieldAnswers(\n fields: LockerverseCustomField[],\n values: CustomFieldValues\n): LockerverseCustomFieldAnswer[] {\n return fields.map((field): LockerverseCustomFieldAnswer => {\n const value = values[field.id];\n if (field.type === \"checkbox\") {\n return { fieldId: field.id, value: value === true };\n }\n if (field.type === \"checkboxes\" || field.type === \"multi_select\") {\n return { fieldId: field.id, value: Array.isArray(value) ? value : [] };\n }\n return {\n fieldId: field.id,\n value: getStringValue(value),\n };\n });\n}\n\nexport function validateCustomFields(\n fields: LockerverseCustomField[],\n values: CustomFieldValues\n) {\n const errors: Record<string, string> = {};\n for (const field of fields) {\n if (!field.required) {\n continue;\n }\n const message = `${field.label} is required.`;\n const value = values[field.id];\n if (field.type === \"checkbox\") {\n if (value !== true) {\n errors[field.id] = message;\n }\n continue;\n }\n const result =\n field.type === \"checkboxes\" || field.type === \"multi_select\"\n ? safeParse(pipe(array(string()), minLength(1, message)), value ?? [])\n : safeParse(\n pipe(string(), trim(), nonEmpty(message)),\n getStringValue(value)\n );\n if (!result.success) {\n errors[field.id] = result.issues[0]?.message ?? message;\n }\n }\n return errors;\n}\n\nexport function CustomFields({\n choiceClassName,\n errorClassName,\n errors,\n fields,\n idPrefix,\n onChange,\n values,\n}: {\n choiceClassName: string;\n errorClassName: string;\n errors: Record<string, string>;\n fields: LockerverseCustomField[];\n idPrefix: string;\n onChange: (values: CustomFieldValues) => void;\n values: CustomFieldValues;\n}) {\n return fields.map((field) => (\n <CustomField\n choiceClassName={choiceClassName}\n error={errors[field.id]}\n errorClassName={errorClassName}\n field={field}\n idPrefix={idPrefix}\n key={field.id}\n onChange={(value) => onChange({ ...values, [field.id]: value })}\n value={values[field.id]}\n />\n ));\n}\n\ntype CustomFieldProps = {\n choiceClassName: string;\n error: string | undefined;\n errorClassName: string;\n field: LockerverseCustomField;\n idPrefix: string;\n onChange: (value: boolean | string | string[]) => void;\n value: boolean | string | string[] | undefined;\n};\n\nfunction CustomField(props: CustomFieldProps) {\n const { field, idPrefix } = props;\n const controlId = `${idPrefix}-custom-${field.id}`;\n const errorId = `${controlId}-error`;\n const controlProps = { ...props, controlId, errorId };\n switch (field.type) {\n case \"checkbox\":\n return <BooleanCustomField {...controlProps} field={field} />;\n case \"text\":\n case \"textarea\":\n return <TextCustomField {...controlProps} field={field} />;\n case \"select\":\n case \"multi_select\":\n return <SelectCustomField {...controlProps} field={field} />;\n case \"radio\":\n case \"checkboxes\":\n return <ChoiceCustomField {...controlProps} field={field} />;\n default:\n return null;\n }\n}\n\nfunction BooleanCustomField({\n choiceClassName,\n controlId,\n error,\n errorClassName,\n errorId,\n field,\n onChange,\n value,\n}: ControlProps & { field: LockerverseBooleanCustomField }) {\n return (\n <label className={choiceClassName} htmlFor={controlId}>\n <input\n aria-describedby={error ? errorId : undefined}\n aria-invalid={error ? \"true\" : undefined}\n checked={value === true}\n id={controlId}\n name={`custom:${field.id}`}\n onChange={(event) => onChange(event.currentTarget.checked)}\n required={field.required}\n type=\"checkbox\"\n />\n <span>{field.label}</span>\n <FieldError className={errorClassName} error={error} id={errorId} />\n </label>\n );\n}\n\ntype ControlProps = CustomFieldProps & {\n controlId: string;\n errorId: string;\n};\n\nfunction FieldError({\n className,\n error,\n id,\n}: {\n className: string;\n error: string | undefined;\n id: string;\n}) {\n return error ? (\n <span className={className} id={id} role=\"alert\">\n {error}\n </span>\n ) : null;\n}\n\nfunction TextCustomField({\n controlId,\n error,\n errorClassName,\n errorId,\n field,\n onChange,\n value,\n}: ControlProps & {\n field: Extract<LockerverseCustomField, { type: \"text\" | \"textarea\" }>;\n}) {\n const commonProps = {\n \"aria-describedby\": error ? errorId : undefined,\n \"aria-invalid\": error ? (\"true\" as const) : undefined,\n id: controlId,\n name: `custom:${field.id}`,\n onChange: (\n event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>\n ) => onChange(event.currentTarget.value),\n required: field.required,\n value: getStringValue(value),\n };\n return (\n <label htmlFor={controlId}>\n <span>{field.label}</span>\n {field.type === \"textarea\" ? (\n <textarea {...commonProps} />\n ) : (\n <input {...commonProps} />\n )}\n <FieldError className={errorClassName} error={error} id={errorId} />\n </label>\n );\n}\n\nfunction SelectCustomField({\n controlId,\n error,\n errorClassName,\n errorId,\n field,\n onChange,\n value,\n}: ControlProps & {\n field: LockerverseMultiOptionCustomField | LockerverseSingleOptionCustomField;\n}) {\n return (\n <label htmlFor={controlId}>\n <span>{field.label}</span>\n <select\n aria-describedby={error ? errorId : undefined}\n aria-invalid={error ? \"true\" : undefined}\n id={controlId}\n multiple={field.type === \"multi_select\"}\n name={`custom:${field.id}`}\n onChange={(event) =>\n onChange(\n field.type === \"multi_select\"\n ? [...event.currentTarget.selectedOptions].map(\n (option) => option.value\n )\n : event.currentTarget.value\n )\n }\n required={field.required}\n value={\n value === true || value === false\n ? \"\"\n : (value ?? (field.type === \"multi_select\" ? [] : \"\"))\n }\n >\n {field.type === \"select\" ? <option value=\"\">Select…</option> : null}\n {field.options.map((option) => (\n <option key={option.id} value={option.id}>\n {option.label}\n </option>\n ))}\n </select>\n <FieldError className={errorClassName} error={error} id={errorId} />\n </label>\n );\n}\n\nfunction ChoiceCustomField({\n choiceClassName,\n controlId,\n error,\n errorClassName,\n errorId,\n field,\n onChange,\n value,\n}: ControlProps & {\n field: LockerverseMultiOptionCustomField | LockerverseSingleOptionCustomField;\n}) {\n const selectedValues = Array.isArray(value) ? value : [];\n return (\n <fieldset\n aria-describedby={error ? errorId : undefined}\n aria-invalid={error ? \"true\" : undefined}\n >\n <legend>{field.label}</legend>\n {field.options.map((option, index) => (\n <label className={choiceClassName} key={option.id}>\n <input\n checked={\n Array.isArray(value)\n ? value.includes(option.id)\n : value === option.id\n }\n id={`${controlId}-${index}`}\n name={`custom:${field.id}`}\n onChange={(event) => {\n if (field.type === \"radio\") {\n onChange(option.id);\n return;\n }\n onChange(\n event.currentTarget.checked\n ? [...selectedValues, option.id]\n : selectedValues.filter((id) => id !== option.id)\n );\n }}\n required={field.required && field.type === \"radio\"}\n type={field.type === \"radio\" ? \"radio\" : \"checkbox\"}\n value={option.id}\n />\n <span>{option.label}</span>\n </label>\n ))}\n <FieldError className={errorClassName} error={error} id={errorId} />\n </fieldset>\n );\n}\n","export function FormSkeleton({\n fieldCount,\n label,\n sectionCount = 0,\n showCheckbox = false,\n}: {\n fieldCount: number;\n label: string;\n sectionCount?: number;\n showCheckbox?: boolean;\n}) {\n return (\n <div className=\"lockerverse-form-skeleton__loading\">\n <span className=\"lockerverse-form-skeleton__sr-only\" role=\"status\">\n {label}\n </span>\n <div aria-hidden=\"true\" className=\"lockerverse-form-skeleton\">\n <div className=\"lockerverse-form-skeleton__branding\">\n <span className=\"lockerverse-form-skeleton__avatar\" />\n <span className=\"lockerverse-form-skeleton__community\" />\n </div>\n <div className=\"lockerverse-form-skeleton__fields\">\n {Array.from({ length: fieldCount }, (_, index) => (\n <div className=\"lockerverse-form-skeleton__field\" key={index}>\n <span className=\"lockerverse-form-skeleton__label\" />\n <span className=\"lockerverse-form-skeleton__input\" />\n </div>\n ))}\n </div>\n {Array.from({ length: sectionCount }, (_, index) => (\n <div className=\"lockerverse-form-skeleton__section\" key={index}>\n <span className=\"lockerverse-form-skeleton__section-label\" />\n <div className=\"lockerverse-form-skeleton__section-content\">\n <span className=\"lockerverse-form-skeleton__section-full\" />\n <div className=\"lockerverse-form-skeleton__section-grid\">\n <span className=\"lockerverse-form-skeleton__section-half\" />\n <span className=\"lockerverse-form-skeleton__section-half\" />\n </div>\n </div>\n </div>\n ))}\n <div className=\"lockerverse-form-skeleton__actions\">\n {showCheckbox ? (\n <span className=\"lockerverse-form-skeleton__check-line\" />\n ) : null}\n <span className=\"lockerverse-form-skeleton__button\" />\n </div>\n </div>\n </div>\n );\n}\n","import { email, nonEmpty, pipe, regex, string, transform, trim } from \"valibot\";\n\nexport const EMAIL_REQUIRED_MESSAGE = \"Email is required.\";\nexport const EMAIL_INVALID_MESSAGE = \"Enter a valid email address.\";\nexport const PHONE_REQUIRED_MESSAGE = \"Phone is required.\";\nexport const PHONE_INVALID_MESSAGE = \"Enter a valid phone number.\";\n\nconst OPTIONAL_EMAIL_PATTERN = /^(?:$|[^\\s@]+@[^\\s@]+\\.[^\\s@]+)$/;\nconst INTERNATIONAL_PHONE_PATTERN = /^\\+[1-9]\\d{6,14}$/;\nconst OPTIONAL_INTERNATIONAL_PHONE_PATTERN = /^(?:$|\\+[1-9]\\d{6,14})$/;\n\nexport function normalizePhone(input: string) {\n return input.trim().replace(/[().\\s-]/g, \"\");\n}\n\nexport const optionalEmailSchema = pipe(\n string(),\n trim(),\n regex(OPTIONAL_EMAIL_PATTERN, EMAIL_INVALID_MESSAGE)\n);\n\nexport const requiredEmailSchema = pipe(\n string(),\n trim(),\n nonEmpty(EMAIL_REQUIRED_MESSAGE),\n email(EMAIL_INVALID_MESSAGE)\n);\n\nexport const optionalPhoneSchema = pipe(\n string(),\n trim(),\n transform(normalizePhone),\n regex(OPTIONAL_INTERNATIONAL_PHONE_PATTERN, PHONE_INVALID_MESSAGE)\n);\n\nexport const requiredPhoneSchema = pipe(\n string(),\n trim(),\n nonEmpty(PHONE_REQUIRED_MESSAGE),\n transform(normalizePhone),\n regex(INTERNATIONAL_PHONE_PATTERN, PHONE_INVALID_MESSAGE)\n);\n","import {\n normalizePhone,\n PHONE_INVALID_MESSAGE,\n PHONE_REQUIRED_MESSAGE,\n} from \"./contact-validation.ts\";\n\nexport const PHONE_COUNTRIES = [\n {\n callingCode: \"+1\",\n label: \"🇺🇸 +1\",\n value: \"US\",\n },\n {\n callingCode: \"+52\",\n label: \"🇲🇽 +52\",\n value: \"MX\",\n },\n {\n callingCode: \"+380\",\n label: \"🇺🇦 +380\",\n value: \"UA\",\n },\n {\n callingCode: \"+48\",\n label: \"🇵🇱 +48\",\n value: \"PL\",\n },\n {\n callingCode: \"+1\",\n label: \"🇨🇦 +1\",\n value: \"CA\",\n },\n {\n callingCode: \"+49\",\n label: \"🇩🇪 +49\",\n value: \"DE\",\n },\n {\n callingCode: \"+44\",\n label: \"🇬🇧 +44\",\n value: \"GB\",\n },\n {\n callingCode: \"+46\",\n label: \"🇸🇪 +46\",\n value: \"SE\",\n },\n {\n callingCode: \"+358\",\n label: \"🇫🇮 +358\",\n value: \"FI\",\n },\n {\n callingCode: \"+1\",\n label: \"🇵🇷 +1\",\n value: \"PR\",\n },\n] as const;\n\nexport type PhoneCountry = (typeof PHONE_COUNTRIES)[number][\"value\"];\n\nexport function getPhoneServerError(serverCode: string | undefined) {\n if (\n serverCode === \"PAYMENT_WIDGET_PHONE_REQUIRED\" ||\n serverCode === \"SIGN_UP_WIDGET_PHONE_REQUIRED\"\n ) {\n return PHONE_REQUIRED_MESSAGE;\n }\n if (\n serverCode === \"PAYMENT_WIDGET_PHONE_INVALID\" ||\n serverCode === \"SIGN_UP_WIDGET_PHONE_INVALID\"\n ) {\n return PHONE_INVALID_MESSAGE;\n }\n}\n\nfunction getPhoneCountry(country: string) {\n return (\n PHONE_COUNTRIES.find((option) => option.value === country) ??\n PHONE_COUNTRIES[0]\n );\n}\n\nfunction removeRepeatedCallingCode(phone: string, callingCode: string) {\n const repeatedCallingCode = `${callingCode}${callingCode}`;\n let normalizedPhone = phone;\n while (normalizedPhone.startsWith(repeatedCallingCode)) {\n normalizedPhone = `${callingCode}${normalizedPhone.slice(repeatedCallingCode.length)}`;\n }\n return normalizedPhone;\n}\n\nexport function getInternationalPhone(phone: string, country: string) {\n const normalizedPhone = normalizePhone(phone);\n if (!normalizedPhone) {\n return \"\";\n }\n\n const selectedCountry = getPhoneCountry(country);\n const phoneWithOneCallingCode = removeRepeatedCallingCode(\n normalizedPhone,\n selectedCountry.callingCode\n );\n\n return phoneWithOneCallingCode.startsWith(\"+\")\n ? phoneWithOneCallingCode\n : `${selectedCountry.callingCode}${phoneWithOneCallingCode}`;\n}\n","export function notifyHostCallback<Value>(\n callback: ((value: Value) => void) | undefined,\n value: Value\n) {\n if (!callback) {\n return;\n }\n try {\n Promise.resolve(callback(value)).catch(() => undefined);\n } catch {\n // Host callback failures must not change completed SDK state.\n }\n}\n"],"mappings":"mMAAA,MAAM,EAAY,8BACZ,EAAuB,6BAE7B,SAAgB,EAAqB,EAAe,CAClD,IAAM,EAAe,EAAM,KAAK,EAChC,OAAO,EAAqB,KAAK,CAAY,EACzC,IAAI,IACJ,CACN,CAEA,SAAS,EAAc,EAAe,CACpC,IAAM,EAAQ,EAAU,KAAK,EAAqB,CAAK,CAAC,EACxD,GAAI,CAAC,EACH,OAEF,GAAM,EAAG,GAAS,EAClB,GAAI,CAAC,EACH,OAEF,IAAM,EACJ,EAAM,SAAW,EACb,MAAM,KAAK,EAAQ,GAAc,GAAG,IAAY,GAAW,CAAC,CAAC,KAAK,EAAE,EACpE,EACN,MAAO,CAAC,EAAG,EAAG,CAAC,CAAC,CAAC,IAAK,GACpB,OAAO,SAAS,EAAS,MAAM,EAAQ,EAAS,CAAC,EAAG,EAAE,CACxD,CACF,CAEA,SAAS,EAAkB,CAAC,EAAK,EAAO,GAAiB,CACvD,GAAM,CAAC,EAAY,EAAG,EAAc,EAAG,EAAa,GAAK,CACvD,EACA,EACA,CACF,CAAC,CAAC,KAAK,EAAU,IAAM,CACrB,IAAM,EAAa,EAAU,IAC7B,OAAO,GAAc,OACjB,EAAa,QACX,EAA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b,MAAO,UACP,MAAO,IACT,CACF,EAIA,SAAgB,EAAoB,EAAgC,CAClE,GACE,IAAe,iCACf,IAAe,gCAEf,OAAO,EAET,GACE,IAAe,gCACf,IAAe,+BAEf,OAAO,CAEX,CAEA,SAAS,EAAgB,EAAiB,CACxC,OACE,EAAgB,KAAM,GAAW,EAAO,QAAU,CAAO,GACzD,EAAgB,EAEpB,CAEA,SAAS,EAA0B,EAAe,EAAqB,CACrE,IAAM,EAAsB,GAAG,IAAc,IACzC,EAAkB,EACtB,KAAO,EAAgB,WAAW,CAAmB,GACnD,EAAkB,GAAG,IAAc,EAAgB,MAAM,EAAoB,MAAM,IAErF,OAAO,CACT,CAEA,SAAgB,EAAsB,EAAe,EAAiB,CACpE,IAAM,EAAkB,EAAe,CAAK,EAC5C,GAAI,CAAC,EACH,MAAO,GAGT,IAAM,EAAkB,EAAgB,CAAO,EACzC,EAA0B,EAC9B,EACA,EAAgB,WAClB,EAEA,OAAO,EAAwB,WAAW,GAAG,EACzC,EACA,GAAG,EAAgB,cAAc,GACvC,CC3GA,SAAgB,EACd,EACA,EACA,CACK,KAGL,GAAI,CACF,QAAQ,QAAQ,EAAS,CAAK,CAAC,CAAC,CAAC,UAAY,IAAA,EAAS,CACxD,MAAQ,CAER,CACF"}
1
+ {"version":3,"file":"host-callback.js","names":[],"sources":["../src/contact-validation.ts","../src/host-callback.ts"],"sourcesContent":["import { email, nonEmpty, pipe, regex, string, transform, trim } from \"valibot\";\n\nexport const EMAIL_REQUIRED_MESSAGE = \"Email is required.\";\nexport const EMAIL_INVALID_MESSAGE = \"Enter a valid email address.\";\nexport const PHONE_REQUIRED_MESSAGE = \"Phone is required.\";\nexport const PHONE_INVALID_MESSAGE = \"Enter a valid phone number.\";\n\nconst OPTIONAL_EMAIL_PATTERN = /^(?:$|[^\\s@]+@[^\\s@]+\\.[^\\s@]+)$/;\nconst INTERNATIONAL_PHONE_PATTERN = /^\\+[1-9]\\d{6,14}$/;\nconst OPTIONAL_INTERNATIONAL_PHONE_PATTERN = /^(?:$|\\+[1-9]\\d{6,14})$/;\n\nexport function normalizePhone(input: string) {\n return input.trim().replace(/[().\\s-]/g, \"\");\n}\n\nexport const optionalEmailSchema = pipe(\n string(),\n trim(),\n regex(OPTIONAL_EMAIL_PATTERN, EMAIL_INVALID_MESSAGE)\n);\n\nexport const requiredEmailSchema = pipe(\n string(),\n trim(),\n nonEmpty(EMAIL_REQUIRED_MESSAGE),\n email(EMAIL_INVALID_MESSAGE)\n);\n\nexport const optionalPhoneSchema = pipe(\n string(),\n trim(),\n transform(normalizePhone),\n regex(OPTIONAL_INTERNATIONAL_PHONE_PATTERN, PHONE_INVALID_MESSAGE)\n);\n\nexport const requiredPhoneSchema = pipe(\n string(),\n trim(),\n nonEmpty(PHONE_REQUIRED_MESSAGE),\n transform(normalizePhone),\n regex(INTERNATIONAL_PHONE_PATTERN, PHONE_INVALID_MESSAGE)\n);\n","export function notifyHostCallback<Value>(\n callback: ((value: Value) => void) | undefined,\n value: Value\n) {\n if (!callback) {\n return;\n }\n try {\n Promise.resolve(callback(value)).catch(() => undefined);\n } catch {\n // Host callback failures must not change completed SDK state.\n }\n}\n"],"mappings":"wGAEA,MACa,EAAwB,+BACxB,EAAyB,qBACzB,EAAwB,8BAE/B,EAAyB,mCACzB,EAA8B,oBAC9B,EAAuC,0BAE7C,SAAgB,EAAe,EAAe,CAC5C,OAAO,EAAM,KAAK,CAAC,CAAC,QAAQ,YAAa,EAAE,CAC7C,CAEA,MAAa,EAAsB,EACjC,EAAO,EACP,EAAK,EACL,EAAM,EAAwB,CAAqB,CACrD,EAEa,EAAsB,EACjC,EAAO,EACP,EAAK,EACL,EAAS,oBAAsB,EAC/B,EAAM,CAAqB,CAC7B,EAEa,EAAsB,EACjC,EAAO,EACP,EAAK,EACL,EAAU,CAAc,EACxB,EAAM,EAAsC,CAAqB,CACnE,EAEa,EAAsB,EACjC,EAAO,EACP,EAAK,EACL,EAAS,CAAsB,EAC/B,EAAU,CAAc,EACxB,EAAM,EAA6B,CAAqB,CAC1D,ECzCA,SAAgB,EACd,EACA,EACA,CACK,KAGL,GAAI,CACF,QAAQ,QAAQ,EAAS,CAAK,CAAC,CAAC,CAAC,UAAY,IAAA,EAAS,CACxD,MAAQ,CAER,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"immutable-resource-identity.js","names":[],"sources":["../src/immutable-resource-identity.ts"],"sourcesContent":["import { useRef } from \"react\";\n\ntype LockerverseResourceIdentity = {\n apiBaseUrl: string | undefined;\n communitySlug: string;\n environment: string | undefined;\n slug: string;\n};\n\nfunction hasSameIdentity(\n initial: LockerverseResourceIdentity,\n current: LockerverseResourceIdentity\n) {\n return (\n initial.apiBaseUrl === current.apiBaseUrl &&\n initial.communitySlug === current.communitySlug &&\n initial.environment === current.environment &&\n initial.slug === current.slug\n );\n}\n\nexport function useImmutableResourceIdentity(\n resource: \"payment widget\" | \"signup\",\n identity: LockerverseResourceIdentity\n) {\n const initial = useRef(identity);\n if (!hasSameIdentity(initial.current, identity)) {\n throw new TypeError(\n `Lockerverse ${resource} identity cannot change after initialization. Remount with a new React key.`\n );\n }\n}\n"],"mappings":"+BASA,SAAS,EACP,EACA,EACA,CACA,OACE,EAAQ,aAAe,EAAQ,YAC/B,EAAQ,gBAAkB,EAAQ,eAClC,EAAQ,cAAgB,EAAQ,aAChC,EAAQ,OAAS,EAAQ,IAE7B,CAEA,SAAgB,EACd,EACA,EACA,CAEA,GAAI,CAAC,EADW,EAAO,CACI,CAAC,CAAC,QAAS,CAAQ,EAC5C,MAAU,UACR,eAAe,EAAS,4EAC1B,CAEJ"}
1
+ {"version":3,"file":"immutable-resource-identity.js","names":[],"sources":["../src/immutable-resource-identity.ts"],"sourcesContent":["import { useRef } from \"react\";\n\ntype LockerverseResourceIdentity = {\n apiBaseUrl: string | undefined;\n communitySlug: string;\n environment: string | undefined;\n slug: string;\n};\n\nfunction hasSameIdentity(\n initial: LockerverseResourceIdentity,\n current: LockerverseResourceIdentity\n) {\n return (\n initial.apiBaseUrl === current.apiBaseUrl &&\n initial.communitySlug === current.communitySlug &&\n initial.environment === current.environment &&\n initial.slug === current.slug\n );\n}\n\nexport function useImmutableResourceIdentity(\n resource: \"payment widget\" | \"signup\" | \"auctions\",\n identity: LockerverseResourceIdentity\n) {\n const initial = useRef(identity);\n if (!hasSameIdentity(initial.current, identity)) {\n throw new TypeError(\n `Lockerverse ${resource} identity cannot change after initialization. Remount with a new React key.`\n );\n }\n}\n"],"mappings":"+BASA,SAAS,EACP,EACA,EACA,CACA,OACE,EAAQ,aAAe,EAAQ,YAC/B,EAAQ,gBAAkB,EAAQ,eAClC,EAAQ,cAAgB,EAAQ,aAChC,EAAQ,OAAS,EAAQ,IAE7B,CAEA,SAAgB,EACd,EACA,EACA,CAEA,GAAI,CAAC,EADW,EAAO,CACI,CAAC,CAAC,QAAS,CAAQ,EAC5C,MAAU,UACR,eAAe,EAAS,4EAC1B,CAEJ"}
@@ -1,2 +1,2 @@
1
- import{g as e,h as t}from"./host-callback.js";import{n,t as r}from"./lockerverse-payment.js";import{Dialog as i}from"@base-ui/react/dialog";import{getLockerverseMinimumCustomAmountCents as a}from"@lockerverse/sdk/checkout";import{createElement as o,useState as s}from"react";import{Fragment as c,jsx as l,jsxs as u}from"react/jsx-runtime";const d=new Intl.NumberFormat(`en-US`,{currency:`USD`,style:`currency`}),f=/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,p=[1e3,2500,5e3,1e4];function m(e){if(!f.test(e))return null;let t=Math.round(Number(e)*100);return Number.isSafeInteger(t)&&t>0?t:null}function h(e,t){let n=``;return t===`monthly`&&(n=`/month`),t===`annually`&&(n=`/year`),`${d.format(e/100)}${n}`}function g({customAmounts:e,product:t,quantities:n,recurringProductId:r,setCustomAmounts:i,setQuantities:o,setRecurringProductId:s}){let c=n[t.id]??0;if(t.pricingMode===`fixed`&&t.paymentOption===`one-time`){let e=t.minimumQuantity??1,n=Math.min(t.maximumQuantity??1/0,t.inventoryQuantity??1/0);return u(`span`,{className:`lockerverse-launcher__quantity`,children:[l(`button`,{"aria-label":`Decrease ${t.name} quantity`,disabled:c===0,onClick:()=>{s(null),o(n=>{let r=n[t.id]??0;return{...n,[t.id]:r<=e?0:r-1}})},type:`button`,children:`−`}),l(`output`,{"aria-label":`${t.name} quantity`,children:c}),l(`button`,{"aria-label":`Increase ${t.name} quantity`,disabled:n<e||c>=n,onClick:()=>{s(null),o(n=>{let r=n[t.id]??0;return{...n,[t.id]:r===0?e:r+1}})},type:`button`,children:`+`})]})}return t.pricingMode===`custom`&&t.paymentOption===`one-time`?u(`span`,{className:`lockerverse-launcher__custom-amount`,children:[l(`span`,{"aria-hidden":`true`,children:`$`}),l(`input`,{"aria-label":`${t.name} amount`,min:a(t)/100,name:`amount-${t.slug}`,onChange:e=>{s(null),i(n=>({...n,[t.id]:e.target.value}))},placeholder:`0.00`,step:`0.01`,type:`number`,value:e[t.id]??``}),t.minimumAmountCents===null?null:u(`small`,{children:[`Minimum `,d.format(t.minimumAmountCents/100)]})]}):l(`button`,{"aria-label":`Select ${t.name}`,"aria-pressed":r===t.id,className:`lockerverse-launcher__select`,onClick:()=>{o({}),i({}),s(e=>e===t.id?null:t.id)},type:`button`,children:`Select`})}function _({variant:e=`default`,...t}){let{customAmounts:n,product:r,quantities:i,recurringProductId:o}=t,s=m(n[r.id]??``),c=o===r.id||r.paymentOption===`one-time`&&(r.pricingMode===`fixed`&&(i[r.id]??0)>0||r.pricingMode===`custom`&&s!==null&&s>=a(r));return u(`article`,{className:`lockerverse-launcher__product lockerverse-launcher__product--${e}`,"data-selected":c||void 0,children:[u(`span`,{className:`lockerverse-launcher__product-copy`,children:[l(`strong`,{className:`lockerverse-launcher__product-name`,children:r.name}),r.description?l(`small`,{children:r.description}):null,r.amountCents===null?null:l(`span`,{className:`lockerverse-launcher__product-price`,children:h(r.amountCents,r.paymentOption)})]}),l(g,{...t})]})}function v({customAmounts:e,product:t,setCustomAmounts:n,setRecurringProductId:r}){let i=e[t.id]??``,o=m(i),s=p.filter(e=>e>=a(t)),c=s.includes(o??0),f=e=>{r(null),n(n=>({...n,[t.id]:e}))};return l(`div`,{className:`lockerverse-launcher__donation-option`,children:u(`fieldset`,{className:`lockerverse-launcher__donation-choices`,children:[u(`legend`,{className:`lockerverse-launcher__sr-only`,children:[t.name,` amount`]}),l(`button`,{"aria-pressed":i===``,onClick:()=>f(``),type:`button`,children:`No thanks`}),s.map(e=>l(`button`,{"aria-pressed":o===e,onClick:()=>f(String(e/100)),type:`button`,children:d.format(e/100).replace(`.00`,``)},e)),l(`label`,{className:`lockerverse-launcher__donation-other`,"data-selected":i!==``&&!c||void 0,children:l(`input`,{"aria-label":`${t.name} amount`,min:a(t)/100,name:`amount-${t.slug}`,onChange:e=>f(e.target.value),placeholder:`Other $`,step:`0.01`,type:`number`,value:c?``:i})})]})})}function y({products:e,variant:t=`default`,...n}){return l(`div`,{className:`lockerverse-launcher__product-list`,children:e.map(e=>t===`donation`?o(v,{...n,key:e.id,product:e}):o(_,{...n,key:e.id,product:e,variant:t}))})}function b(e,t){let n=0,r=0;for(let i of t){let t=e.products.find(e=>e.slug===i.productSlug);if(t){if(`quantity`in i){n+=i.quantity,r+=(t.amountCents??0)*i.quantity;continue}n+=1,r+=`amountCents`in i?i.amountCents:t.amountCents??0}}return{amountCents:r,itemCount:n}}function x(){return l(`div`,{"aria-label":`Loading donation options`,className:`lockerverse-launcher__loading`,role:`status`,children:[0,1,2].map(e=>l(`span`,{"aria-hidden":`true`,className:`lockerverse-launcher__loading-row`},e))})}function S(e,t,n,r){if(r){let t=e.products.find(e=>e.id===r&&e.paymentOption!==`one-time`);return t?[{productSlug:t.slug}]:[]}return e.products.flatMap(e=>{let r=t[e.id]??0;if(e.pricingMode===`fixed`&&e.paymentOption===`one-time`&&r>0)return[{productSlug:e.slug,quantity:r}];let i=m(n[e.id]??``);return e.pricingMode===`custom`&&e.paymentOption===`one-time`&&i!==null&&i>=a(e)?[{amountCents:i,productSlug:e.slug}]:[]})}function C({catalog:e,onContinue:t,...n}){let r=S(e,n.quantities,n.customAmounts,n.recurringProductId),i=b(e,r),a=e.products.filter(e=>e.paymentOption===`one-time`&&e.pricingMode===`custom`),o=e.products.filter(e=>!a.includes(e));return u(`form`,{className:`lockerverse-launcher__products`,onSubmit:e=>{e.preventDefault(),r.length>0&&t(r)},children:[o.length>0?l(`section`,{className:`lockerverse-launcher__section`,children:l(y,{...n,products:o})}):null,a.length>0?u(`section`,{className:`lockerverse-launcher__donation`,children:[u(`header`,{className:`lockerverse-launcher__section-header`,children:[l(`h3`,{children:`Add a donation`}),l(`p`,{children:`Choose an amount to add to this order.`})]}),l(y,{...n,products:a,variant:`donation`})]}):null,e.products.length>0?u(`footer`,{className:`lockerverse-launcher__footer`,children:[u(`p`,{"aria-live":`polite`,className:`lockerverse-launcher__summary`,children:[l(`span`,{children:i.itemCount===0?`No items selected`:`${i.itemCount} ${i.itemCount===1?`item`:`items`} selected`}),i.itemCount===0?null:l(`strong`,{children:d.format(i.amountCents/100)})]}),l(`button`,{className:`lockerverse-launcher__continue`,disabled:r.length===0,type:`submit`,children:`Continue`})]}):null]})}function w({onEdit:e,paymentProps:t,selection:n,style:i,widget:a}){return u(`div`,{className:`lockerverse-launcher__checkout`,children:[l(`header`,{className:`lockerverse-launcher__checkout-toolbar`,children:l(`button`,{className:`lockerverse-launcher__back`,onClick:e,type:`button`,children:`Edit order`})}),l(r,{...t,selection:n,style:i,widget:a})]})}function T({catalog:e,checkout:t}){return t?u(c,{children:[l(i.Title,{className:`lockerverse-launcher__sr-only`,children:`Checkout`}),l(i.Description,{className:`lockerverse-launcher__sr-only`,children:`Review the order and complete payment.`})]}):e?u(`header`,{className:`lockerverse-launcher__header`,children:[e.community?u(`div`,{className:`lockerverse-launcher__brand`,children:[e.community.imageUrl?l(`img`,{alt:`${e.community.name} logo`,height:`28`,src:e.community.imageUrl,width:`28`}):null,l(`span`,{children:e.community.name})]}):null,l(i.Title,{className:`lockerverse-launcher__title`,children:e.widget.title??e.widget.name}),l(i.Description,{className:`lockerverse-launcher__description`,children:e.widget.description??`Choose your options, then continue to checkout.`})]}):u(`header`,{className:`lockerverse-launcher__header`,children:[l(i.Title,{className:`lockerverse-launcher__title`,children:`Donate`}),l(i.Description,{className:`lockerverse-launcher__description`,children:`Choose your options, then continue to checkout.`})]})}function E({buttonLabel:r=`Donate`,position:a=`inline`,widget:o,...c}){let[d,f]=s(null),[p,m]=s({}),[h,g]=s({}),[_,v]=s(null),{catalog:y,error:b,loading:S}=o,E=e(c.style?.[`--lockerverse-accent`]??y?.community?.accentColor??`#38d77a`),D=t(E),O={...c.style};(c.style?.[`--lockerverse-accent`]!==void 0||y?.community?.accentColor)&&(O[`--lockerverse-accent`]=E),D&&c.style?.[`--lockerverse-accent-contrast`]===void 0&&(O[`--lockerverse-accent-contrast`]=D);let k;return k=S?l(x,{}):b?u(`div`,{role:`alert`,children:[l(`p`,{children:`Unable to load donation options.`}),l(`button`,{onClick:o.refresh,type:`button`,children:`Retry`})]}):y?l(C,{catalog:y,customAmounts:p,onContinue:f,quantities:h,recurringProductId:_,setCustomAmounts:m,setQuantities:g,setRecurringProductId:v}):l(x,{}),!(S||b)&&d&&y&&(k=l(w,{onEdit:()=>f(null),paymentProps:c,selection:d,style:O,widget:o})),u(i.Root,{onOpenChange:e=>{e&&y&&c.stripeLoader===void 0&&requestAnimationFrame(()=>{n(y)})},children:[l(i.Trigger,{className:`lockerverse-launcher lockerverse-launcher--${a}`,"data-lockerverse-theme":c.theme??`dark`,style:O,children:r}),u(i.Portal,{children:[l(i.Backdrop,{className:`lockerverse-launcher__backdrop`}),l(i.Viewport,{className:`lockerverse-launcher__viewport`,children:u(i.Popup,{className:`lockerverse-launcher__dialog`,"data-lockerverse-theme":c.theme??`dark`,style:O,children:[l(T,{catalog:y,checkout:d!==null}),l(i.Close,{"aria-label":`Close donation dialog`,className:`lockerverse-launcher__close`,children:l(`span`,{"aria-hidden":`true`,children:`×`})}),k]})})]})]})}export{E as t};
1
+ import{l as e,u as t}from"./phone.js";import{n,t as r}from"./lockerverse-payment.js";import{createElement as i,useState as a}from"react";import{Fragment as o,jsx as s,jsxs as c}from"react/jsx-runtime";import{Dialog as l}from"@base-ui/react/dialog";import{getLockerverseMinimumCustomAmountCents as u}from"@lockerverse/sdk/checkout";const d=new Intl.NumberFormat(`en-US`,{currency:`USD`,style:`currency`}),f=/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,p=[1e3,2500,5e3,1e4];function m(e){if(!f.test(e))return null;let t=Math.round(Number(e)*100);return Number.isSafeInteger(t)&&t>0?t:null}function h(e,t){let n=``;return t===`monthly`&&(n=`/month`),t===`annually`&&(n=`/year`),`${d.format(e/100)}${n}`}function g({customAmounts:e,product:t,quantities:n,recurringProductId:r,setCustomAmounts:i,setQuantities:a,setRecurringProductId:o}){let l=n[t.id]??0;if(t.pricingMode===`fixed`&&t.paymentOption===`one-time`){let e=t.minimumQuantity??1,n=Math.min(t.maximumQuantity??1/0,t.inventoryQuantity??1/0);return c(`span`,{className:`lockerverse-launcher__quantity`,children:[s(`button`,{"aria-label":`Decrease ${t.name} quantity`,disabled:l===0,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r<=e?0:r-1}})},type:`button`,children:`−`}),s(`output`,{"aria-label":`${t.name} quantity`,children:l}),s(`button`,{"aria-label":`Increase ${t.name} quantity`,disabled:n<e||l>=n,onClick:()=>{o(null),a(n=>{let r=n[t.id]??0;return{...n,[t.id]:r===0?e:r+1}})},type:`button`,children:`+`})]})}return t.pricingMode===`custom`&&t.paymentOption===`one-time`?c(`span`,{className:`lockerverse-launcher__custom-amount`,children:[s(`span`,{"aria-hidden":`true`,children:`$`}),s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>{o(null),i(n=>({...n,[t.id]:e.target.value}))},placeholder:`0.00`,step:`0.01`,type:`number`,value:e[t.id]??``}),t.minimumAmountCents===null?null:c(`small`,{children:[`Minimum `,d.format(t.minimumAmountCents/100)]})]}):s(`button`,{"aria-label":`Select ${t.name}`,"aria-pressed":r===t.id,className:`lockerverse-launcher__select`,onClick:()=>{a({}),i({}),o(e=>e===t.id?null:t.id)},type:`button`,children:`Select`})}function _({variant:e=`default`,...t}){let{customAmounts:n,product:r,quantities:i,recurringProductId:a}=t,o=m(n[r.id]??``),l=a===r.id||r.paymentOption===`one-time`&&(r.pricingMode===`fixed`&&(i[r.id]??0)>0||r.pricingMode===`custom`&&o!==null&&o>=u(r));return c(`article`,{className:`lockerverse-launcher__product lockerverse-launcher__product--${e}`,"data-selected":l||void 0,children:[c(`span`,{className:`lockerverse-launcher__product-copy`,children:[s(`strong`,{className:`lockerverse-launcher__product-name`,children:r.name}),r.description?s(`small`,{children:r.description}):null,r.amountCents===null?null:s(`span`,{className:`lockerverse-launcher__product-price`,children:h(r.amountCents,r.paymentOption)})]}),s(g,{...t})]})}function v({customAmounts:e,product:t,setCustomAmounts:n,setRecurringProductId:r}){let i=e[t.id]??``,a=m(i),o=p.filter(e=>e>=u(t)),l=o.includes(a??0),f=e=>{r(null),n(n=>({...n,[t.id]:e}))};return s(`div`,{className:`lockerverse-launcher__donation-option`,children:c(`fieldset`,{className:`lockerverse-launcher__donation-choices`,children:[c(`legend`,{className:`lockerverse-launcher__sr-only`,children:[t.name,` amount`]}),s(`button`,{"aria-pressed":i===``,onClick:()=>f(``),type:`button`,children:`No thanks`}),o.map(e=>s(`button`,{"aria-pressed":a===e,onClick:()=>f(String(e/100)),type:`button`,children:d.format(e/100).replace(`.00`,``)},e)),s(`label`,{className:`lockerverse-launcher__donation-other`,"data-selected":i!==``&&!l||void 0,children:s(`input`,{"aria-label":`${t.name} amount`,min:u(t)/100,name:`amount-${t.slug}`,onChange:e=>f(e.target.value),placeholder:`Other $`,step:`0.01`,type:`number`,value:l?``:i})})]})})}function y({products:e,variant:t=`default`,...n}){return s(`div`,{className:`lockerverse-launcher__product-list`,children:e.map(e=>t===`donation`?i(v,{...n,key:e.id,product:e}):i(_,{...n,key:e.id,product:e,variant:t}))})}function b(e,t){let n=0,r=0;for(let i of t){let t=e.products.find(e=>e.slug===i.productSlug);if(t){if(`quantity`in i){n+=i.quantity,r+=(t.amountCents??0)*i.quantity;continue}n+=1,r+=`amountCents`in i?i.amountCents:t.amountCents??0}}return{amountCents:r,itemCount:n}}function x(){return s(`div`,{"aria-label":`Loading donation options`,className:`lockerverse-launcher__loading`,role:`status`,children:[0,1,2].map(e=>s(`span`,{"aria-hidden":`true`,className:`lockerverse-launcher__loading-row`},e))})}function S(e,t,n,r){if(r){let t=e.products.find(e=>e.id===r&&e.paymentOption!==`one-time`);return t?[{productSlug:t.slug}]:[]}return e.products.flatMap(e=>{let r=t[e.id]??0;if(e.pricingMode===`fixed`&&e.paymentOption===`one-time`&&r>0)return[{productSlug:e.slug,quantity:r}];let i=m(n[e.id]??``);return e.pricingMode===`custom`&&e.paymentOption===`one-time`&&i!==null&&i>=u(e)?[{amountCents:i,productSlug:e.slug}]:[]})}function C({catalog:e,onContinue:t,...n}){let r=S(e,n.quantities,n.customAmounts,n.recurringProductId),i=b(e,r),a=e.products.filter(e=>e.paymentOption===`one-time`&&e.pricingMode===`custom`),o=e.products.filter(e=>!a.includes(e));return c(`form`,{className:`lockerverse-launcher__products`,onSubmit:e=>{e.preventDefault(),r.length>0&&t(r)},children:[o.length>0?s(`section`,{className:`lockerverse-launcher__section`,children:s(y,{...n,products:o})}):null,a.length>0?c(`section`,{className:`lockerverse-launcher__donation`,children:[c(`header`,{className:`lockerverse-launcher__section-header`,children:[s(`h3`,{children:`Add a donation`}),s(`p`,{children:`Choose an amount to add to this order.`})]}),s(y,{...n,products:a,variant:`donation`})]}):null,e.products.length>0?c(`footer`,{className:`lockerverse-launcher__footer`,children:[c(`p`,{"aria-live":`polite`,className:`lockerverse-launcher__summary`,children:[s(`span`,{children:i.itemCount===0?`No items selected`:`${i.itemCount} ${i.itemCount===1?`item`:`items`} selected`}),i.itemCount===0?null:s(`strong`,{children:d.format(i.amountCents/100)})]}),s(`button`,{className:`lockerverse-launcher__continue`,disabled:r.length===0,type:`submit`,children:`Continue`})]}):null]})}function w({onEdit:e,paymentProps:t,selection:n,style:i,widget:a}){return c(`div`,{className:`lockerverse-launcher__checkout`,children:[s(`header`,{className:`lockerverse-launcher__checkout-toolbar`,children:s(`button`,{className:`lockerverse-launcher__back`,onClick:e,type:`button`,children:`Edit order`})}),s(r,{...t,selection:n,style:i,widget:a})]})}function T({catalog:e,checkout:t}){return t?c(o,{children:[s(l.Title,{className:`lockerverse-launcher__sr-only`,children:`Checkout`}),s(l.Description,{className:`lockerverse-launcher__sr-only`,children:`Review the order and complete payment.`})]}):e?c(`header`,{className:`lockerverse-launcher__header`,children:[e.community?c(`div`,{className:`lockerverse-launcher__brand`,children:[e.community.imageUrl?s(`img`,{alt:`${e.community.name} logo`,height:`28`,src:e.community.imageUrl,width:`28`}):null,s(`span`,{children:e.community.name})]}):null,s(l.Title,{className:`lockerverse-launcher__title`,children:e.widget.title??e.widget.name}),s(l.Description,{className:`lockerverse-launcher__description`,children:e.widget.description??`Choose your options, then continue to checkout.`})]}):c(`header`,{className:`lockerverse-launcher__header`,children:[s(l.Title,{className:`lockerverse-launcher__title`,children:`Donate`}),s(l.Description,{className:`lockerverse-launcher__description`,children:`Choose your options, then continue to checkout.`})]})}function E({buttonLabel:r=`Donate`,position:i=`inline`,widget:o,...u}){let[d,f]=a(null),[p,m]=a({}),[h,g]=a({}),[_,v]=a(null),{catalog:y,error:b,loading:S}=o,E=t(u.style?.[`--lockerverse-accent`]??y?.community?.accentColor??`#38d77a`),D=e(E),O={...u.style};(u.style?.[`--lockerverse-accent`]!==void 0||y?.community?.accentColor)&&(O[`--lockerverse-accent`]=E),D&&u.style?.[`--lockerverse-accent-contrast`]===void 0&&(O[`--lockerverse-accent-contrast`]=D);let k;return k=S?s(x,{}):b?c(`div`,{role:`alert`,children:[s(`p`,{children:`Unable to load donation options.`}),s(`button`,{onClick:o.refresh,type:`button`,children:`Retry`})]}):y?s(C,{catalog:y,customAmounts:p,onContinue:f,quantities:h,recurringProductId:_,setCustomAmounts:m,setQuantities:g,setRecurringProductId:v}):s(x,{}),!(S||b)&&d&&y&&(k=s(w,{onEdit:()=>f(null),paymentProps:u,selection:d,style:O,widget:o})),c(l.Root,{onOpenChange:e=>{e&&y&&u.stripeLoader===void 0&&requestAnimationFrame(()=>{n(y)})},children:[s(l.Trigger,{className:`lockerverse-launcher lockerverse-launcher--${i}`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:r}),c(l.Portal,{children:[s(l.Backdrop,{className:`lockerverse-launcher__backdrop`}),s(l.Viewport,{className:`lockerverse-launcher__viewport`,children:c(l.Popup,{className:`lockerverse-launcher__dialog`,"data-lockerverse-theme":u.theme??`dark`,style:O,children:[s(T,{catalog:y,checkout:d!==null}),s(l.Close,{"aria-label":`Close donation dialog`,className:`lockerverse-launcher__close`,children:s(`span`,{"aria-hidden":`true`,children:`×`})}),k]})})]})]})}export{E as t};
2
2
  //# sourceMappingURL=lockerverse-donate-launcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lockerverse-donate-launcher.js","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"sourcesContent":["import { Dialog } from \"@base-ui/react/dialog\";\nimport {\n getLockerverseMinimumCustomAmountCents,\n type LockerverseCatalog,\n type LockerverseProduct,\n} from \"@lockerverse/sdk/checkout\";\nimport {\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n useState,\n} from \"react\";\nimport { getAccentContrast, normalizeAccentColor } from \"./accent-contrast.ts\";\nimport { LockerversePayment } from \"./lockerverse-payment.tsx\";\nimport { preloadLockerversePayment } from \"./payment-form.tsx\";\nimport type {\n LockerverseDonateLauncherProps,\n LockerversePaymentProps,\n LockerversePaymentSelectionItem,\n LockerversePaymentStyle,\n} from \"./types.ts\";\nimport type { UseLockerverseWidgetResult } from \"./use-lockerverse-widget.ts\";\n\nconst usd = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\nconst decimalAmountPattern = /^(?:0|[1-9]\\d*)(?:\\.\\d{1,2})?$/;\nconst suggestedDonationAmountsCents = [1000, 2500, 5000, 10_000];\n\nfunction parseAmountCents(value: string) {\n if (!decimalAmountPattern.test(value)) {\n return null;\n }\n const amountCents = Math.round(Number(value) * 100);\n return Number.isSafeInteger(amountCents) && amountCents > 0\n ? amountCents\n : null;\n}\n\nfunction formatProductPrice(\n amountCents: number,\n paymentOption: \"one-time\" | \"monthly\" | \"annually\"\n) {\n let cadence = \"\";\n if (paymentOption === \"monthly\") {\n cadence = \"/month\";\n }\n if (paymentOption === \"annually\") {\n cadence = \"/year\";\n }\n return `${usd.format(amountCents / 100)}${cadence}`;\n}\n\ntype LauncherProductControlProps = {\n customAmounts: Record<string, string>;\n product: LockerverseProduct;\n quantities: Record<string, number>;\n recurringProductId: string | null;\n setCustomAmounts: Dispatch<SetStateAction<Record<string, string>>>;\n setQuantities: Dispatch<SetStateAction<Record<string, number>>>;\n setRecurringProductId: Dispatch<SetStateAction<string | null>>;\n};\n\nfunction LauncherProductControl({\n customAmounts,\n product,\n quantities,\n recurringProductId,\n setCustomAmounts,\n setQuantities,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const quantity = quantities[product.id] ?? 0;\n if (product.pricingMode === \"fixed\" && product.paymentOption === \"one-time\") {\n const minimum = product.minimumQuantity ?? 1;\n const maximum = Math.min(\n product.maximumQuantity ?? Number.POSITIVE_INFINITY,\n product.inventoryQuantity ?? Number.POSITIVE_INFINITY\n );\n return (\n <span className=\"lockerverse-launcher__quantity\">\n <button\n aria-label={`Decrease ${product.name} quantity`}\n disabled={quantity === 0}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity <= minimum ? 0 : currentQuantity - 1,\n };\n });\n }}\n type=\"button\"\n >\n −\n </button>\n <output aria-label={`${product.name} quantity`}>{quantity}</output>\n <button\n aria-label={`Increase ${product.name} quantity`}\n disabled={maximum < minimum || quantity >= maximum}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity === 0 ? minimum : currentQuantity + 1,\n };\n });\n }}\n type=\"button\"\n >\n +\n </button>\n </span>\n );\n }\n\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\"\n ) {\n return (\n <span className=\"lockerverse-launcher__custom-amount\">\n <span aria-hidden=\"true\">$</span>\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: event.target.value,\n }));\n }}\n placeholder=\"0.00\"\n step=\"0.01\"\n type=\"number\"\n value={customAmounts[product.id] ?? \"\"}\n />\n {product.minimumAmountCents === null ? null : (\n <small>Minimum {usd.format(product.minimumAmountCents / 100)}</small>\n )}\n </span>\n );\n }\n\n return (\n <button\n aria-label={`Select ${product.name}`}\n aria-pressed={recurringProductId === product.id}\n className=\"lockerverse-launcher__select\"\n onClick={() => {\n setQuantities({});\n setCustomAmounts({});\n setRecurringProductId((current) =>\n current === product.id ? null : product.id\n );\n }}\n type=\"button\"\n >\n Select\n </button>\n );\n}\n\ntype LauncherProductOptionProps = LauncherProductControlProps & {\n variant?: \"default\" | \"donation\";\n};\n\nfunction LauncherProductOption({\n variant = \"default\",\n ...props\n}: LauncherProductOptionProps) {\n const { customAmounts, product, quantities, recurringProductId } = props;\n const customAmount = parseAmountCents(customAmounts[product.id] ?? \"\");\n const isSelected =\n recurringProductId === product.id ||\n (product.paymentOption === \"one-time\" &&\n ((product.pricingMode === \"fixed\" && (quantities[product.id] ?? 0) > 0) ||\n (product.pricingMode === \"custom\" &&\n customAmount !== null &&\n customAmount >= getLockerverseMinimumCustomAmountCents(product))));\n return (\n <article\n className={`lockerverse-launcher__product lockerverse-launcher__product--${variant}`}\n data-selected={isSelected || undefined}\n >\n <span className=\"lockerverse-launcher__product-copy\">\n <strong className=\"lockerverse-launcher__product-name\">\n {product.name}\n </strong>\n {product.description ? <small>{product.description}</small> : null}\n {product.amountCents === null ? null : (\n <span className=\"lockerverse-launcher__product-price\">\n {formatProductPrice(product.amountCents, product.paymentOption)}\n </span>\n )}\n </span>\n <LauncherProductControl {...props} />\n </article>\n );\n}\n\nfunction LauncherDonationOption({\n customAmounts,\n product,\n setCustomAmounts,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const amount = customAmounts[product.id] ?? \"\";\n const amountCents = parseAmountCents(amount);\n const suggestions = suggestedDonationAmountsCents.filter(\n (suggestion) =>\n suggestion >= getLockerverseMinimumCustomAmountCents(product)\n );\n const isSuggestedAmount = suggestions.includes(amountCents ?? 0);\n const setAmount = (value: string) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: value,\n }));\n };\n\n return (\n <div className=\"lockerverse-launcher__donation-option\">\n <fieldset className=\"lockerverse-launcher__donation-choices\">\n <legend className=\"lockerverse-launcher__sr-only\">\n {product.name} amount\n </legend>\n <button\n aria-pressed={amount === \"\"}\n onClick={() => setAmount(\"\")}\n type=\"button\"\n >\n No thanks\n </button>\n {suggestions.map((suggestion) => (\n <button\n aria-pressed={amountCents === suggestion}\n key={suggestion}\n onClick={() => setAmount(String(suggestion / 100))}\n type=\"button\"\n >\n {usd.format(suggestion / 100).replace(\".00\", \"\")}\n </button>\n ))}\n <label\n className=\"lockerverse-launcher__donation-other\"\n data-selected={amount !== \"\" && !isSuggestedAmount ? true : undefined}\n >\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => setAmount(event.target.value)}\n placeholder=\"Other $\"\n step=\"0.01\"\n type=\"number\"\n value={isSuggestedAmount ? \"\" : amount}\n />\n </label>\n </fieldset>\n </div>\n );\n}\n\ntype LauncherProductListProps = Omit<LauncherProductControlProps, \"product\"> & {\n products: LockerverseProduct[];\n variant?: LauncherProductOptionProps[\"variant\"];\n};\n\nfunction LauncherProductList({\n products,\n variant = \"default\",\n ...controlProps\n}: LauncherProductListProps) {\n return (\n <div className=\"lockerverse-launcher__product-list\">\n {products.map((product) =>\n variant === \"donation\" ? (\n <LauncherDonationOption\n {...controlProps}\n key={product.id}\n product={product}\n />\n ) : (\n <LauncherProductOption\n {...controlProps}\n key={product.id}\n product={product}\n variant={variant}\n />\n )\n )}\n </div>\n );\n}\n\nfunction getSelectionSummary(\n catalog: LockerverseCatalog,\n selection: LockerversePaymentSelectionItem[]\n) {\n let itemCount = 0;\n let amountCents = 0;\n for (const item of selection) {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n continue;\n }\n if (\"quantity\" in item) {\n itemCount += item.quantity;\n amountCents += (product.amountCents ?? 0) * item.quantity;\n continue;\n }\n itemCount += 1;\n amountCents +=\n \"amountCents\" in item ? item.amountCents : (product.amountCents ?? 0);\n }\n return { amountCents, itemCount };\n}\n\nfunction LauncherLoading() {\n return (\n <div\n aria-label=\"Loading donation options\"\n className=\"lockerverse-launcher__loading\"\n role=\"status\"\n >\n {[0, 1, 2].map((item) => (\n <span\n aria-hidden=\"true\"\n className=\"lockerverse-launcher__loading-row\"\n key={item}\n />\n ))}\n </div>\n );\n}\n\nfunction createLauncherSelection(\n catalog: LockerverseCatalog,\n quantities: Record<string, number>,\n customAmounts: Record<string, string>,\n recurringProductId: string | null\n): LockerversePaymentSelectionItem[] {\n if (recurringProductId) {\n const product = catalog.products.find(\n (candidate) =>\n candidate.id === recurringProductId &&\n candidate.paymentOption !== \"one-time\"\n );\n return product ? [{ productSlug: product.slug }] : [];\n }\n\n return catalog.products.flatMap(\n (product): LockerversePaymentSelectionItem[] => {\n const quantity = quantities[product.id] ?? 0;\n if (\n product.pricingMode === \"fixed\" &&\n product.paymentOption === \"one-time\" &&\n quantity > 0\n ) {\n return [{ productSlug: product.slug, quantity }];\n }\n const amountCents = parseAmountCents(customAmounts[product.id] ?? \"\");\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\" &&\n amountCents !== null &&\n amountCents >= getLockerverseMinimumCustomAmountCents(product)\n ) {\n return [{ amountCents, productSlug: product.slug }];\n }\n return [];\n }\n );\n}\n\ntype LauncherSelectionStateProps = Omit<LauncherProductControlProps, \"product\">;\n\ntype LauncherCatalogProps = LauncherSelectionStateProps & {\n catalog: LockerverseCatalog;\n onContinue: (selection: LockerversePaymentSelectionItem[]) => void;\n};\n\nfunction LauncherCatalog({\n catalog,\n onContinue,\n ...selectionState\n}: LauncherCatalogProps) {\n const draftSelection = createLauncherSelection(\n catalog,\n selectionState.quantities,\n selectionState.customAmounts,\n selectionState.recurringProductId\n );\n const summary = getSelectionSummary(catalog, draftSelection);\n const donationProducts = catalog.products.filter(\n (product) =>\n product.paymentOption === \"one-time\" && product.pricingMode === \"custom\"\n );\n const orderProducts = catalog.products.filter(\n (product) => !donationProducts.includes(product)\n );\n\n return (\n <form\n className=\"lockerverse-launcher__products\"\n onSubmit={(event) => {\n event.preventDefault();\n if (draftSelection.length > 0) {\n onContinue(draftSelection);\n }\n }}\n >\n {orderProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__section\">\n <LauncherProductList {...selectionState} products={orderProducts} />\n </section>\n ) : null}\n {donationProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__donation\">\n <header className=\"lockerverse-launcher__section-header\">\n <h3>Add a donation</h3>\n <p>Choose an amount to add to this order.</p>\n </header>\n <LauncherProductList\n {...selectionState}\n products={donationProducts}\n variant=\"donation\"\n />\n </section>\n ) : null}\n {catalog.products.length > 0 ? (\n <footer className=\"lockerverse-launcher__footer\">\n <p aria-live=\"polite\" className=\"lockerverse-launcher__summary\">\n <span>\n {summary.itemCount === 0\n ? \"No items selected\"\n : `${summary.itemCount} ${summary.itemCount === 1 ? \"item\" : \"items\"} selected`}\n </span>\n {summary.itemCount === 0 ? null : (\n <strong>{usd.format(summary.amountCents / 100)}</strong>\n )}\n </p>\n <button\n className=\"lockerverse-launcher__continue\"\n disabled={draftSelection.length === 0}\n type=\"submit\"\n >\n Continue\n </button>\n </footer>\n ) : null}\n </form>\n );\n}\n\ntype LauncherPaymentProps = Omit<\n LockerversePaymentProps,\n \"selection\" | \"widget\"\n>;\n\ntype LauncherCheckoutProps = {\n onEdit: () => void;\n paymentProps: LauncherPaymentProps;\n selection: LockerversePaymentSelectionItem[];\n style: LockerversePaymentStyle;\n widget: UseLockerverseWidgetResult;\n};\n\nfunction LauncherCheckout({\n onEdit,\n paymentProps,\n selection,\n style,\n widget,\n}: LauncherCheckoutProps) {\n return (\n <div className=\"lockerverse-launcher__checkout\">\n <header className=\"lockerverse-launcher__checkout-toolbar\">\n <button\n className=\"lockerverse-launcher__back\"\n onClick={onEdit}\n type=\"button\"\n >\n Edit order\n </button>\n </header>\n <LockerversePayment\n {...paymentProps}\n selection={selection}\n style={style}\n widget={widget}\n />\n </div>\n );\n}\n\nfunction LauncherDialogHeading({\n catalog,\n checkout,\n}: {\n catalog: LockerverseCatalog | null;\n checkout: boolean;\n}) {\n if (checkout) {\n return (\n <>\n <Dialog.Title className=\"lockerverse-launcher__sr-only\">\n Checkout\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__sr-only\">\n Review the order and complete payment.\n </Dialog.Description>\n </>\n );\n }\n\n if (!catalog) {\n return (\n <header className=\"lockerverse-launcher__header\">\n <Dialog.Title className=\"lockerverse-launcher__title\">\n Donate\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n Choose your options, then continue to checkout.\n </Dialog.Description>\n </header>\n );\n }\n\n return (\n <header className=\"lockerverse-launcher__header\">\n {catalog.community ? (\n <div className=\"lockerverse-launcher__brand\">\n {catalog.community.imageUrl ? (\n <img\n alt={`${catalog.community.name} logo`}\n height=\"28\"\n src={catalog.community.imageUrl}\n width=\"28\"\n />\n ) : null}\n <span>{catalog.community.name}</span>\n </div>\n ) : null}\n <Dialog.Title className=\"lockerverse-launcher__title\">\n {catalog.widget.title ?? catalog.widget.name}\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n {catalog.widget.description ??\n \"Choose your options, then continue to checkout.\"}\n </Dialog.Description>\n </header>\n );\n}\n\nexport function LockerverseDonateLauncher({\n buttonLabel = \"Donate\",\n position = \"inline\",\n widget,\n ...paymentProps\n}: LockerverseDonateLauncherProps) {\n const [selection, setSelection] = useState<\n LockerversePaymentSelectionItem[] | null\n >(null);\n const [customAmounts, setCustomAmounts] = useState<Record<string, string>>(\n {}\n );\n const [quantities, setQuantities] = useState<Record<string, number>>({});\n const [recurringProductId, setRecurringProductId] = useState<string | null>(\n null\n );\n const { catalog, error, loading } = widget;\n const accent = normalizeAccentColor(\n paymentProps.style?.[\"--lockerverse-accent\"] ??\n catalog?.community?.accentColor ??\n \"#38d77a\"\n );\n const accentContrast = getAccentContrast(accent);\n const launcherStyle: LockerversePaymentStyle = { ...paymentProps.style };\n if (\n paymentProps.style?.[\"--lockerverse-accent\"] !== undefined ||\n catalog?.community?.accentColor\n ) {\n launcherStyle[\"--lockerverse-accent\"] = accent;\n }\n if (\n accentContrast &&\n paymentProps.style?.[\"--lockerverse-accent-contrast\"] === undefined\n ) {\n launcherStyle[\"--lockerverse-accent-contrast\"] = accentContrast;\n }\n\n let content: ReactNode;\n if (loading) {\n content = <LauncherLoading />;\n } else if (error) {\n content = (\n <div role=\"alert\">\n <p>Unable to load donation options.</p>\n <button onClick={widget.refresh} type=\"button\">\n Retry\n </button>\n </div>\n );\n } else if (catalog) {\n content = (\n <LauncherCatalog\n catalog={catalog}\n customAmounts={customAmounts}\n onContinue={setSelection}\n quantities={quantities}\n recurringProductId={recurringProductId}\n setCustomAmounts={setCustomAmounts}\n setQuantities={setQuantities}\n setRecurringProductId={setRecurringProductId}\n />\n );\n } else {\n content = <LauncherLoading />;\n }\n if (!(loading || error) && selection && catalog) {\n content = (\n <LauncherCheckout\n onEdit={() => setSelection(null)}\n paymentProps={paymentProps}\n selection={selection}\n style={launcherStyle}\n widget={widget}\n />\n );\n }\n\n return (\n <Dialog.Root\n onOpenChange={(open) => {\n if (open && catalog && paymentProps.stripeLoader === undefined) {\n requestAnimationFrame(() => {\n preloadLockerversePayment(catalog);\n });\n }\n }}\n >\n <Dialog.Trigger\n className={`lockerverse-launcher lockerverse-launcher--${position}`}\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n {buttonLabel}\n </Dialog.Trigger>\n <Dialog.Portal>\n <Dialog.Backdrop className=\"lockerverse-launcher__backdrop\" />\n <Dialog.Viewport className=\"lockerverse-launcher__viewport\">\n <Dialog.Popup\n className=\"lockerverse-launcher__dialog\"\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n <LauncherDialogHeading\n catalog={catalog}\n checkout={selection !== null}\n />\n <Dialog.Close\n aria-label=\"Close donation dialog\"\n className=\"lockerverse-launcher__close\"\n >\n <span aria-hidden=\"true\">×</span>\n </Dialog.Close>\n {content}\n </Dialog.Popup>\n </Dialog.Viewport>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}\n"],"mappings":"mVAuBA,MAAM,EAAM,IAAI,KAAK,aAAa,QAAS,CACzC,SAAU,MACV,MAAO,UACT,CAAC,EACK,EAAuB,iCACvB,EAAgC,CAAC,IAAM,KAAM,IAAM,GAAM,EAE/D,SAAS,EAAiB,EAAe,CACvC,GAAI,CAAC,EAAqB,KAAK,CAAK,EAClC,OAAO,KAET,IAAM,EAAc,KAAK,MAAM,OAAO,CAAK,EAAI,GAAG,EAClD,OAAO,OAAO,cAAc,CAAW,GAAK,EAAc,EACtD,EACA,IACN,CAEA,SAAS,EACP,EACA,EACA,CACA,IAAI,EAAU,GAOd,OANI,IAAkB,YACpB,EAAU,UAER,IAAkB,aACpB,EAAU,SAEL,GAAG,EAAI,OAAO,EAAc,GAAG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ACH,YACX,MAAO,EACC,QACT,CAAA,GAKH,EAAC,EAAO,KAAR,CACE,aAAe,GAAS,CAClB,GAAQ,GAAW,EAAa,eAAiB,IAAA,IACnD,0BAA4B,CAC1B,EAA0B,CAAO,CACnC,CAAC,CAEL,EAPF,SAAA,CASE,EAAC,EAAO,QAAR,CACE,UAAW,8CAA8C,IACzD,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAEN,SAAA,CACa,CAAA,EAChB,EAAC,EAAO,OAAR,CAAA,SAAA,CACE,EAAC,EAAO,SAAR,CAAiB,UAAU,gCAAkC,CAAA,EAC7D,EAAC,EAAO,SAAR,CAAiB,UAAU,iCACzB,SAAA,EAAC,EAAO,MAAR,CACE,UAAU,+BACV,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAHT,SAAA,CAKE,EAAC,EAAD,CACW,UACT,SAAU,IAAc,IACzB,CAAA,EACD,EAAC,EAAO,MAAR,CACE,aAAW,wBACX,UAAU,8BAEV,SAAA,EAAC,OAAD,CAAM,cAAY,OAAO,SAAA,GAAO,CAAA,CACpB,CAAA,EACb,CACW,GACC,CAAA,CACJ,CAAA,CAAA,CACJ,GAEjB"}
1
+ {"version":3,"file":"lockerverse-donate-launcher.js","names":[],"sources":["../src/lockerverse-donate-launcher.tsx"],"sourcesContent":["import { Dialog } from \"@base-ui/react/dialog\";\nimport {\n getLockerverseMinimumCustomAmountCents,\n type LockerverseCatalog,\n type LockerverseProduct,\n} from \"@lockerverse/sdk/checkout\";\nimport {\n type Dispatch,\n type ReactNode,\n type SetStateAction,\n useState,\n} from \"react\";\nimport { getAccentContrast, normalizeAccentColor } from \"./accent-contrast.ts\";\nimport { LockerversePayment } from \"./lockerverse-payment.tsx\";\nimport { preloadLockerversePayment } from \"./payment-form.tsx\";\nimport type {\n LockerverseDonateLauncherProps,\n LockerversePaymentProps,\n LockerversePaymentSelectionItem,\n LockerversePaymentStyle,\n} from \"./types.ts\";\nimport type { UseLockerverseWidgetResult } from \"./use-lockerverse-widget.ts\";\n\nconst usd = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\nconst decimalAmountPattern = /^(?:0|[1-9]\\d*)(?:\\.\\d{1,2})?$/;\nconst suggestedDonationAmountsCents = [1000, 2500, 5000, 10_000];\n\nfunction parseAmountCents(value: string) {\n if (!decimalAmountPattern.test(value)) {\n return null;\n }\n const amountCents = Math.round(Number(value) * 100);\n return Number.isSafeInteger(amountCents) && amountCents > 0\n ? amountCents\n : null;\n}\n\nfunction formatProductPrice(\n amountCents: number,\n paymentOption: \"one-time\" | \"monthly\" | \"annually\"\n) {\n let cadence = \"\";\n if (paymentOption === \"monthly\") {\n cadence = \"/month\";\n }\n if (paymentOption === \"annually\") {\n cadence = \"/year\";\n }\n return `${usd.format(amountCents / 100)}${cadence}`;\n}\n\ntype LauncherProductControlProps = {\n customAmounts: Record<string, string>;\n product: LockerverseProduct;\n quantities: Record<string, number>;\n recurringProductId: string | null;\n setCustomAmounts: Dispatch<SetStateAction<Record<string, string>>>;\n setQuantities: Dispatch<SetStateAction<Record<string, number>>>;\n setRecurringProductId: Dispatch<SetStateAction<string | null>>;\n};\n\nfunction LauncherProductControl({\n customAmounts,\n product,\n quantities,\n recurringProductId,\n setCustomAmounts,\n setQuantities,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const quantity = quantities[product.id] ?? 0;\n if (product.pricingMode === \"fixed\" && product.paymentOption === \"one-time\") {\n const minimum = product.minimumQuantity ?? 1;\n const maximum = Math.min(\n product.maximumQuantity ?? Number.POSITIVE_INFINITY,\n product.inventoryQuantity ?? Number.POSITIVE_INFINITY\n );\n return (\n <span className=\"lockerverse-launcher__quantity\">\n <button\n aria-label={`Decrease ${product.name} quantity`}\n disabled={quantity === 0}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity <= minimum ? 0 : currentQuantity - 1,\n };\n });\n }}\n type=\"button\"\n >\n −\n </button>\n <output aria-label={`${product.name} quantity`}>{quantity}</output>\n <button\n aria-label={`Increase ${product.name} quantity`}\n disabled={maximum < minimum || quantity >= maximum}\n onClick={() => {\n setRecurringProductId(null);\n setQuantities((current) => {\n const currentQuantity = current[product.id] ?? 0;\n return {\n ...current,\n [product.id]:\n currentQuantity === 0 ? minimum : currentQuantity + 1,\n };\n });\n }}\n type=\"button\"\n >\n +\n </button>\n </span>\n );\n }\n\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\"\n ) {\n return (\n <span className=\"lockerverse-launcher__custom-amount\">\n <span aria-hidden=\"true\">$</span>\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: event.target.value,\n }));\n }}\n placeholder=\"0.00\"\n step=\"0.01\"\n type=\"number\"\n value={customAmounts[product.id] ?? \"\"}\n />\n {product.minimumAmountCents === null ? null : (\n <small>Minimum {usd.format(product.minimumAmountCents / 100)}</small>\n )}\n </span>\n );\n }\n\n return (\n <button\n aria-label={`Select ${product.name}`}\n aria-pressed={recurringProductId === product.id}\n className=\"lockerverse-launcher__select\"\n onClick={() => {\n setQuantities({});\n setCustomAmounts({});\n setRecurringProductId((current) =>\n current === product.id ? null : product.id\n );\n }}\n type=\"button\"\n >\n Select\n </button>\n );\n}\n\ntype LauncherProductOptionProps = LauncherProductControlProps & {\n variant?: \"default\" | \"donation\";\n};\n\nfunction LauncherProductOption({\n variant = \"default\",\n ...props\n}: LauncherProductOptionProps) {\n const { customAmounts, product, quantities, recurringProductId } = props;\n const customAmount = parseAmountCents(customAmounts[product.id] ?? \"\");\n const isSelected =\n recurringProductId === product.id ||\n (product.paymentOption === \"one-time\" &&\n ((product.pricingMode === \"fixed\" && (quantities[product.id] ?? 0) > 0) ||\n (product.pricingMode === \"custom\" &&\n customAmount !== null &&\n customAmount >= getLockerverseMinimumCustomAmountCents(product))));\n return (\n <article\n className={`lockerverse-launcher__product lockerverse-launcher__product--${variant}`}\n data-selected={isSelected || undefined}\n >\n <span className=\"lockerverse-launcher__product-copy\">\n <strong className=\"lockerverse-launcher__product-name\">\n {product.name}\n </strong>\n {product.description ? <small>{product.description}</small> : null}\n {product.amountCents === null ? null : (\n <span className=\"lockerverse-launcher__product-price\">\n {formatProductPrice(product.amountCents, product.paymentOption)}\n </span>\n )}\n </span>\n <LauncherProductControl {...props} />\n </article>\n );\n}\n\nfunction LauncherDonationOption({\n customAmounts,\n product,\n setCustomAmounts,\n setRecurringProductId,\n}: LauncherProductControlProps) {\n const amount = customAmounts[product.id] ?? \"\";\n const amountCents = parseAmountCents(amount);\n const suggestions = suggestedDonationAmountsCents.filter(\n (suggestion) =>\n suggestion >= getLockerverseMinimumCustomAmountCents(product)\n );\n const isSuggestedAmount = suggestions.includes(amountCents ?? 0);\n const setAmount = (value: string) => {\n setRecurringProductId(null);\n setCustomAmounts((current) => ({\n ...current,\n [product.id]: value,\n }));\n };\n\n return (\n <div className=\"lockerverse-launcher__donation-option\">\n <fieldset className=\"lockerverse-launcher__donation-choices\">\n <legend className=\"lockerverse-launcher__sr-only\">\n {product.name} amount\n </legend>\n <button\n aria-pressed={amount === \"\"}\n onClick={() => setAmount(\"\")}\n type=\"button\"\n >\n No thanks\n </button>\n {suggestions.map((suggestion) => (\n <button\n aria-pressed={amountCents === suggestion}\n key={suggestion}\n onClick={() => setAmount(String(suggestion / 100))}\n type=\"button\"\n >\n {usd.format(suggestion / 100).replace(\".00\", \"\")}\n </button>\n ))}\n <label\n className=\"lockerverse-launcher__donation-other\"\n data-selected={amount !== \"\" && !isSuggestedAmount ? true : undefined}\n >\n <input\n aria-label={`${product.name} amount`}\n min={getLockerverseMinimumCustomAmountCents(product) / 100}\n name={`amount-${product.slug}`}\n onChange={(event) => setAmount(event.target.value)}\n placeholder=\"Other $\"\n step=\"0.01\"\n type=\"number\"\n value={isSuggestedAmount ? \"\" : amount}\n />\n </label>\n </fieldset>\n </div>\n );\n}\n\ntype LauncherProductListProps = Omit<LauncherProductControlProps, \"product\"> & {\n products: LockerverseProduct[];\n variant?: LauncherProductOptionProps[\"variant\"];\n};\n\nfunction LauncherProductList({\n products,\n variant = \"default\",\n ...controlProps\n}: LauncherProductListProps) {\n return (\n <div className=\"lockerverse-launcher__product-list\">\n {products.map((product) =>\n variant === \"donation\" ? (\n <LauncherDonationOption\n {...controlProps}\n key={product.id}\n product={product}\n />\n ) : (\n <LauncherProductOption\n {...controlProps}\n key={product.id}\n product={product}\n variant={variant}\n />\n )\n )}\n </div>\n );\n}\n\nfunction getSelectionSummary(\n catalog: LockerverseCatalog,\n selection: LockerversePaymentSelectionItem[]\n) {\n let itemCount = 0;\n let amountCents = 0;\n for (const item of selection) {\n const product = catalog.products.find(\n (candidate) => candidate.slug === item.productSlug\n );\n if (!product) {\n continue;\n }\n if (\"quantity\" in item) {\n itemCount += item.quantity;\n amountCents += (product.amountCents ?? 0) * item.quantity;\n continue;\n }\n itemCount += 1;\n amountCents +=\n \"amountCents\" in item ? item.amountCents : (product.amountCents ?? 0);\n }\n return { amountCents, itemCount };\n}\n\nfunction LauncherLoading() {\n return (\n <div\n aria-label=\"Loading donation options\"\n className=\"lockerverse-launcher__loading\"\n role=\"status\"\n >\n {[0, 1, 2].map((item) => (\n <span\n aria-hidden=\"true\"\n className=\"lockerverse-launcher__loading-row\"\n key={item}\n />\n ))}\n </div>\n );\n}\n\nfunction createLauncherSelection(\n catalog: LockerverseCatalog,\n quantities: Record<string, number>,\n customAmounts: Record<string, string>,\n recurringProductId: string | null\n): LockerversePaymentSelectionItem[] {\n if (recurringProductId) {\n const product = catalog.products.find(\n (candidate) =>\n candidate.id === recurringProductId &&\n candidate.paymentOption !== \"one-time\"\n );\n return product ? [{ productSlug: product.slug }] : [];\n }\n\n return catalog.products.flatMap(\n (product): LockerversePaymentSelectionItem[] => {\n const quantity = quantities[product.id] ?? 0;\n if (\n product.pricingMode === \"fixed\" &&\n product.paymentOption === \"one-time\" &&\n quantity > 0\n ) {\n return [{ productSlug: product.slug, quantity }];\n }\n const amountCents = parseAmountCents(customAmounts[product.id] ?? \"\");\n if (\n product.pricingMode === \"custom\" &&\n product.paymentOption === \"one-time\" &&\n amountCents !== null &&\n amountCents >= getLockerverseMinimumCustomAmountCents(product)\n ) {\n return [{ amountCents, productSlug: product.slug }];\n }\n return [];\n }\n );\n}\n\ntype LauncherSelectionStateProps = Omit<LauncherProductControlProps, \"product\">;\n\ntype LauncherCatalogProps = LauncherSelectionStateProps & {\n catalog: LockerverseCatalog;\n onContinue: (selection: LockerversePaymentSelectionItem[]) => void;\n};\n\nfunction LauncherCatalog({\n catalog,\n onContinue,\n ...selectionState\n}: LauncherCatalogProps) {\n const draftSelection = createLauncherSelection(\n catalog,\n selectionState.quantities,\n selectionState.customAmounts,\n selectionState.recurringProductId\n );\n const summary = getSelectionSummary(catalog, draftSelection);\n const donationProducts = catalog.products.filter(\n (product) =>\n product.paymentOption === \"one-time\" && product.pricingMode === \"custom\"\n );\n const orderProducts = catalog.products.filter(\n (product) => !donationProducts.includes(product)\n );\n\n return (\n <form\n className=\"lockerverse-launcher__products\"\n onSubmit={(event) => {\n event.preventDefault();\n if (draftSelection.length > 0) {\n onContinue(draftSelection);\n }\n }}\n >\n {orderProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__section\">\n <LauncherProductList {...selectionState} products={orderProducts} />\n </section>\n ) : null}\n {donationProducts.length > 0 ? (\n <section className=\"lockerverse-launcher__donation\">\n <header className=\"lockerverse-launcher__section-header\">\n <h3>Add a donation</h3>\n <p>Choose an amount to add to this order.</p>\n </header>\n <LauncherProductList\n {...selectionState}\n products={donationProducts}\n variant=\"donation\"\n />\n </section>\n ) : null}\n {catalog.products.length > 0 ? (\n <footer className=\"lockerverse-launcher__footer\">\n <p aria-live=\"polite\" className=\"lockerverse-launcher__summary\">\n <span>\n {summary.itemCount === 0\n ? \"No items selected\"\n : `${summary.itemCount} ${summary.itemCount === 1 ? \"item\" : \"items\"} selected`}\n </span>\n {summary.itemCount === 0 ? null : (\n <strong>{usd.format(summary.amountCents / 100)}</strong>\n )}\n </p>\n <button\n className=\"lockerverse-launcher__continue\"\n disabled={draftSelection.length === 0}\n type=\"submit\"\n >\n Continue\n </button>\n </footer>\n ) : null}\n </form>\n );\n}\n\ntype LauncherPaymentProps = Omit<\n LockerversePaymentProps,\n \"selection\" | \"widget\"\n>;\n\ntype LauncherCheckoutProps = {\n onEdit: () => void;\n paymentProps: LauncherPaymentProps;\n selection: LockerversePaymentSelectionItem[];\n style: LockerversePaymentStyle;\n widget: UseLockerverseWidgetResult;\n};\n\nfunction LauncherCheckout({\n onEdit,\n paymentProps,\n selection,\n style,\n widget,\n}: LauncherCheckoutProps) {\n return (\n <div className=\"lockerverse-launcher__checkout\">\n <header className=\"lockerverse-launcher__checkout-toolbar\">\n <button\n className=\"lockerverse-launcher__back\"\n onClick={onEdit}\n type=\"button\"\n >\n Edit order\n </button>\n </header>\n <LockerversePayment\n {...paymentProps}\n selection={selection}\n style={style}\n widget={widget}\n />\n </div>\n );\n}\n\nfunction LauncherDialogHeading({\n catalog,\n checkout,\n}: {\n catalog: LockerverseCatalog | null;\n checkout: boolean;\n}) {\n if (checkout) {\n return (\n <>\n <Dialog.Title className=\"lockerverse-launcher__sr-only\">\n Checkout\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__sr-only\">\n Review the order and complete payment.\n </Dialog.Description>\n </>\n );\n }\n\n if (!catalog) {\n return (\n <header className=\"lockerverse-launcher__header\">\n <Dialog.Title className=\"lockerverse-launcher__title\">\n Donate\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n Choose your options, then continue to checkout.\n </Dialog.Description>\n </header>\n );\n }\n\n return (\n <header className=\"lockerverse-launcher__header\">\n {catalog.community ? (\n <div className=\"lockerverse-launcher__brand\">\n {catalog.community.imageUrl ? (\n <img\n alt={`${catalog.community.name} logo`}\n height=\"28\"\n src={catalog.community.imageUrl}\n width=\"28\"\n />\n ) : null}\n <span>{catalog.community.name}</span>\n </div>\n ) : null}\n <Dialog.Title className=\"lockerverse-launcher__title\">\n {catalog.widget.title ?? catalog.widget.name}\n </Dialog.Title>\n <Dialog.Description className=\"lockerverse-launcher__description\">\n {catalog.widget.description ??\n \"Choose your options, then continue to checkout.\"}\n </Dialog.Description>\n </header>\n );\n}\n\nexport function LockerverseDonateLauncher({\n buttonLabel = \"Donate\",\n position = \"inline\",\n widget,\n ...paymentProps\n}: LockerverseDonateLauncherProps) {\n const [selection, setSelection] = useState<\n LockerversePaymentSelectionItem[] | null\n >(null);\n const [customAmounts, setCustomAmounts] = useState<Record<string, string>>(\n {}\n );\n const [quantities, setQuantities] = useState<Record<string, number>>({});\n const [recurringProductId, setRecurringProductId] = useState<string | null>(\n null\n );\n const { catalog, error, loading } = widget;\n const accent = normalizeAccentColor(\n paymentProps.style?.[\"--lockerverse-accent\"] ??\n catalog?.community?.accentColor ??\n \"#38d77a\"\n );\n const accentContrast = getAccentContrast(accent);\n const launcherStyle: LockerversePaymentStyle = { ...paymentProps.style };\n if (\n paymentProps.style?.[\"--lockerverse-accent\"] !== undefined ||\n catalog?.community?.accentColor\n ) {\n launcherStyle[\"--lockerverse-accent\"] = accent;\n }\n if (\n accentContrast &&\n paymentProps.style?.[\"--lockerverse-accent-contrast\"] === undefined\n ) {\n launcherStyle[\"--lockerverse-accent-contrast\"] = accentContrast;\n }\n\n let content: ReactNode;\n if (loading) {\n content = <LauncherLoading />;\n } else if (error) {\n content = (\n <div role=\"alert\">\n <p>Unable to load donation options.</p>\n <button onClick={widget.refresh} type=\"button\">\n Retry\n </button>\n </div>\n );\n } else if (catalog) {\n content = (\n <LauncherCatalog\n catalog={catalog}\n customAmounts={customAmounts}\n onContinue={setSelection}\n quantities={quantities}\n recurringProductId={recurringProductId}\n setCustomAmounts={setCustomAmounts}\n setQuantities={setQuantities}\n setRecurringProductId={setRecurringProductId}\n />\n );\n } else {\n content = <LauncherLoading />;\n }\n if (!(loading || error) && selection && catalog) {\n content = (\n <LauncherCheckout\n onEdit={() => setSelection(null)}\n paymentProps={paymentProps}\n selection={selection}\n style={launcherStyle}\n widget={widget}\n />\n );\n }\n\n return (\n <Dialog.Root\n onOpenChange={(open) => {\n if (open && catalog && paymentProps.stripeLoader === undefined) {\n requestAnimationFrame(() => {\n preloadLockerversePayment(catalog);\n });\n }\n }}\n >\n <Dialog.Trigger\n className={`lockerverse-launcher lockerverse-launcher--${position}`}\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n {buttonLabel}\n </Dialog.Trigger>\n <Dialog.Portal>\n <Dialog.Backdrop className=\"lockerverse-launcher__backdrop\" />\n <Dialog.Viewport className=\"lockerverse-launcher__viewport\">\n <Dialog.Popup\n className=\"lockerverse-launcher__dialog\"\n data-lockerverse-theme={paymentProps.theme ?? \"dark\"}\n style={launcherStyle}\n >\n <LauncherDialogHeading\n catalog={catalog}\n checkout={selection !== null}\n />\n <Dialog.Close\n aria-label=\"Close donation dialog\"\n className=\"lockerverse-launcher__close\"\n >\n <span aria-hidden=\"true\">×</span>\n </Dialog.Close>\n {content}\n </Dialog.Popup>\n </Dialog.Viewport>\n </Dialog.Portal>\n </Dialog.Root>\n );\n}\n"],"mappings":"2UAuBA,MAAM,EAAM,IAAI,KAAK,aAAa,QAAS,CACzC,SAAU,MACV,MAAO,UACT,CAAC,EACK,EAAuB,iCACvB,EAAgC,CAAC,IAAM,KAAM,IAAM,GAAM,EAE/D,SAAS,EAAiB,EAAe,CACvC,GAAI,CAAC,EAAqB,KAAK,CAAK,EAClC,OAAO,KAET,IAAM,EAAc,KAAK,MAAM,OAAO,CAAK,EAAI,GAAG,EAClD,OAAO,OAAO,cAAc,CAAW,GAAK,EAAc,EACtD,EACA,IACN,CAEA,SAAS,EACP,EACA,EACA,CACA,IAAI,EAAU,GAOd,OANI,IAAkB,YACpB,EAAU,UAER,IAA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tC,EACE,EAAC,EAAD,CACE,WAAc,EAAa,IAAI,EACjB,eACH,YACX,MAAO,EACC,QACT,CAAA,GAKH,EAAC,EAAO,KAAR,CACE,aAAe,GAAS,CAClB,GAAQ,GAAW,EAAa,eAAiB,IAAA,IACnD,0BAA4B,CAC1B,EAA0B,CAAO,CACnC,CAAC,CAEL,EAPF,SAAA,CASE,EAAC,EAAO,QAAR,CACE,UAAW,8CAA8C,IACzD,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAEN,SAAA,CACa,CAAA,EAChB,EAAC,EAAO,OAAR,CAAA,SAAA,CACE,EAAC,EAAO,SAAR,CAAiB,UAAU,gCAAkC,CAAA,EAC7D,EAAC,EAAO,SAAR,CAAiB,UAAU,iCACzB,SAAA,EAAC,EAAO,MAAR,CACE,UAAU,+BACV,yBAAwB,EAAa,OAAS,OAC9C,MAAO,EAHT,SAAA,CAKE,EAAC,EAAD,CACW,UACT,SAAU,IAAc,IACzB,CAAA,EACD,EAAC,EAAO,MAAR,CACE,aAAW,wBACX,UAAU,8BAEV,SAAA,EAAC,OAAD,CAAM,cAAY,OAAO,SAAA,GAAO,CAAA,CACpB,CAAA,EACb,CACW,GACC,CAAA,CACJ,CAAA,CAAA,CACJ,GAEjB"}
@@ -1,2 +1,2 @@
1
- import{a as e,c as t,d as n,f as r,g as i,h as a,i as o,l as s,m as c,n as l,p as u,r as d,t as f,u as p}from"./host-callback.js";import{LockerverseSdkError as m,estimateLockerverseCheckout as h}from"@lockerverse/sdk/checkout";import{createContext as g,useCallback as _,useContext as v,useEffect as y,useId as b,useLayoutEffect as x,useMemo as S,useReducer as C,useRef as w,useState as T}from"react";import{AddressElement as E,Elements as D,PaymentElement as O,useElements as k,useStripe as A}from"@stripe/react-stripe-js";import{loadStripe as j}from"@stripe/stripe-js/pure/index.js";import{array as M,minLength as N,minValue as P,nonEmpty as F,number as I,object as L,pipe as R,regex as ee,safeInteger as te,safeParse as z,strictObject as B,string as V,trim as ne,union as re}from"valibot";import{Fragment as H,jsx as U,jsxs as W}from"react/jsx-runtime";import{Select as G}from"@base-ui/react/select";const ie=new Intl.NumberFormat(`en-US`,{currency:`USD`,style:`currency`});function K(e){return ie.format(e/100)}const q=g(void 0);function J({children:e,container:t}){return U(q.Provider,{value:t,children:e})}function ae(){return U(`svg`,{"aria-hidden":`true`,fill:`none`,viewBox:`0 0 16 16`,children:U(`path`,{d:`m4 6 4 4 4-4`})})}function oe(){return U(`svg`,{"aria-hidden":`true`,fill:`none`,viewBox:`0 0 16 16`,children:U(`path`,{d:`m3 8 3 3 7-7`})})}function Y({ariaDescribedBy:e,ariaLabel:t,ariaLabelledBy:n,className:r,id:i,invalid:a=!1,name:o,onValueChange:s,options:c,value:l}){let u=v(q),d=[`lockerverse-payment__select`,r].filter(Boolean).join(` `);return U(`div`,{className:d,children:W(G.Root,{id:i,items:c,name:o,onValueChange:e=>{e!==null&&s(e)},value:l,children:[W(G.Trigger,{"aria-describedby":e,"aria-invalid":a||void 0,"aria-label":t,"aria-labelledby":n,className:`lockerverse-payment__select-trigger`,children:[U(G.Value,{}),U(G.Icon,{"aria-hidden":`true`,className:`lockerverse-payment__select-icon`,children:U(ae,{})})]}),U(G.Portal,{container:u,children:U(G.Positioner,{alignItemWithTrigger:!1,className:`lockerverse-payment__select-positioner`,sideOffset:6,children:U(G.Popup,{className:`lockerverse-payment__select-popup`,children:U(G.List,{className:`lockerverse-payment__select-list`,children:c.map(e=>W(G.Item,{className:`lockerverse-payment__select-item`,value:e.value,children:[U(G.ItemText,{children:e.label}),U(G.ItemIndicator,{"aria-hidden":`true`,className:`lockerverse-payment__select-item-indicator`,children:U(oe,{})})]},e.value))})})})})]})})}const X=[`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`],se=[`15`,`12`,`10`,`5`],Z=[...se,`custom`];function ce({enabled:e,error:t,errorId:n,onChange:r,values:i}){if(!e)return null;let a=e=>r({...i,...e}),o=(e,t)=>{let n=Z.indexOf(t),r;switch(e.key){case`ArrowDown`:case`ArrowRight`:r=(n+1)%Z.length;break;case`ArrowLeft`:case`ArrowUp`:r=(n-1+Z.length)%Z.length;break;case`Home`:r=0;break;case`End`:r=Z.length-1;break;default:return}e.preventDefault();let i=Z[r];i&&((e.currentTarget.closest(`[role="radiogroup"]`)?.querySelectorAll(`input[type="radio"]`))?.[r]?.focus(),a({tipPercent:i}))};return W(`div`,{className:`lockerverse-payment__tip-box`,children:[U(`p`,{children:`Add a tip to support the Lockerverse platform`}),W(`div`,{"aria-label":`Tip amount`,role:`radiogroup`,children:[se.map(e=>W(`label`,{className:`lockerverse-payment__tip-choice`,children:[U(`input`,{checked:i.tipPercent===e,name:`tipPercent`,onChange:()=>a({tipPercent:e}),onKeyDown:t=>o(t,e),tabIndex:i.tipPercent===e?0:-1,type:`radio`,value:e}),W(`span`,{children:[e,`%`]})]},e)),W(`label`,{className:`lockerverse-payment__tip-choice`,children:[U(`input`,{checked:i.tipPercent===`custom`,name:`tipPercent`,onChange:()=>a({tipPercent:`custom`}),onKeyDown:e=>o(e,`custom`),tabIndex:i.tipPercent===`custom`?0:-1,type:`radio`,value:`custom`}),U(`span`,{children:`Other`})]})]}),i.tipPercent===`custom`?W(`label`,{children:[U(`span`,{children:`Custom tip`}),W(`span`,{className:`lockerverse-payment__money-input`,children:[U(`span`,{"aria-hidden":`true`,children:`$`}),U(`input`,{"aria-describedby":t?n:void 0,"aria-invalid":t?`true`:void 0,inputMode:`decimal`,name:`tip`,onChange:e=>a({customTip:e.currentTarget.value}),placeholder:`0.00`,value:i.customTip})]}),t?U(`span`,{className:`lockerverse-payment__field-message`,id:n,children:t}):null]}):U(`input`,{name:`tip`,type:`hidden`,value:i.tipPercent})]})}function le({checked:e,children:t,name:n,onChange:r}){return W(`label`,{className:`lockerverse-payment__check-row`,children:[U(`input`,{checked:e,name:n,onChange:e=>r(e.currentTarget.checked),type:`checkbox`}),U(`span`,{children:t})]})}function ue({customFields:e,errors:t,fields:r,idPrefix:i,isPromoApplying:a,onChange:o,onApplyPromo:s,promoError:c,values:l}){let u=e=>o({...l,...e});return W(`div`,{className:`lockerverse-payment__additional-fields`,children:[r.memberId?W(`label`,{children:[U(`span`,{children:`Member ID`}),U(`input`,{name:`memberId`,onChange:e=>u({memberId:e.currentTarget.value}),placeholder:`Optional`,value:l.memberId})]}):null,r.merchSize?W(`div`,{className:`lockerverse-payment__field`,children:[U(`span`,{id:`${i}-merch-size-label`,children:`Size`}),U(Y,{ariaLabelledBy:`${i}-merch-size-label`,name:`merchSize`,onValueChange:e=>{let t=X.find(t=>t===e);t&&u({merchSize:t})},options:X.map(e=>({label:e,value:e})),value:l.merchSize})]}):null,r.promoCode?W(`div`,{className:`lockerverse-payment__field`,children:[U(`span`,{id:`${i}-promo-code-label`,children:`Promo code`}),W(`div`,{className:`lockerverse-payment__promo-control`,children:[U(`input`,{"aria-describedby":c?`${i}-promo-code-error`:void 0,"aria-invalid":c?`true`:void 0,"aria-labelledby":`${i}-promo-code-label`,name:`promoCode`,onChange:e=>u({promoCode:e.currentTarget.value}),placeholder:`Optional`,value:l.promoCode}),U(`button`,{disabled:!l.promoCode.trim()||a,onClick:s,type:`button`,children:a?`Applying…`:`Apply`})]}),c?U(`p`,{className:`lockerverse-payment__field-message`,id:`${i}-promo-code-error`,role:`alert`,children:c}):null]}):null,U(n,{choiceClassName:`lockerverse-payment__check-row`,errorClassName:`lockerverse-payment__field-message`,errors:t,fields:e,idPrefix:i,onChange:e=>u({customFields:e}),values:l.customFields})]})}function de({amountCents:e,enabled:t,onChange:n,values:r}){return t?W(le,{checked:r.includeServiceFee,name:`includeServiceFee`,onChange:e=>n({...r,includeServiceFee:e}),children:[`Add `,K(e),` to help cover processing fees`]}):null}function fe(e){return{error:void 0,message:void 0,status:e?`recovering`:`editing`}}function Q(e,t,n){return t.includes(e.status)?{...e,...n}:e}function pe(e,t){if(e.status===`sold_out`||e.status===`succeeded`||e.status===`unresolved`)return e;switch(t.type){case`field_changed`:return Q(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`editing`});case`validation_failed`:return Q(e,[`editing`],{status:`invalid`});case`quote_refresh_started`:return Q(e,[`editing`,`invalid`],{status:`refreshing_quote`});case`quote_refresh_succeeded`:return Q(e,[`refreshing_quote`],{error:void 0,status:`editing`});case`quote_refresh_failed`:return Q(e,[`refreshing_quote`],{error:t.error??e.error,status:`editing`});case`submission_started`:return Q(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`submitting`});case`submission_validation_failed`:return Q(e,[`submitting`],{error:void 0,status:`invalid`});case`quote_changed`:return Q(e,[`submitting`],{status:`editing`});case`retryable_failure`:return Q(e,[`editing`,`invalid`,`submitting`],{error:t.error,status:`editing`});case`recovery_failed`:return Q(e,[`recovering`],{error:t.error,status:`editing`});case`sold_out`:return{error:void 0,message:void 0,status:`sold_out`};case`succeeded`:return Q(e,[`recovering`,`submitting`],{message:t.message,status:`succeeded`});case`unresolved`:return Q(e,[`recovering`,`submitting`],{message:t.message,status:`unresolved`});default:return e}}function me(e){return e.status===`editing`||e.status===`invalid`||e.status===`refreshing_quote`?e.error:void 0}function he(e){return e.status===`sold_out`?`sold_out`:e.status===`succeeded`?`success`:e.status===`unresolved`?`unresolved`:e.status===`submitting`||e.status===`recovering`?`submitting`:e.status===`invalid`?`invalid`:me(e)?`error`:`idle`}function ge(e){return e.status===`submitting`}function _e(t){return e(t)}function ve(e,n){let r=n?{...e,phone:_e(e.phone)}:e,i=L(n?{email:t,phone:s}:{email:t}),a=z(i,r);if(a.success)return{errors:{},value:a.output};let o={};for(let e of a.issues){let t=e.path?.[0]?.key;(t===`email`||t===`phone`)&&!o[t]&&(o[t]=e.message)}return{errors:o,value:null}}const ye=[`amountCents`,`discountableSubtotalCents`,`discountCents`,`serviceFeeCents`,`subtotalCents`,`tipCents`,`totalCents`],be=[`discountableSubtotalCents`,`discountCents`,`subtotalCents`];function xe(e,t,n,r){return(n===t.totalCents?be:ye).some(n=>e[n]!==t[n])||r!==t.payment.connectedAccountId||e.authoritative&&(e.payment.connectedAccountId!==r||e.payment.currency!==t.payment.currency)||JSON.stringify(e.appliedDiscount)!==JSON.stringify(t.appliedDiscount)||JSON.stringify(e.lineItems)!==JSON.stringify(t.lineItems)}function Se(e){return e.checkoutStatus===`success`?{kind:`success`,payment:e}:e.checkoutStatus===`failed`?{kind:`failed`,payment:e}:{kind:`unresolved`,paymentReference:e.paymentReference,reason:e.checkoutStatus===`action_required`?`action_required`:`pending`}}async function Ce(e,t,n){if(t.checkoutStatus!==`action_required`)return Se(t);if(!n)return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`};if(t.clientSecret)try{await n.handleNextAction({clientSecret:t.clientSecret})}catch{}try{return Se(await e.getPaymentStatus(t.paymentReference))}catch{return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`}}}async function we(e,t,n){let r;try{r=await e.submitPayment(t)}catch(n){if(!(n instanceof m&&n.recoveryRecommended))throw n;try{r=await e.getPaymentStatus(t.checkout.paymentReference)}catch{return{kind:`unresolved`,paymentReference:t.checkout.paymentReference,reason:`recovery_failed`}}}return Ce(e,r,n)}async function Te(e,t,n){try{return Ce(e,await e.getPaymentStatus(t),n)}catch{return{kind:`unresolved`,paymentReference:t,reason:`recovery_failed`}}}const Ee=R(V(),ne(),F()),De=R(I(),te(),P(1)),Oe=R(M(re([B({amountCents:De,productSlug:Ee}),B({productSlug:Ee,quantity:De}),B({productSlug:Ee})])),N(1)),ke=R(V(),ne(),ee(/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,`Enter a valid tip amount.`));function Ae(e){let t=z(ke,e);if(!t.success)return{message:t.issues[0]?.message??`Enter a valid tip amount.`,success:!1};let[n=`0`,r=``]=t.output.split(`.`),i=BigInt(n)*100n+BigInt(r.padEnd(2,`0`));return i>BigInt(2**53-1)?{message:`Enter a valid tip amount.`,success:!1}:{cents:Number(i),success:!0}}function je(e){let t=z(Oe,e);return t.success?{success:!0,value:t.output}:{message:`Lockerverse payment configuration is invalid.`,success:!1}}const Me=`This promo code is invalid or cannot be applied.`;function Ne(e,t){return t.tipPercent===`custom`?t.customTip.trim()?Ae(t.customTip):{cents:0,success:!0}:{cents:Math.round(e*Number(t.tipPercent)/100),success:!0}}function Pe(e,t,n,r){let i={};return n&&(i.email=n),e.widget.fields.serviceFee&&(i.includeServiceFee=t.includeServiceFee),e.widget.fields.promoCode&&t.promoCode.trim()&&(i.promoCode=t.promoCode.trim()),e.widget.fields.tipping&&(i.tipCents=r),i}function Fe(e,t,n){let r=e.widget.fields.tipping?Ne(n.subtotalCents,t):{cents:0,success:!0};if(!r.success)return{parsedTip:r,totalCents:null};let i=e.widget.fields.serviceFee&&t.includeServiceFee?n.serviceFeeCents||Math.round(n.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0;return{parsedTip:r,totalCents:n.totalCents-n.serviceFeeCents-n.tipCents+i+r.cents}}function Ie(e,t){return{displayedTotalCents:e.totalCents,promoError:t&&e.appliedDiscount?.source!==`promo_code`?Me:void 0}}function Le(e,t){let n;return t||(n=e instanceof Error?e.message:`The order total could not be updated.`),{paymentError:n,promoError:t?Me:void 0}}function Re(e,t){if(!e?.complete)throw Error(`${t} address is required.`);return e.value}function ze(e,t,n,r){if(e.widget.fields.shipping)return t.shippingMatchesBilling?n:Re(r.shipping,`Shipping`)}function Be({billingAddress:e,catalog:t,email:n,phone:r,shippingAddress:i}){let a={payment_method_data:{billing_details:t.widget.fields.phone?{address:e.address,email:n,name:e.name,phone:r}:{address:e.address,email:n,name:e.name}}};return i?{...a,shipping:{address:i.address,name:i.name,phone:t.widget.fields.phone?r:i.phone??null}}:a}function Ve({catalog:e,confirmationToken:t,email:n,fieldValues:i,metadata:a,phone:o,shippingAddress:s}){let c={customFieldAnswers:r(e.widget.customFields,i.customFields),email:n};if(t&&(c.confirmationToken=t),a&&(c.metadata=a),e.widget.fields.memberId&&i.memberId.trim()&&(c.memberId=i.memberId.trim()),e.widget.fields.merchSize&&(c.merchSize=i.merchSize),e.widget.fields.phone&&(c.phone=o),s){let e={city:s.address.city??``,country:s.address.country,line1:s.address.line1??``,postal_code:s.address.postal_code??``,state:s.address.state??``};s.address.line2&&(e.line2=s.address.line2),c.shipping={address:e,name:s.name}}return c}function He(e){if(!e())throw Error(`Payment component is no longer active.`)}function Ue(e,t){f(e,t)}function We(e,t,n,r){return e.kind===`failed`?{kind:`payment_failed`,message:r}:e.kind===`unresolved`?{kind:`payment_unresolved`,paymentReference:e.paymentReference,reason:e.reason}:{email:n,kind:`payment`,payment:e.payment,quote:t}}async function Ge({addresses:e,catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:o,isAttemptActive:s,locallyPreviewedTotalCents:c,metadata:l,onPaymentRecoveryChange:u,phone:d,quote:f,stripe:p,stripeConnectedAccountId:m}){let h=a.trim().toLowerCase(),g=_e(d),_=Ne(f.subtotalCents,o);if(!_.success)throw Error(_.message);let v=await r.calculateTotal({...Pe(t,o,h,_.cents),catalog:t,items:n});if(He(s),v.totalCents>0&&xe(f,v,c,m))return{kind:`quote_changed`,quote:v};let y,b;if(v.totalCents===0)t.widget.fields.shipping&&(y=ze(t,o,Re(e.billing,`Billing`),e));else{if(!(i&&p))throw Error(`Payment form is still loading.`);await i.update({amount:v.totalCents}),He(s);let n=await i.submit();if(He(s),n.error)throw Error(n.error.message);let r=Re(e.billing,`Billing`);y=ze(t,o,r,e);let a=await p.createConfirmationToken({elements:i,params:Be({billingAddress:r,catalog:t,email:h,phone:g,shippingAddress:y})});if(He(s),a.error)throw Error(a.error.message);b=a.confirmationToken.id}Ue(u,{connectedAccountId:v.payment.connectedAccountId,paymentReference:v.paymentReference});let x=await we(r,{checkout:v,submission:Ve({catalog:t,confirmationToken:b,email:h,fieldValues:o,metadata:l,phone:g,shippingAddress:y})},p);return He(s),We(x,v,h,v.totalCents===0?`Order could not be completed. Review the details and try again.`:`Payment was declined. Check your payment details and try again.`)}function Ke(e,t){f(e,t)}function qe(e,t){f(e,t)}function Je(e,t){return{...e,...t}}function Ye(e,t,n){return e.kind===`unresolved`&&e.reason===`action_required`&&!t&&!n}function Xe(e){return e instanceof m&&e.serverCode===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`}function Ze({nextQuote:e,onQuoteChange:t,setDisplayedTotalCents:n,setPromoError:r,updateState:i,validatePromo:a}){let o=Ie(e,a);i({type:`quote_refresh_succeeded`}),n(o.displayedTotalCents),t(e),a&&r(o.promoError)}function Qe({error:e,setPromoError:t,updateState:n,validatePromo:r}){let i=Le(e,r);r&&t(i.promoError),n(i.paymentError===void 0?{type:`quote_refresh_failed`}:{error:i.paymentError,type:`quote_refresh_failed`})}function $e({onPaymentComplete:e,onPaymentRecoveryChange:t,onPaymentUncertain:n,onQuoteChange:r,result:i,setDisplayedTotalCents:a,dispatchState:o}){if(i.kind===`quote_changed`){let e=`The total changed to ${K(i.quote.totalCents)}. Review it and pay again.`;r(i.quote,e),a(i.quote.totalCents),o({type:`quote_changed`});return}if(i.kind===`payment_failed`){Ke(t,null),o({error:i.message,type:`retryable_failure`});return}if(i.kind===`payment_unresolved`){o({message:`Payment is still processing. Do not submit it again.`,type:`unresolved`}),qe(n,{paymentReference:i.paymentReference,reason:i.reason});return}r(i.quote),Ke(t,null),o({message:i.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),f(e,Je(i.payment,{email:i.email,lineItems:i.quote.lineItems}))}function et(e){let{catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:s,metadata:c,onPaymentComplete:l,onResumePaymentFailed:u,onPaymentRecoveryChange:d,onPaymentUncertain:p,onQuoteChange:h,onStateChange:g,quote:v,resumePayment:b,stripe:x,stripeConnectedAccountId:S,stripeLoadFailed:C,paymentState:E,updateState:D}=e,[O,k]=T(v.totalCents),[A,j]=T(),M=w(!1),N=w(0),P=w(0),F=_(e=>D(e,!0),[D]),I=_(()=>{let e=P.current+1;return P.current=e,()=>P.current===e},[]);y(()=>()=>{P.current+=1,N.current+=1},[]);let{parsedTip:L,totalCents:R}=Fe(t,s,v);y(()=>{R!==null&&(k(R),R>0&&i?.update({amount:R}))},[t.pricingPolicy.serviceFeeRateBasisPoints,t.widget.fields.serviceFee,i,s.includeServiceFee,R,v.serviceFeeCents,v.tipCents,v.totalCents,v.subtotalCents]),y(()=>{if(!b||M.current||E.status!==`recovering`)return;M.current=!0;let e=I();return g(he(E)),Te(r,b.paymentReference,x).then(t=>{if(e()&&!Ye(t,x,C)){if(t.kind===`failed`){Ke(d,null),u(),F({error:`The previous payment failed. Check your details and try again.`,type:`recovery_failed`});return}if(t.kind===`unresolved`){F({message:`Payment is still processing. Do not submit it again.`,type:`unresolved`}),qe(p,{paymentReference:t.paymentReference,reason:t.reason});return}Ke(d,null),F({message:t.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),f(l,Je(t.payment,{email:null,lineItems:null}))}}),()=>{e()&&(P.current+=1),M.current=!1}},[r,l,u,d,p,g,b,x,C,I,F,E]);let ee=_((e=!1,t=!1)=>{t||(N.current+=1),e&&j(void 0),D({type:`field_changed`})},[D]);async function te(e=!1,i=!1){let o=ve({email:a.trim().toLowerCase(),phone:``},!1);if(!(L.success&&(o.value||e)))return;N.current+=1;let c=N.current;D({type:`quote_refresh_started`});try{let e=await r.calculateTotal({...Pe(t,s,o.value?.email??``,L.cents),catalog:t,items:n});if(c!==N.current)return;Ze({nextQuote:e,onQuoteChange:h,setDisplayedTotalCents:k,setPromoError:j,updateState:D,validatePromo:i})}catch(e){if(c!==N.current)return;if(Xe(e)){D({type:`sold_out`});return}Qe({error:e,setPromoError:j,updateState:D,validatePromo:i})}}async function z(){j(void 0),await te(!0,!0)}async function B({addresses:e,phone:u}){F({type:`submission_started`});let f=I();try{let o=await Ge({addresses:e,catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:s,isAttemptActive:f,locallyPreviewedTotalCents:O,metadata:c,onPaymentRecoveryChange:d,phone:u,quote:v,stripe:x,stripeConnectedAccountId:S});if(!f())return;$e({dispatchState:F,onPaymentComplete:l,onPaymentRecoveryChange:d,onPaymentUncertain:p,onQuoteChange:h,result:o,setDisplayedTotalCents:k})}catch(e){if(!f())return;if(Ke(d,null),Xe(e)){F({type:`sold_out`});return}let t=e instanceof m?o(e.serverCode):void 0;if(t)return F({type:`submission_validation_failed`}),{phoneError:t};F({error:e instanceof Error?e.message:`Payment could not be completed.`,type:`retryable_failure`})}}let V=E.status===`succeeded`||E.status===`unresolved`?E.message:void 0;return{commands:{applyPromo:z,fieldChanged:ee,refreshAuthoritativeTotal:te,reportStripeLoadError:e=>F({error:e,type:`retryable_failure`}),reportValidationFailure:()=>F({type:`validation_failed`}),submit:B},state:{displayedTotalCents:O,isRecovering:E.status===`recovering`,isRefreshingQuote:E.status===`refreshing_quote`,isSubmitting:ge(E),parsedTip:L,paymentError:me(E),promoError:A,terminalMessage:V}}}const tt=new Map,nt=(e,t)=>{let n=t?.stripeAccount??null,r=tt.get(e);r||(r=new Map,tt.set(e,r));let i=r.get(n);if(i)return i;let a=j(e,t).catch(()=>(r?.get(n)===a&&(r.delete(n),r.size===0&&tt.delete(e)),null));return r.set(n,a),a};function rt(e){let{connectedAccountId:t,publishableKey:n}=e.payment;return nt(n,t?{stripeAccount:t}:void 0)}function it(e){return e===`monthly`?{interval:`month`,label:`Monthly`}:e===`annually`?{interval:`year`,label:`Annual`}:null}function at(e,t,n){if(n){let{connectedAccountId:e}=n;return e}if(`payment`in t){let{connectedAccountId:e}=t.payment;return e}let{connectedAccountId:r}=e.payment;return r}function ot({accentColor:e,catalog:t,checkoutItems:n,client:r,fontFamily:i,metadata:a,onPaymentComplete:o,onResumePaymentFailed:s,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:u,quote:d,resumePayment:f,onStateChange:p,stripeLoader:m,theme:h,visualStyle:g}){let[v,b]=T(()=>fe(!!f)),x=w(v);x.current=v;let C=_((e,t=!1)=>{let n=pe(x.current,e);n!==x.current&&(x.current=n,b(n),t&&p(he(n)))},[p]),E=at(t,d,f),O=w({connectedAccountId:E,paymentOption:d.paymentOption});v.status!==`submitting`&&v.status!==`recovering`&&(O.current={connectedAccountId:E,paymentOption:d.paymentOption});let{connectedAccountId:k,paymentOption:A}=O.current,j=S(()=>m(t.payment.publishableKey,k?{stripeAccount:k}:void 0).catch(()=>null),[t.payment.publishableKey,k,m]),[M,N]=T(!1);return y(()=>{let e=!0;return N(!1),j.then(t=>{e&&t===null&&N(!0)}),()=>{e=!1}},[j]),U(D,{options:{amount:Math.max(d.totalCents,100),appearance:{rules:{".Input:focus":{borderColor:e,boxShadow:`0 0 0 1px ${e}`,outline:`none`}},theme:h===`light`?`stripe`:`night`,variables:{borderRadius:g?.[`--lockerverse-radius`]??`10px`,colorBackground:g?.[`--lockerverse-control`]??(h===`light`?`#f5f6f7`:`#121212`),colorDanger:g?.[`--lockerverse-danger`]??(h===`light`?`#c52b3e`:`#f08a98`),colorPrimary:e,colorText:g?.[`--lockerverse-text`]??(h===`light`?`#121416`:`#ffffff`),colorTextPlaceholder:g?.[`--lockerverse-placeholder`]??(h===`light`?`#72767d`:`#6b6b6b`),colorTextSecondary:g?.[`--lockerverse-muted`]??(h===`light`?`#62666d`:`#a1a1aa`),focusBoxShadow:`none`,focusOutline:`none`,fontFamily:i,fontSizeBase:`16px`}},currency:t.payment.currency,excludedPaymentMethodTypes:[`us_bank_account`],mode:A===`one-time`?`payment`:`subscription`,syncAddressCheckbox:`none`},stripe:j,children:U(_t,{catalog:t,checkoutItems:n,client:r,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:u,onResumePaymentFailed:s,onStateChange:p,paymentState:v,quote:d,resumePayment:f,stripeConnectedAccountId:k,stripeLoadFailed:M,updateState:C})},`${t.payment.publishableKey}:${k??`platform`}:${A}`)}function st({label:e}){return W(`div`,{className:`lockerverse-payment__stripe-loader`,role:`status`,children:[U(`p`,{children:e}),W(`div`,{"aria-hidden":`true`,children:[U(`span`,{}),U(`span`,{}),U(`span`,{})]})]})}function ct({onError:e,onReady:t,ready:n}){return W(`div`,{className:`lockerverse-payment__stripe-element`,"data-ready":n,children:[n?null:U(st,{label:`Loading payment form...`}),U(`div`,{className:`lockerverse-payment__stripe-mount`,children:U(O,{onLoadError:({error:t})=>e(t.message??`Payment form failed to load.`),onReady:t,options:{business:{name:`Lockerverse`},fields:{billingDetails:{address:`never`,email:`never`,name:`never`,phone:`never`}},layout:`tabs`,terms:{applePay:`auto`,auBecsDebit:`never`,bancontact:`never`,card:`always`,cashapp:`never`,googlePay:`never`,ideal:`never`,paypal:`auto`,sepaDebit:`never`,sofort:`never`,usBankAccount:`never`},wallets:{applePay:`auto`,googlePay:`never`}}})})]})}function lt({label:e,mode:t,onChange:n,onError:r,onReady:i,ready:a}){return W(`div`,{className:`lockerverse-payment__address`,children:[U(`h2`,{children:e}),W(`div`,{className:`lockerverse-payment__stripe-element lockerverse-payment__stripe-element--address`,"data-ready":a,children:[a?null:U(st,{label:`Loading ${e.toLowerCase()}...`}),U(`div`,{className:`lockerverse-payment__stripe-mount`,children:U(E,{onChange:n,onLoadError:({error:t})=>r(t.message??`${e} failed to load.`),onReady:i,options:{autocomplete:{mode:`automatic`},mode:t}})})]})]})}function ut({message:e}){return e?U(`p`,{className:`lockerverse-payment__field-message`,role:`alert`,children:e}):null}function dt({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:i,isShippingAddressReady:a,onAddressChange:o,onFieldValuesChange:s,onStripeLoadError:c,setIsBillingAddressReady:l,setIsPaymentReady:u,setIsShippingAddressReady:d}){let f=t>0;return W(H,{children:[f?U(ct,{onError:c,onReady:()=>u(!0),ready:i}):null,f||e.widget.fields.shipping?U(lt,{label:f?`Billing address`:`Shipping address`,mode:`billing`,onChange:e=>o(`billing`,e),onError:c,onReady:()=>l(!0),ready:r}):null,e.widget.fields.shipping?W(`div`,{className:`lockerverse-payment__shipping`,children:[U(le,{checked:n.shippingMatchesBilling,name:`shippingMatchesBilling`,onChange:e=>{s({...n,shippingMatchesBilling:e}),e?o(`shipping`,null):d(!1)},children:`Shipping is same as billing information`}),n.shippingMatchesBilling?null:U(lt,{label:`Shipping address`,mode:`shipping`,onChange:e=>o(`shipping`,e),onError:c,onReady:()=>d(!0),ready:a})]}):null]})}function ft({displayedBaseCents:e,displayedTipCents:t,displayedTotalCents:n,quote:r}){let i=it(r.paymentOption),a=Math.max(0,e-r.subtotalCents+r.discountCents);return W(`section`,{"aria-label":`Payment summary`,className:`lockerverse-payment__payment-summary`,children:[U(`h2`,{children:`Order summary`}),U(`div`,{className:`lockerverse-payment__payment-summary-items`,children:r.lineItems.map(e=>W(`div`,{className:`lockerverse-payment__payment-summary-row`,children:[W(`span`,{children:[e.productName,e.quantity>1?W(H,{children:[` `,W(`small`,{children:[`× `,e.quantity]})]}):null,e.paymentOption===`monthly`?U(`small`,{children:` · Monthly`}):null,e.paymentOption===`annually`?U(`small`,{children:` · Annual`}):null]}),U(`strong`,{children:K(e.subtotalCents)})]},e.listingId))}),W(`div`,{className:`lockerverse-payment__payment-summary-totals`,children:[a>0?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-detail`,children:[U(`span`,{children:`Service fee`}),U(`strong`,{children:K(a)})]}):null,r.discountCents>0&&r.appliedDiscount?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-discount`,children:[W(`span`,{children:[r.appliedDiscount.source===`email_list`?`Email discount`:`Promo code discount`,` `,`(`,r.appliedDiscount.percentageOff,`% off)`]}),W(`strong`,{children:[`-`,K(r.discountCents)]})]}):null,t>0?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-detail lockerverse-payment__payment-summary-tip`,children:[U(`span`,{children:`Tip`}),U(`strong`,{children:K(t)})]}):null,W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-total`,children:[U(`span`,{children:i?`${i.label} total`:`Total`}),U(`strong`,{children:K(n)})]})]})]})}function pt({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:i,isRequiredShippingReady:a,isSubmitting:o,onFieldValuesChange:s,quote:c}){let l=t===0,u=l?!e.widget.fields.shipping||r&&a:i&&r&&a,d=it(c.paymentOption),f=l?`Complete order`:`Pay ${K(t)}`;!l&&d&&(f=`Subscribe for ${K(t)}/${d.interval}`),o&&(f=l?`Completing…`:`Processing…`);let p=`Process payment for ${K(t)} total`;return l?p=`Complete order`:d&&(p=`Start ${d.label.toLowerCase()} subscription for ${K(t)}`),W(`div`,{className:`lockerverse-payment__actions`,children:[U(de,{amountCents:c.serviceFeeCents||Math.round(c.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4),enabled:e.widget.fields.serviceFee,onChange:s,values:n}),U(`button`,{"aria-busy":o,"aria-label":p,disabled:o||!u,type:`submit`,children:f})]})}function mt(e,t){let n=e.elements.namedItem(t);if(n instanceof HTMLElement){n.focus();return}n instanceof RadioNodeList&&Array.from(n).find(e=>e instanceof HTMLElement)?.focus()}function ht({customFieldErrors:e,emailRef:t,form:n,parsedTipSuccess:r,phoneRef:i,validationErrors:a}){if(a.email){t.current?.focus();return}if(a.phone){i.current?.focus();return}if(!r){n.querySelector(`[name="tip"]`)?.focus();return}let[o]=Object.keys(e);o&&mt(n,`custom:${o}`)}function gt({email:e,emailDiscountPercentOff:t,emailErrorId:n,emailId:r,emailRef:i,errors:a,onEmailBlur:o,onEmailChange:s,onPhoneChange:c,onPhoneCountryChange:u,phone:d,phoneCountry:f,phoneEnabled:p,phoneErrorId:m,phoneId:h,phoneRef:g}){return W(`div`,{className:`lockerverse-payment__contact`,children:[U(`label`,{htmlFor:r,children:`Email`}),U(`input`,{"aria-describedby":a.email?n:void 0,"aria-invalid":a.email?`true`:void 0,autoComplete:`email`,id:r,name:`email`,onBlur:o,onChange:e=>s(e.currentTarget.value),placeholder:`name@example.com`,ref:i,type:`email`,value:e}),a.email?U(`p`,{className:`lockerverse-payment__field-message`,id:n,children:a.email}):null,t===void 0?null:W(`p`,{className:`lockerverse-payment__discount-message`,role:`status`,children:[`Your email qualifies for `,t,`% off.`]}),p?W(H,{children:[U(`label`,{htmlFor:h,children:`Phone`}),W(`div`,{className:`lockerverse-payment__phone-control`,children:[U(Y,{ariaLabel:`Phone number country`,className:`lockerverse-payment__select--phone-country`,name:`phoneCountry`,onValueChange:u,options:l,value:f}),U(`input`,{"aria-describedby":a.phone?m:void 0,"aria-invalid":a.phone?`true`:void 0,autoComplete:`tel`,id:h,inputMode:`tel`,name:`phone`,onChange:e=>c(e.currentTarget.value),placeholder:`(201) 555-0123`,ref:g,type:`tel`,value:d})]}),a.phone?U(`p`,{className:`lockerverse-payment__field-message`,id:m,children:a.phone}):null]}):null]})}function _t({catalog:e,checkoutItems:t,client:n,metadata:r,onPaymentComplete:i,onResumePaymentFailed:a,onPaymentRecoveryChange:o,onPaymentUncertain:s,onQuoteChange:l,onStateChange:f,quote:p,resumePayment:m,stripeConnectedAccountId:h,stripeLoadFailed:g,paymentState:_,updateState:v}){let[x,S]=T(``),[C,E]=T(``),[D,O]=T(`US`),[j,M]=T({}),[N,P]=T({}),[F,I]=T(),[L,R]=T(!1),[ee,te]=T(!1),[z,B]=T(!1),[V,ne]=T({customFields:u(e.widget.customFields),customTip:``,includeServiceFee:e.widget.fields.serviceFee,memberId:``,merchSize:`M`,promoCode:``,shippingMatchesBilling:!0,tipPercent:`10`}),re=w({billing:null,shipping:null}),H=w(null),G=w(null),ie=w(null),K=w(p.totalCents>0),q=et({catalog:e,checkoutItems:t,client:n,elements:k(),email:x,fieldValues:V,metadata:r,onPaymentComplete:i,onPaymentRecoveryChange:o,onPaymentUncertain:s,onQuoteChange:l,onResumePaymentFailed:a,onStateChange:f,paymentState:_,quote:p,resumePayment:m,stripe:A(),stripeConnectedAccountId:h,stripeLoadFailed:g,updateState:v}),{displayedTotalCents:J,isRecovering:ae,isRefreshingQuote:oe,isSubmitting:Y,parsedTip:X,paymentError:se,promoError:Z,terminalMessage:le}=q.state,de=`lockerverse-${b()}`,fe=`${de}-email`,Q=`${fe}-error`,pe=`${de}-phone`,me=`${pe}-error`,he=`${de}-tip-error`,ge=(X.success?X.cents:null)??0,_e=J-ge,ye=!e.widget.fields.shipping||V.shippingMatchesBilling||z;y(()=>{Y&&ie.current?.focus({preventScroll:!0})},[Y]),y(()=>{Y||j.email||!j.phone||G.current?.focus()},[j.email,j.phone,Y]),y(()=>{let e=J>0;e&&!K.current&&(R(!1),te(!1)),K.current=e},[J]);function be(e){q.commands.fieldChanged(!1,e!==`email`),M(t=>{let n={...t};return delete n[e],n})}function xe(e){let t=e.promoCode!==V.promoCode,n=e.includeServiceFee!==V.includeServiceFee;q.commands.fieldChanged(t,!(t||n)),ne(e),P({}),I(void 0)}async function Se(t){t.preventDefault();let n=d(C,D),r=ve({email:x,phone:n},e.widget.fields.phone),i=c(e.widget.customFields,V.customFields);if(!(r.value&&X.success)||Object.keys(i).length>0){M(r.errors),P(i),I(X.success?void 0:X.message),q.commands.reportValidationFailure();let e=t.currentTarget;queueMicrotask(()=>{ht({customFieldErrors:i,emailRef:H,form:e,parsedTipSuccess:X.success,phoneRef:G,validationErrors:r.errors})});return}M({}),P({});let a=await q.commands.submit({addresses:re.current,phone:n});a?.phoneError&&M({phone:a.phoneError})}return le?U(`p`,{className:`lockerverse-payment__payment-status`,ref:ie,role:`status`,tabIndex:-1,children:le}):ae?U(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:`Recovering payment…`}):W(`form`,{"aria-busy":Y,className:`lockerverse-payment__form`,noValidate:!0,onSubmit:Se,children:[U(`div`,{"data-lockerverse-input-region":``,inert:Y?!0:void 0,children:W(`fieldset`,{className:`lockerverse-payment__input-fieldset`,disabled:Y,children:[U(ft,{displayedBaseCents:_e,displayedTipCents:ge,displayedTotalCents:J,quote:p}),U(ce,{enabled:e.widget.fields.tipping,error:F,errorId:he,onChange:xe,values:V}),U(gt,{email:x,emailDiscountPercentOff:p.appliedDiscount?.source===`email_list`?p.appliedDiscount.percentageOff:void 0,emailErrorId:Q,emailId:fe,emailRef:H,errors:j,onEmailBlur:()=>q.commands.refreshAuthoritativeTotal(),onEmailChange:e=>{S(e),be(`email`)},onPhoneChange:e=>{E(e),be(`phone`)},onPhoneCountryChange:e=>{O(e),q.commands.fieldChanged(!1,!0),requestAnimationFrame(()=>G.current?.focus())},phone:C,phoneCountry:D,phoneEnabled:e.widget.fields.phone,phoneErrorId:me,phoneId:pe,phoneRef:G}),U(dt,{catalog:e,displayedTotalCents:J,fieldValues:V,isBillingAddressReady:ee,isPaymentReady:L,isShippingAddressReady:z,onAddressChange:(e,t)=>{re.current[e]=t},onFieldValuesChange:xe,onStripeLoadError:q.commands.reportStripeLoadError,setIsBillingAddressReady:te,setIsPaymentReady:R,setIsShippingAddressReady:B}),U(ue,{customFields:e.widget.customFields,errors:N,fields:e.widget.fields,idPrefix:de,isPromoApplying:oe,onApplyPromo:q.commands.applyPromo,onChange:xe,promoError:Z,values:V}),U(pt,{catalog:e,displayedTotalCents:J,fieldValues:V,isBillingAddressReady:ee,isPaymentReady:L,isRequiredShippingReady:ye,isSubmitting:Y,onFieldValuesChange:xe,quote:p})]})}),Y?U(`p`,{className:`lockerverse-payment__sr-only`,ref:ie,role:`status`,tabIndex:-1,children:J===0?`Completing order…`:`Processing payment…`}):null,U(ut,{message:se})]})}function vt(){return U(p,{fieldCount:2,label:`Loading payment…`,sectionCount:2,showCheckbox:!0})}function yt(e,t){switch(t.type){case`loading`:return{phase:`loading`,revision:e.revision};case`ready`:return St(t.displayedQuote,e.revision+1);case`error`:return{failure:t.failure,phase:`error`,revision:e.revision};case`checkout`:return e.phase===`ready`?{...e,displayedQuote:t.checkout,quoteFailure:void 0}:e;case`quote-error`:return e.phase===`ready`?{...e,quoteFailure:t.failure}:e;default:return e}}function $(e,t){return e===t}function bt({checkout:e}){return{displayedQuote:e,type:`ready`}}function xt(e){return e instanceof Error?e.message:`Lockerverse payment could not load.`}function St(e,t){return{checkoutItems:[...e.items],displayedQuote:e,phase:`ready`,quoteFailure:void 0,revision:t}}function Ct(e,t){let n=e.widget.fields.serviceFee;return h(e,{includeServiceFee:n,selection:t})}function wt(e,t){try{return St(Ct(e,t),1)}catch(e){return{failure:xt(e),phase:`error`,revision:0}}}function Tt({catalog:e,client:t,paymentState:n,selection:r}){let i=je(r),a=i.success?JSON.stringify(i.value):`invalid-selection`,o=S(()=>i.success?i.value:[],[i.success,a]),[s,c]=C(yt,void 0,()=>i.success?wt(e,o):{phase:`loading`,revision:0}),l=w(void 0),u=w(0),d=w(s.phase===`ready`?a:void 0),f=w(s.phase===`error`?a:void 0),p=n===`submitting`||n===`success`||n===`unresolved`;y(()=>{if(!i.success||p||$(f.current,a)||$(l.current,a))return;let n=!0;l.current=a;let r=d.current===a;r||c({type:`loading`});function s(e){n&&c(e)}function m(){n&&(l.current=void 0,f.current=a)}let h;function g(e){if(!n||(l.current=void 0,f.current=a,r&&h!==void 0&&u.current!==h))return;let t=xt(e);if(t===`This option is sold out.`){c({failure:t,type:`error`});return}c(r?{failure:t,type:`quote-error`}:{failure:t,type:`error`})}async function _(){try{h=u.current;let n=e.widget.fields.serviceFee;if(!r){let t=Ct(e,o);r=!0,d.current=a,s(bt({checkout:t}))}let i=await t.calculateTotal({catalog:e,includeServiceFee:n,selection:o});m(),u.current===h&&s({checkout:i,type:`checkout`})}catch(e){g(e)}}return _(),()=>{n=!1,$(l.current,a)&&(l.current=void 0)}},[e,t,i.success,p,a,o]);let m=$(d.current,a)||$(f.current,a)||$(l.current,a),h=p||m?s:{phase:`loading`,revision:s.revision};return{selectionError:i.success?void 0:i.message,session:h,updateCheckout:e=>{u.current+=1,c({checkout:e,type:`checkout`})}}}function Et(e,t){let n=i(e?.[`--lockerverse-accent`]??t?.accentColor??`#38d77a`),r=a(n),o={...e};return(e?.[`--lockerverse-accent`]!==void 0||t?.accentColor)&&(o[`--lockerverse-accent`]=n),r&&e?.[`--lockerverse-accent-contrast`]===void 0&&(o[`--lockerverse-accent-contrast`]=r),{accent:n,rootStyle:o}}function Dt({catalog:e,client:t,...n}){let{branding:r,className:i,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:s,onPaymentUncertain:c,resumePayment:l,selection:u,style:d,stripeLoader:f=nt,theme:p=`dark`,...m}=n,[h,g]=T(l),v=w(null),[b,S]=T(),[C,E]=T(`idle`),D=w(void 0),{selectionError:O,session:k,updateCheckout:A}=Tt({catalog:e,client:t,paymentState:C,selection:u}),j=k.phase===`ready`?k.revision:void 0,M=_(e=>{j!==void 0&&(D.current=j),E(e)},[j]),N=_(e=>s?.(e),[s]),P=_(()=>{g(void 0)},[]);y(()=>{k.phase===`loading`&&S(void 0)},[k.phase]),x(()=>{k.phase===`ready`&&D.current!==k.revision&&E(e=>e===`success`||e===`unresolved`?e:`idle`)},[k.phase,k.revision]);let F=[`lockerverse-payment`,i].filter(Boolean).join(` `),I=r??e.community,{accent:L,rootStyle:R}=Et(d,I);return O?U(`section`,{...m,className:F,"data-lockerverse-theme":p,role:`alert`,style:R,children:O}):k.phase===`error`&&k.failure===`This option is sold out.`||C===`sold_out`?W(`section`,{...m,className:F,"data-lockerverse-theme":p,role:`alert`,style:R,children:[U(`h1`,{children:`Sold out`}),U(`p`,{children:`This option is sold out.`})]}):k.phase===`error`?U(`section`,{...m,className:F,"data-lockerverse-theme":p,style:R,children:U(`p`,{role:`alert`,children:k.failure})}):k.phase===`ready`?W(`section`,{...m,"aria-label":`Payment`,className:F,"data-lockerverse-theme":p,"data-payment-state":C,ref:v,style:R,children:[W(`header`,{children:[e.widget.showCommunityBranding&&I?W(`div`,{className:`lockerverse-payment__branding`,children:[I.imageUrl?U(`img`,{alt:I.name,height:`48`,src:I.imageUrl,width:`48`}):null,U(`strong`,{children:I.name})]}):null,U(`h1`,{children:e.widget.title??e.widget.name}),e.widget.description?U(`p`,{children:e.widget.description}):null]}),b?U(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:b}):null,k.quoteFailure?W(`div`,{className:`lockerverse-payment__payment-status`,role:`alert`,children:[U(`span`,{children:k.quoteFailure}),U(`span`,{children:` The final total will be checked when you submit.`})]}):null,U(J,{container:v,children:U(ot,{accentColor:L,catalog:e,checkoutItems:k.checkoutItems,client:t,fontFamily:d?.[`--lockerverse-font-family`]??`ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:N,onPaymentUncertain:c,onQuoteChange:(e,t)=>{S(t),A(e)},onResumePaymentFailed:P,onStateChange:M,quote:k.displayedQuote,resumePayment:h,stripeLoader:f,theme:p,visualStyle:R},k.revision)})]}):U(`section`,{...m,"aria-busy":`true`,"aria-label":`Payment`,className:F,"data-lockerverse-theme":p,style:R,children:U(vt,{})})}function Ot({children:e,loading:t=!1,viewProps:n}){let{branding:r,className:o,metadata:s,onPaymentComplete:c,onPaymentRecoveryChange:l,onPaymentUncertain:u,resumePayment:d,selection:f,stripeLoader:p,style:m,theme:h=`dark`,...g}=n,_=i(m?.[`--lockerverse-accent`]??r?.accentColor??`#38d77a`),v=a(_),y={...m};return(m?.[`--lockerverse-accent`]!==void 0||r?.accentColor)&&(y[`--lockerverse-accent`]=_),v&&m?.[`--lockerverse-accent-contrast`]===void 0&&(y[`--lockerverse-accent-contrast`]=v),U(`section`,{...g,...t?{"aria-busy":!0,"aria-label":`Payment`}:{},className:[`lockerverse-payment`,o].filter(Boolean).join(` `),"data-lockerverse-theme":h,style:y,children:e})}function kt({widget:e,...t}){return e.error?W(Ot,{viewProps:t,children:[U(`p`,{role:`alert`,children:e.error.message}),U(`button`,{onClick:e.refresh,type:`button`,children:`Retry`})]}):e.loading||!e.catalog?U(Ot,{loading:!0,viewProps:t,children:U(vt,{})}):U(Dt,{catalog:e.catalog,client:e.client,...t})}export{rt as n,kt as t};
1
+ import{c as e,i as t,s as n,t as r}from"./host-callback.js";import{t as i}from"./format-money.js";import{a,c as o,i as s,l as c,n as l,o as u,r as d,s as f,t as p,u as m}from"./phone.js";import{AddressElement as h,Elements as g,PaymentElement as _,useElements as v,useStripe as y}from"@stripe/react-stripe-js";import{loadStripe as b}from"@stripe/stripe-js/pure/index.js";import{createContext as x,useCallback as S,useContext as C,useEffect as w,useId as T,useLayoutEffect as E,useMemo as D,useReducer as O,useRef as k,useState as A}from"react";import{array as j,minLength as M,minValue as N,nonEmpty as P,number as F,object as I,pipe as L,regex as R,safeInteger as z,safeParse as B,strictObject as V,string as ee,trim as H,union as te}from"valibot";import{Fragment as ne,jsx as U,jsxs as W}from"react/jsx-runtime";import{LockerverseSdkError as re,estimateLockerverseCheckout as ie}from"@lockerverse/sdk/checkout";import{Select as G}from"@base-ui/react/select";const ae=x(void 0);function K({children:e,container:t}){return U(ae.Provider,{value:t,children:e})}function q(){return U(`svg`,{"aria-hidden":`true`,fill:`none`,viewBox:`0 0 16 16`,children:U(`path`,{d:`m4 6 4 4 4-4`})})}function oe(){return U(`svg`,{"aria-hidden":`true`,fill:`none`,viewBox:`0 0 16 16`,children:U(`path`,{d:`m3 8 3 3 7-7`})})}function se({ariaDescribedBy:e,ariaLabel:t,ariaLabelledBy:n,className:r,id:i,invalid:a=!1,name:o,onValueChange:s,options:c,value:l}){let u=C(ae),d=[`lockerverse-payment__select`,r].filter(Boolean).join(` `);return U(`div`,{className:d,children:W(G.Root,{id:i,items:c,name:o,onValueChange:e=>{e!==null&&s(e)},value:l,children:[W(G.Trigger,{"aria-describedby":e,"aria-invalid":a||void 0,"aria-label":t,"aria-labelledby":n,className:`lockerverse-payment__select-trigger`,children:[U(G.Value,{}),U(G.Icon,{"aria-hidden":`true`,className:`lockerverse-payment__select-icon`,children:U(q,{})})]}),U(G.Portal,{container:u,children:U(G.Positioner,{alignItemWithTrigger:!1,className:`lockerverse-payment__select-positioner`,sideOffset:6,children:U(G.Popup,{className:`lockerverse-payment__select-popup`,children:U(G.List,{className:`lockerverse-payment__select-list`,children:c.map(e=>W(G.Item,{className:`lockerverse-payment__select-item`,value:e.value,children:[U(G.ItemText,{children:e.label}),U(G.ItemIndicator,{"aria-hidden":`true`,className:`lockerverse-payment__select-item-indicator`,children:U(oe,{})})]},e.value))})})})})]})})}const J=[`XS`,`S`,`M`,`L`,`XL`,`XXL`,`XXXL`],Y=[`15`,`12`,`10`,`5`],X=[...Y,`custom`];function ce({enabled:e,error:t,errorId:n,onChange:r,values:i}){if(!e)return null;let a=e=>r({...i,...e}),o=(e,t)=>{let n=X.indexOf(t),r;switch(e.key){case`ArrowDown`:case`ArrowRight`:r=(n+1)%X.length;break;case`ArrowLeft`:case`ArrowUp`:r=(n-1+X.length)%X.length;break;case`Home`:r=0;break;case`End`:r=X.length-1;break;default:return}e.preventDefault();let i=X[r];i&&((e.currentTarget.closest(`[role="radiogroup"]`)?.querySelectorAll(`input[type="radio"]`))?.[r]?.focus(),a({tipPercent:i}))};return W(`div`,{className:`lockerverse-payment__tip-box`,children:[U(`p`,{children:`Add a tip to support the Lockerverse platform`}),W(`div`,{"aria-label":`Tip amount`,role:`radiogroup`,children:[Y.map(e=>W(`label`,{className:`lockerverse-payment__tip-choice`,children:[U(`input`,{checked:i.tipPercent===e,name:`tipPercent`,onChange:()=>a({tipPercent:e}),onKeyDown:t=>o(t,e),tabIndex:i.tipPercent===e?0:-1,type:`radio`,value:e}),W(`span`,{children:[e,`%`]})]},e)),W(`label`,{className:`lockerverse-payment__tip-choice`,children:[U(`input`,{checked:i.tipPercent===`custom`,name:`tipPercent`,onChange:()=>a({tipPercent:`custom`}),onKeyDown:e=>o(e,`custom`),tabIndex:i.tipPercent===`custom`?0:-1,type:`radio`,value:`custom`}),U(`span`,{children:`Other`})]})]}),i.tipPercent===`custom`?W(`label`,{children:[U(`span`,{children:`Custom tip`}),W(`span`,{className:`lockerverse-payment__money-input`,children:[U(`span`,{"aria-hidden":`true`,children:`$`}),U(`input`,{"aria-describedby":t?n:void 0,"aria-invalid":t?`true`:void 0,inputMode:`decimal`,name:`tip`,onChange:e=>a({customTip:e.currentTarget.value}),placeholder:`0.00`,value:i.customTip})]}),t?U(`span`,{className:`lockerverse-payment__field-message`,id:n,children:t}):null]}):U(`input`,{name:`tip`,type:`hidden`,value:i.tipPercent})]})}function le({checked:e,children:t,name:n,onChange:r}){return W(`label`,{className:`lockerverse-payment__check-row`,children:[U(`input`,{checked:e,name:n,onChange:e=>r(e.currentTarget.checked),type:`checkbox`}),U(`span`,{children:t})]})}function ue({customFields:e,errors:t,fields:n,idPrefix:r,isPromoApplying:i,memberIdLabel:o,onChange:s,onApplyPromo:c,promoError:l,values:u}){let d=e=>s({...u,...e});return W(`div`,{className:`lockerverse-payment__additional-fields`,children:[n.memberId?W(`label`,{children:[U(`span`,{children:o?.trim()||`Member ID`}),U(`input`,{name:`memberId`,onChange:e=>d({memberId:e.currentTarget.value}),placeholder:`Optional`,value:u.memberId})]}):null,n.merchSize?W(`div`,{className:`lockerverse-payment__field`,children:[U(`span`,{id:`${r}-merch-size-label`,children:`Size`}),U(se,{ariaLabelledBy:`${r}-merch-size-label`,name:`merchSize`,onValueChange:e=>{let t=J.find(t=>t===e);t&&d({merchSize:t})},options:J.map(e=>({label:e,value:e})),value:u.merchSize})]}):null,n.promoCode?W(`div`,{className:`lockerverse-payment__field`,children:[U(`span`,{id:`${r}-promo-code-label`,children:`Promo code`}),W(`div`,{className:`lockerverse-payment__promo-control`,children:[U(`input`,{"aria-describedby":l?`${r}-promo-code-error`:void 0,"aria-invalid":l?`true`:void 0,"aria-labelledby":`${r}-promo-code-label`,name:`promoCode`,onChange:e=>d({promoCode:e.currentTarget.value}),placeholder:`Optional`,value:u.promoCode}),U(`button`,{disabled:!u.promoCode.trim()||i,onClick:c,type:`button`,children:i?`Applying…`:`Apply`})]}),l?U(`p`,{className:`lockerverse-payment__field-message`,id:`${r}-promo-code-error`,role:`alert`,children:l}):null]}):null,U(a,{choiceClassName:`lockerverse-payment__check-row`,errorClassName:`lockerverse-payment__field-message`,errors:t,fields:e,idPrefix:r,onChange:e=>d({customFields:e}),values:u.customFields})]})}function de({amountCents:e,enabled:t,onChange:n,values:r}){return t?W(le,{checked:r.includeServiceFee,name:`includeServiceFee`,onChange:e=>n({...r,includeServiceFee:e}),children:[`Add `,i(e),` to help cover processing fees`]}):null}function fe(e){return{error:void 0,message:void 0,status:e?`recovering`:`editing`}}function Z(e,t,n){return t.includes(e.status)?{...e,...n}:e}function pe(e,t){if(e.status===`sold_out`||e.status===`succeeded`||e.status===`unresolved`)return e;switch(t.type){case`field_changed`:return Z(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`editing`});case`validation_failed`:return Z(e,[`editing`],{status:`invalid`});case`quote_refresh_started`:return Z(e,[`editing`,`invalid`],{status:`refreshing_quote`});case`quote_refresh_succeeded`:return Z(e,[`refreshing_quote`],{error:void 0,status:`editing`});case`quote_refresh_failed`:return Z(e,[`refreshing_quote`],{error:t.error??e.error,status:`editing`});case`submission_started`:return Z(e,[`editing`,`invalid`,`refreshing_quote`],{error:void 0,status:`submitting`});case`submission_validation_failed`:return Z(e,[`submitting`],{error:void 0,status:`invalid`});case`quote_changed`:return Z(e,[`submitting`],{status:`editing`});case`retryable_failure`:return Z(e,[`editing`,`invalid`,`submitting`],{error:t.error,status:`editing`});case`recovery_failed`:return Z(e,[`recovering`],{error:t.error,status:`editing`});case`sold_out`:return{error:void 0,message:void 0,status:`sold_out`};case`succeeded`:return Z(e,[`recovering`,`submitting`],{message:t.message,status:`succeeded`});case`unresolved`:return Z(e,[`recovering`,`submitting`],{message:t.message,status:`unresolved`});default:return e}}function me(e){return e.status===`editing`||e.status===`invalid`||e.status===`refreshing_quote`?e.error:void 0}function he(e){return e.status===`sold_out`?`sold_out`:e.status===`succeeded`?`success`:e.status===`unresolved`?`unresolved`:e.status===`submitting`||e.status===`recovering`?`submitting`:e.status===`invalid`?`invalid`:me(e)?`error`:`idle`}function ge(e){return e.status===`submitting`}function _e(e){return t(e)}function ve(t,r){let i=r?{...t,phone:_e(t.phone)}:t,a=I(r?{email:n,phone:e}:{email:n}),o=B(a,i);if(o.success)return{errors:{},value:o.output};let s={};for(let e of o.issues){let t=e.path?.[0]?.key;(t===`email`||t===`phone`)&&!s[t]&&(s[t]=e.message)}return{errors:s,value:null}}const ye=[`amountCents`,`discountableSubtotalCents`,`discountCents`,`serviceFeeCents`,`subtotalCents`,`tipCents`,`totalCents`],be=[`discountableSubtotalCents`,`discountCents`,`subtotalCents`];function xe(e,t,n,r){return(n===t.totalCents?be:ye).some(n=>e[n]!==t[n])||r!==t.payment.connectedAccountId||e.authoritative&&(e.payment.connectedAccountId!==r||e.payment.currency!==t.payment.currency)||JSON.stringify(e.appliedDiscount)!==JSON.stringify(t.appliedDiscount)||JSON.stringify(e.lineItems)!==JSON.stringify(t.lineItems)}function Q(e){return e.checkoutStatus===`success`?{kind:`success`,payment:e}:e.checkoutStatus===`failed`?{kind:`failed`,payment:e}:{kind:`unresolved`,paymentReference:e.paymentReference,reason:e.checkoutStatus===`action_required`?`action_required`:`pending`}}async function Se(e,t,n){if(t.checkoutStatus!==`action_required`)return Q(t);if(!n)return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`};if(t.clientSecret)try{await n.handleNextAction({clientSecret:t.clientSecret})}catch{}try{return Q(await e.getPaymentStatus(t.paymentReference))}catch{return{kind:`unresolved`,paymentReference:t.paymentReference,reason:`action_required`}}}async function Ce(e,t,n){let r;try{r=await e.submitPayment(t)}catch(n){if(!(n instanceof re&&n.recoveryRecommended))throw n;try{r=await e.getPaymentStatus(t.checkout.paymentReference)}catch{return{kind:`unresolved`,paymentReference:t.checkout.paymentReference,reason:`recovery_failed`}}}return Se(e,r,n)}async function we(e,t,n){try{return Se(e,await e.getPaymentStatus(t),n)}catch{return{kind:`unresolved`,paymentReference:t,reason:`recovery_failed`}}}const Te=L(ee(),H(),P()),Ee=L(F(),z(),N(1)),De=L(j(te([V({amountCents:Ee,productSlug:Te}),V({productSlug:Te,quantity:Ee}),V({productSlug:Te})])),M(1)),Oe=L(ee(),H(),R(/^(?:0|[1-9]\d*)(?:\.\d{1,2})?$/,`Enter a valid tip amount.`));function ke(e){let t=B(Oe,e);if(!t.success)return{message:t.issues[0]?.message??`Enter a valid tip amount.`,success:!1};let[n=`0`,r=``]=t.output.split(`.`),i=BigInt(n)*100n+BigInt(r.padEnd(2,`0`));return i>BigInt(2**53-1)?{message:`Enter a valid tip amount.`,success:!1}:{cents:Number(i),success:!0}}function Ae(e){let t=B(De,e);return t.success?{success:!0,value:t.output}:{message:`Lockerverse payment configuration is invalid.`,success:!1}}const je=`This promo code is invalid or cannot be applied.`;function Me(e,t){return t.tipPercent===`custom`?t.customTip.trim()?ke(t.customTip):{cents:0,success:!0}:{cents:Math.round(e*Number(t.tipPercent)/100),success:!0}}function Ne(e,t,n,r){let i={};return n&&(i.email=n),e.widget.fields.serviceFee&&(i.includeServiceFee=t.includeServiceFee),e.widget.fields.promoCode&&t.promoCode.trim()&&(i.promoCode=t.promoCode.trim()),e.widget.fields.tipping&&(i.tipCents=r),i}function Pe(e,t,n){let r=e.widget.fields.tipping?Me(n.subtotalCents,t):{cents:0,success:!0};if(!r.success)return{parsedTip:r,totalCents:null};let i=e.widget.fields.serviceFee&&t.includeServiceFee?n.serviceFeeCents||Math.round(n.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4):0;return{parsedTip:r,totalCents:n.totalCents-n.serviceFeeCents-n.tipCents+i+r.cents}}function Fe(e,t){return{displayedTotalCents:e.totalCents,promoError:t&&e.appliedDiscount?.source!==`promo_code`?je:void 0}}function Ie(e,t){let n;return t||(n=e instanceof Error?e.message:`The order total could not be updated.`),{paymentError:n,promoError:t?je:void 0}}function Le(e,t){if(!e?.complete)throw Error(`${t} address is required.`);return e.value}function Re(e,t,n,r){if(e.widget.fields.shipping)return t.shippingMatchesBilling?n:Le(r.shipping,`Shipping`)}function ze({billingAddress:e,catalog:t,email:n,phone:r,shippingAddress:i}){let a={payment_method_data:{billing_details:t.widget.fields.phone?{address:e.address,email:n,name:e.name,phone:r}:{address:e.address,email:n,name:e.name}}};return i?{...a,shipping:{address:i.address,name:i.name,phone:t.widget.fields.phone?r:i.phone??null}}:a}function Be({catalog:e,confirmationToken:t,email:n,fieldValues:r,metadata:i,phone:a,shippingAddress:o}){let s={customFieldAnswers:u(e.widget.customFields,r.customFields),email:n};if(t&&(s.confirmationToken=t),i&&(s.metadata=i),e.widget.fields.memberId&&r.memberId.trim()&&(s.memberId=r.memberId.trim()),e.widget.fields.merchSize&&(s.merchSize=r.merchSize),e.widget.fields.phone&&(s.phone=a),o){let e={city:o.address.city??``,country:o.address.country,line1:o.address.line1??``,postal_code:o.address.postal_code??``,state:o.address.state??``};o.address.line2&&(e.line2=o.address.line2),s.shipping={address:e,name:o.name}}return s}function Ve(e){if(!e())throw Error(`Payment component is no longer active.`)}function He(e,t){r(e,t)}function Ue(e,t,n,r){return e.kind===`failed`?{kind:`payment_failed`,message:r}:e.kind===`unresolved`?{kind:`payment_unresolved`,paymentReference:e.paymentReference,reason:e.reason}:{email:n,kind:`payment`,payment:e.payment,quote:t}}async function We({addresses:e,catalog:t,checkoutItems:n,client:r,elements:i,email:a,fieldValues:o,isAttemptActive:s,locallyPreviewedTotalCents:c,metadata:l,onPaymentRecoveryChange:u,phone:d,quote:f,stripe:p,stripeConnectedAccountId:m}){let h=a.trim().toLowerCase(),g=_e(d),_=Me(f.subtotalCents,o);if(!_.success)throw Error(_.message);let v=await r.calculateTotal({...Ne(t,o,h,_.cents),catalog:t,items:n});if(Ve(s),v.totalCents>0&&xe(f,v,c,m))return{kind:`quote_changed`,quote:v};let y,b;if(v.totalCents===0)t.widget.fields.shipping&&(y=Re(t,o,Le(e.billing,`Billing`),e));else{if(!(i&&p))throw Error(`Payment form is still loading.`);await i.update({amount:v.totalCents}),Ve(s);let n=await i.submit();if(Ve(s),n.error)throw Error(n.error.message);let r=Le(e.billing,`Billing`);y=Re(t,o,r,e);let a=await p.createConfirmationToken({elements:i,params:ze({billingAddress:r,catalog:t,email:h,phone:g,shippingAddress:y})});if(Ve(s),a.error)throw Error(a.error.message);b=a.confirmationToken.id}He(u,{connectedAccountId:v.payment.connectedAccountId,paymentReference:v.paymentReference});let x=await Ce(r,{checkout:v,submission:Be({catalog:t,confirmationToken:b,email:h,fieldValues:o,metadata:l,phone:g,shippingAddress:y})},p);return Ve(s),Ue(x,v,h,v.totalCents===0?`Order could not be completed. Review the details and try again.`:`Payment was declined. Check your payment details and try again.`)}function Ge(e,t){r(e,t)}function Ke(e,t){r(e,t)}function qe(e,t){return{...e,...t}}function Je(e,t,n){return e.kind===`unresolved`&&e.reason===`action_required`&&!t&&!n}function Ye(e){return e instanceof re&&e.serverCode===`PAYMENT_WIDGET_SALES_LIMIT_REACHED`}function Xe({nextQuote:e,onQuoteChange:t,setDisplayedTotalCents:n,setPromoError:r,updateState:i,validatePromo:a}){let o=Fe(e,a);i({type:`quote_refresh_succeeded`}),n(o.displayedTotalCents),t(e),a&&r(o.promoError)}function Ze({error:e,setPromoError:t,updateState:n,validatePromo:r}){let i=Ie(e,r);r&&t(i.promoError),n(i.paymentError===void 0?{type:`quote_refresh_failed`}:{error:i.paymentError,type:`quote_refresh_failed`})}function Qe({onPaymentComplete:e,onPaymentRecoveryChange:t,onPaymentUncertain:n,onQuoteChange:a,result:o,setDisplayedTotalCents:s,dispatchState:c}){if(o.kind===`quote_changed`){let e=`The total changed to ${i(o.quote.totalCents)}. Review it and pay again.`;a(o.quote,e),s(o.quote.totalCents),c({type:`quote_changed`});return}if(o.kind===`payment_failed`){Ge(t,null),c({error:o.message,type:`retryable_failure`});return}if(o.kind===`payment_unresolved`){c({message:`Payment is still processing. Do not submit it again.`,type:`unresolved`}),Ke(n,{paymentReference:o.paymentReference,reason:o.reason});return}a(o.quote),Ge(t,null),c({message:o.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),r(e,qe(o.payment,{email:o.email,lineItems:o.quote.lineItems}))}function $e(e){let{catalog:t,checkoutItems:n,client:i,elements:a,email:o,fieldValues:s,metadata:c,onPaymentComplete:l,onResumePaymentFailed:u,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,onStateChange:h,quote:g,resumePayment:_,stripe:v,stripeConnectedAccountId:y,stripeLoadFailed:b,paymentState:x,updateState:C}=e,[T,E]=A(g.totalCents),[D,O]=A(),j=k(!1),M=k(0),N=k(0),P=S(e=>C(e,!0),[C]),F=S(()=>{let e=N.current+1;return N.current=e,()=>N.current===e},[]);w(()=>()=>{N.current+=1,M.current+=1},[]);let{parsedTip:I,totalCents:L}=Pe(t,s,g);w(()=>{L!==null&&(E(L),L>0&&a?.update({amount:L}))},[t.pricingPolicy.serviceFeeRateBasisPoints,t.widget.fields.serviceFee,a,s.includeServiceFee,L,g.serviceFeeCents,g.tipCents,g.totalCents,g.subtotalCents]),w(()=>{if(!_||j.current||x.status!==`recovering`)return;j.current=!0;let e=F();return h(he(x)),we(i,_.paymentReference,v).then(t=>{if(e()&&!Je(t,v,b)){if(t.kind===`failed`){Ge(f,null),u(),P({error:`The previous payment failed. Check your details and try again.`,type:`recovery_failed`});return}if(t.kind===`unresolved`){P({message:`Payment is still processing. Do not submit it again.`,type:`unresolved`}),Ke(p,{paymentReference:t.paymentReference,reason:t.reason});return}Ge(f,null),P({message:t.payment.paymentRequired?`Payment completed successfully.`:`Order confirmed. No payment was required.`,type:`succeeded`}),r(l,qe(t.payment,{email:null,lineItems:null}))}}),()=>{e()&&(N.current+=1),j.current=!1}},[i,l,u,f,p,h,_,v,b,F,P,x]);let R=S((e=!1,t=!1)=>{t||(M.current+=1),e&&O(void 0),C({type:`field_changed`})},[C]);async function z(e=!1,r=!1){let a=ve({email:o.trim().toLowerCase(),phone:``},!1);if(!(I.success&&(a.value||e)))return;M.current+=1;let c=M.current;C({type:`quote_refresh_started`});try{let e=await i.calculateTotal({...Ne(t,s,a.value?.email??``,I.cents),catalog:t,items:n});if(c!==M.current)return;Xe({nextQuote:e,onQuoteChange:m,setDisplayedTotalCents:E,setPromoError:O,updateState:C,validatePromo:r})}catch(e){if(c!==M.current)return;if(Ye(e)){C({type:`sold_out`});return}Ze({error:e,setPromoError:O,updateState:C,validatePromo:r})}}async function B(){O(void 0),await z(!0,!0)}async function V({addresses:e,phone:r}){P({type:`submission_started`});let u=F();try{let d=await We({addresses:e,catalog:t,checkoutItems:n,client:i,elements:a,email:o,fieldValues:s,isAttemptActive:u,locallyPreviewedTotalCents:T,metadata:c,onPaymentRecoveryChange:f,phone:r,quote:g,stripe:v,stripeConnectedAccountId:y});if(!u())return;Qe({dispatchState:P,onPaymentComplete:l,onPaymentRecoveryChange:f,onPaymentUncertain:p,onQuoteChange:m,result:d,setDisplayedTotalCents:E})}catch(e){if(!u())return;if(Ge(f,null),Ye(e)){P({type:`sold_out`});return}let t=e instanceof re?d(e.serverCode):void 0;if(t)return P({type:`submission_validation_failed`}),{phoneError:t};P({error:e instanceof Error?e.message:`Payment could not be completed.`,type:`retryable_failure`})}}let ee=x.status===`succeeded`||x.status===`unresolved`?x.message:void 0;return{commands:{applyPromo:B,fieldChanged:R,refreshAuthoritativeTotal:z,reportStripeLoadError:e=>P({error:e,type:`retryable_failure`}),reportValidationFailure:()=>P({type:`validation_failed`}),submit:V},state:{displayedTotalCents:T,isRecovering:x.status===`recovering`,isRefreshingQuote:x.status===`refreshing_quote`,isSubmitting:ge(x),parsedTip:I,paymentError:me(x),promoError:D,terminalMessage:ee}}}const et=new Map,tt=(e,t)=>{let n=t?.stripeAccount??null,r=et.get(e);r||(r=new Map,et.set(e,r));let i=r.get(n);if(i)return i;let a=b(e,t).catch(()=>(r?.get(n)===a&&(r.delete(n),r.size===0&&et.delete(e)),null));return r.set(n,a),a};function nt(e){let{connectedAccountId:t,publishableKey:n}=e.payment;return tt(n,t?{stripeAccount:t}:void 0)}function rt(e){return e===`monthly`?{interval:`month`,label:`Monthly`}:e===`annually`?{interval:`year`,label:`Annual`}:null}function it(e,t,n){if(n){let{connectedAccountId:e}=n;return e}if(`payment`in t){let{connectedAccountId:e}=t.payment;return e}let{connectedAccountId:r}=e.payment;return r}function at({accentColor:e,catalog:t,checkoutItems:n,client:r,fontFamily:i,metadata:a,onPaymentComplete:o,onResumePaymentFailed:s,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:u,quote:d,resumePayment:f,onStateChange:p,stripeLoader:m,theme:h,visualStyle:_}){let[v,y]=A(()=>fe(!!f)),b=k(v);b.current=v;let x=S((e,t=!1)=>{let n=pe(b.current,e);n!==b.current&&(b.current=n,y(n),t&&p(he(n)))},[p]),C=it(t,d,f),T=k({connectedAccountId:C,paymentOption:d.paymentOption});v.status!==`submitting`&&v.status!==`recovering`&&(T.current={connectedAccountId:C,paymentOption:d.paymentOption});let{connectedAccountId:E,paymentOption:O}=T.current,j=D(()=>m(t.payment.publishableKey,E?{stripeAccount:E}:void 0).catch(()=>null),[t.payment.publishableKey,E,m]),[M,N]=A(!1);return w(()=>{let e=!0;return N(!1),j.then(t=>{e&&t===null&&N(!0)}),()=>{e=!1}},[j]),U(g,{options:{amount:Math.max(d.totalCents,100),appearance:{rules:{".Input:focus":{borderColor:e,boxShadow:`0 0 0 1px ${e}`,outline:`none`}},theme:h===`light`?`stripe`:`night`,variables:{borderRadius:_?.[`--lockerverse-radius`]??`10px`,colorBackground:_?.[`--lockerverse-control`]??(h===`light`?`#f5f6f7`:`#121212`),colorDanger:_?.[`--lockerverse-danger`]??(h===`light`?`#c52b3e`:`#f08a98`),colorPrimary:e,colorText:_?.[`--lockerverse-text`]??(h===`light`?`#121416`:`#ffffff`),colorTextPlaceholder:_?.[`--lockerverse-placeholder`]??(h===`light`?`#72767d`:`#6b6b6b`),colorTextSecondary:_?.[`--lockerverse-muted`]??(h===`light`?`#62666d`:`#a1a1aa`),focusBoxShadow:`none`,focusOutline:`none`,fontFamily:i,fontSizeBase:`16px`}},currency:t.payment.currency,excludedPaymentMethodTypes:[`us_bank_account`],mode:O===`one-time`?`payment`:`subscription`,syncAddressCheckbox:`none`},stripe:j,children:U(gt,{catalog:t,checkoutItems:n,client:r,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:c,onPaymentUncertain:l,onQuoteChange:u,onResumePaymentFailed:s,onStateChange:p,paymentState:v,quote:d,resumePayment:f,stripeConnectedAccountId:E,stripeLoadFailed:M,updateState:x})},`${t.payment.publishableKey}:${E??`platform`}:${O}`)}function ot({label:e}){return W(`div`,{className:`lockerverse-payment__stripe-loader`,role:`status`,children:[U(`p`,{children:e}),W(`div`,{"aria-hidden":`true`,children:[U(`span`,{}),U(`span`,{}),U(`span`,{})]})]})}function st({onError:e,onReady:t,ready:n}){return W(`div`,{className:`lockerverse-payment__stripe-element`,"data-ready":n,children:[n?null:U(ot,{label:`Loading payment form...`}),U(`div`,{className:`lockerverse-payment__stripe-mount`,children:U(_,{onLoadError:({error:t})=>e(t.message??`Payment form failed to load.`),onReady:t,options:{business:{name:`Lockerverse`},fields:{billingDetails:{address:`never`,email:`never`,name:`never`,phone:`never`}},layout:`tabs`,terms:{applePay:`auto`,auBecsDebit:`never`,bancontact:`never`,card:`always`,cashapp:`never`,googlePay:`never`,ideal:`never`,paypal:`auto`,sepaDebit:`never`,sofort:`never`,usBankAccount:`never`},wallets:{applePay:`auto`,googlePay:`never`}}})})]})}function ct({label:e,mode:t,onChange:n,onError:r,onReady:i,ready:a}){return W(`div`,{className:`lockerverse-payment__address`,children:[U(`h2`,{children:e}),W(`div`,{className:`lockerverse-payment__stripe-element lockerverse-payment__stripe-element--address`,"data-ready":a,children:[a?null:U(ot,{label:`Loading ${e.toLowerCase()}...`}),U(`div`,{className:`lockerverse-payment__stripe-mount`,children:U(h,{onChange:n,onLoadError:({error:t})=>r(t.message??`${e} failed to load.`),onReady:i,options:{autocomplete:{mode:`automatic`},mode:t}})})]})]})}function lt({message:e}){return e?U(`p`,{className:`lockerverse-payment__field-message`,role:`alert`,children:e}):null}function ut({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:i,isShippingAddressReady:a,onAddressChange:o,onFieldValuesChange:s,onStripeLoadError:c,setIsBillingAddressReady:l,setIsPaymentReady:u,setIsShippingAddressReady:d}){let f=t>0;return W(ne,{children:[f?U(st,{onError:c,onReady:()=>u(!0),ready:i}):null,f||e.widget.fields.shipping?U(ct,{label:f?`Billing address`:`Shipping address`,mode:`billing`,onChange:e=>o(`billing`,e),onError:c,onReady:()=>l(!0),ready:r}):null,e.widget.fields.shipping?W(`div`,{className:`lockerverse-payment__shipping`,children:[U(le,{checked:n.shippingMatchesBilling,name:`shippingMatchesBilling`,onChange:e=>{s({...n,shippingMatchesBilling:e}),e?o(`shipping`,null):d(!1)},children:`Shipping is same as billing information`}),n.shippingMatchesBilling?null:U(ct,{label:`Shipping address`,mode:`shipping`,onChange:e=>o(`shipping`,e),onError:c,onReady:()=>d(!0),ready:a})]}):null]})}function dt({displayedBaseCents:e,displayedTipCents:t,displayedTotalCents:n,quote:r}){let a=rt(r.paymentOption),o=Math.max(0,e-r.subtotalCents+r.discountCents);return W(`section`,{"aria-label":`Payment summary`,className:`lockerverse-payment__payment-summary`,children:[U(`h2`,{children:`Order summary`}),U(`div`,{className:`lockerverse-payment__payment-summary-items`,children:r.lineItems.map(e=>W(`div`,{className:`lockerverse-payment__payment-summary-row`,children:[W(`span`,{children:[e.productName,e.quantity>1?W(ne,{children:[` `,W(`small`,{children:[`× `,e.quantity]})]}):null,e.paymentOption===`monthly`?U(`small`,{children:` · Monthly`}):null,e.paymentOption===`annually`?U(`small`,{children:` · Annual`}):null]}),U(`strong`,{children:i(e.subtotalCents)})]},e.listingId))}),W(`div`,{className:`lockerverse-payment__payment-summary-totals`,children:[o>0?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-detail`,children:[U(`span`,{children:`Service fee`}),U(`strong`,{children:i(o)})]}):null,r.discountCents>0&&r.appliedDiscount?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-discount`,children:[W(`span`,{children:[r.appliedDiscount.source===`email_list`?`Email discount`:`Promo code discount`,` `,`(`,r.appliedDiscount.percentageOff,`% off)`]}),W(`strong`,{children:[`-`,i(r.discountCents)]})]}):null,t>0?W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-detail lockerverse-payment__payment-summary-tip`,children:[U(`span`,{children:`Tip`}),U(`strong`,{children:i(t)})]}):null,W(`div`,{className:`lockerverse-payment__payment-summary-row lockerverse-payment__payment-summary-total`,children:[U(`span`,{children:a?`${a.label} total`:`Total`}),U(`strong`,{children:i(n)})]})]})]})}function ft({catalog:e,displayedTotalCents:t,fieldValues:n,isBillingAddressReady:r,isPaymentReady:a,isRequiredShippingReady:o,isSubmitting:s,onFieldValuesChange:c,quote:l}){let u=t===0,d=u?!e.widget.fields.shipping||r&&o:a&&r&&o,f=rt(l.paymentOption),p=u?`Complete order`:`Pay ${i(t)}`;!u&&f&&(p=`Subscribe for ${i(t)}/${f.interval}`),s&&(p=u?`Completing…`:`Processing…`);let m=`Process payment for ${i(t)} total`;return u?m=`Complete order`:f&&(m=`Start ${f.label.toLowerCase()} subscription for ${i(t)}`),W(`div`,{className:`lockerverse-payment__actions`,children:[U(de,{amountCents:l.serviceFeeCents||Math.round(l.subtotalCents*e.pricingPolicy.serviceFeeRateBasisPoints/1e4),enabled:e.widget.fields.serviceFee,onChange:c,values:n}),U(`button`,{"aria-busy":s,"aria-label":m,disabled:s||!d,type:`submit`,children:p})]})}function pt(e,t){let n=e.elements.namedItem(t);if(n instanceof HTMLElement){n.focus();return}n instanceof RadioNodeList&&Array.from(n).find(e=>e instanceof HTMLElement)?.focus()}function mt({customFieldErrors:e,emailRef:t,form:n,parsedTipSuccess:r,phoneRef:i,validationErrors:a}){if(a.email){t.current?.focus();return}if(a.phone){i.current?.focus();return}if(!r){n.querySelector(`[name="tip"]`)?.focus();return}let[o]=Object.keys(e);o&&pt(n,`custom:${o}`)}function ht({email:e,emailDiscountPercentOff:t,emailErrorId:n,emailId:r,emailRef:i,errors:a,onEmailBlur:o,onEmailChange:s,onPhoneChange:c,onPhoneCountryChange:l,phone:u,phoneCountry:d,phoneEnabled:f,phoneErrorId:m,phoneId:h,phoneRef:g}){return W(`div`,{className:`lockerverse-payment__contact`,children:[U(`label`,{htmlFor:r,children:`Email`}),U(`input`,{"aria-describedby":a.email?n:void 0,"aria-invalid":a.email?`true`:void 0,autoComplete:`email`,id:r,name:`email`,onBlur:o,onChange:e=>s(e.currentTarget.value),placeholder:`name@example.com`,ref:i,type:`email`,value:e}),a.email?U(`p`,{className:`lockerverse-payment__field-message`,id:n,children:a.email}):null,t===void 0?null:W(`p`,{className:`lockerverse-payment__discount-message`,role:`status`,children:[`Your email qualifies for `,t,`% off.`]}),f?W(ne,{children:[U(`label`,{htmlFor:h,children:`Phone`}),W(`div`,{className:`lockerverse-payment__phone-control`,children:[U(se,{ariaLabel:`Phone number country`,className:`lockerverse-payment__select--phone-country`,name:`phoneCountry`,onValueChange:l,options:p,value:d}),U(`input`,{"aria-describedby":a.phone?m:void 0,"aria-invalid":a.phone?`true`:void 0,autoComplete:`tel`,id:h,inputMode:`tel`,name:`phone`,onChange:e=>c(e.currentTarget.value),placeholder:`(201) 555-0123`,ref:g,type:`tel`,value:u})]}),a.phone?U(`p`,{className:`lockerverse-payment__field-message`,id:m,children:a.phone}):null]}):null]})}function gt({catalog:e,checkoutItems:t,client:n,metadata:r,onPaymentComplete:i,onResumePaymentFailed:a,onPaymentRecoveryChange:s,onPaymentUncertain:c,onQuoteChange:u,onStateChange:d,quote:p,resumePayment:m,stripeConnectedAccountId:h,stripeLoadFailed:g,paymentState:_,updateState:b}){let[x,S]=A(``),[C,E]=A(``),[D,O]=A(`US`),[j,M]=A({}),[N,P]=A({}),[F,I]=A(),[L,R]=A(!1),[z,B]=A(!1),[V,ee]=A(!1),[H,te]=A({customFields:f(e.widget.customFields),customTip:``,includeServiceFee:e.widget.fields.serviceFee,memberId:``,merchSize:`M`,promoCode:``,shippingMatchesBilling:!0,tipPercent:`10`}),ne=k({billing:null,shipping:null}),re=k(null),ie=k(null),G=k(null),ae=k(p.totalCents>0),K=$e({catalog:e,checkoutItems:t,client:n,elements:v(),email:x,fieldValues:H,metadata:r,onPaymentComplete:i,onPaymentRecoveryChange:s,onPaymentUncertain:c,onQuoteChange:u,onResumePaymentFailed:a,onStateChange:d,paymentState:_,quote:p,resumePayment:m,stripe:y(),stripeConnectedAccountId:h,stripeLoadFailed:g,updateState:b}),{displayedTotalCents:q,isRecovering:oe,isRefreshingQuote:se,isSubmitting:J,parsedTip:Y,paymentError:X,promoError:le,terminalMessage:de}=K.state,fe=`lockerverse-${T()}`,Z=`${fe}-email`,pe=`${Z}-error`,me=`${fe}-phone`,he=`${me}-error`,ge=`${fe}-tip-error`,_e=(Y.success?Y.cents:null)??0,ye=q-_e,be=!e.widget.fields.shipping||H.shippingMatchesBilling||V;w(()=>{J&&G.current?.focus({preventScroll:!0})},[J]),w(()=>{J||j.email||!j.phone||ie.current?.focus()},[j.email,j.phone,J]),w(()=>{let e=q>0;e&&!ae.current&&(R(!1),B(!1)),ae.current=e},[q]);function xe(e){K.commands.fieldChanged(!1,e!==`email`),M(t=>{let n={...t};return delete n[e],n})}function Q(e){let t=e.promoCode!==H.promoCode,n=e.includeServiceFee!==H.includeServiceFee;K.commands.fieldChanged(t,!(t||n)),te(e),P({}),I(void 0)}async function Se(t){t.preventDefault();let n=l(C,D),r=ve({email:x,phone:n},e.widget.fields.phone),i=o(e.widget.customFields,H.customFields);if(!(r.value&&Y.success)||Object.keys(i).length>0){M(r.errors),P(i),I(Y.success?void 0:Y.message),K.commands.reportValidationFailure();let e=t.currentTarget;queueMicrotask(()=>{mt({customFieldErrors:i,emailRef:re,form:e,parsedTipSuccess:Y.success,phoneRef:ie,validationErrors:r.errors})});return}M({}),P({});let a=await K.commands.submit({addresses:ne.current,phone:n});a?.phoneError&&M({phone:a.phoneError})}return de?U(`p`,{className:`lockerverse-payment__payment-status`,ref:G,role:`status`,tabIndex:-1,children:de}):oe?U(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:`Recovering payment…`}):W(`form`,{"aria-busy":J,className:`lockerverse-payment__form`,noValidate:!0,onSubmit:Se,children:[U(`div`,{"data-lockerverse-input-region":``,inert:J?!0:void 0,children:W(`fieldset`,{className:`lockerverse-payment__input-fieldset`,disabled:J,children:[U(dt,{displayedBaseCents:ye,displayedTipCents:_e,displayedTotalCents:q,quote:p}),U(ce,{enabled:e.widget.fields.tipping,error:F,errorId:ge,onChange:Q,values:H}),U(ht,{email:x,emailDiscountPercentOff:p.appliedDiscount?.source===`email_list`?p.appliedDiscount.percentageOff:void 0,emailErrorId:pe,emailId:Z,emailRef:re,errors:j,onEmailBlur:()=>K.commands.refreshAuthoritativeTotal(),onEmailChange:e=>{S(e),xe(`email`)},onPhoneChange:e=>{E(e),xe(`phone`)},onPhoneCountryChange:e=>{O(e),K.commands.fieldChanged(!1,!0),requestAnimationFrame(()=>ie.current?.focus())},phone:C,phoneCountry:D,phoneEnabled:e.widget.fields.phone,phoneErrorId:he,phoneId:me,phoneRef:ie}),U(ut,{catalog:e,displayedTotalCents:q,fieldValues:H,isBillingAddressReady:z,isPaymentReady:L,isShippingAddressReady:V,onAddressChange:(e,t)=>{ne.current[e]=t},onFieldValuesChange:Q,onStripeLoadError:K.commands.reportStripeLoadError,setIsBillingAddressReady:B,setIsPaymentReady:R,setIsShippingAddressReady:ee}),U(ue,{customFields:e.widget.customFields,errors:N,fields:e.widget.fields,idPrefix:fe,isPromoApplying:se,memberIdLabel:e.community?.memberIdLabel,onApplyPromo:K.commands.applyPromo,onChange:Q,promoError:le,values:H}),U(ft,{catalog:e,displayedTotalCents:q,fieldValues:H,isBillingAddressReady:z,isPaymentReady:L,isRequiredShippingReady:be,isSubmitting:J,onFieldValuesChange:Q,quote:p})]})}),J?U(`p`,{className:`lockerverse-payment__sr-only`,ref:G,role:`status`,tabIndex:-1,children:q===0?`Completing order…`:`Processing payment…`}):null,U(lt,{message:X})]})}function _t(){return U(s,{fieldCount:2,label:`Loading payment…`,sectionCount:2,showCheckbox:!0})}function vt(e,t){switch(t.type){case`loading`:return{phase:`loading`,revision:e.revision};case`ready`:return xt(t.displayedQuote,e.revision+1);case`error`:return{failure:t.failure,phase:`error`,revision:e.revision};case`checkout`:return e.phase===`ready`?{...e,displayedQuote:t.checkout,quoteFailure:void 0}:e;case`quote-error`:return e.phase===`ready`?{...e,quoteFailure:t.failure}:e;default:return e}}function $(e,t){return e===t}function yt({checkout:e}){return{displayedQuote:e,type:`ready`}}function bt(e){return e instanceof Error?e.message:`Lockerverse payment could not load.`}function xt(e,t){return{checkoutItems:[...e.items],displayedQuote:e,phase:`ready`,quoteFailure:void 0,revision:t}}function St(e,t){let n=e.widget.fields.serviceFee;return ie(e,{includeServiceFee:n,selection:t})}function Ct(e,t){try{return xt(St(e,t),1)}catch(e){return{failure:bt(e),phase:`error`,revision:0}}}function wt({catalog:e,client:t,paymentState:n,selection:r}){let i=Ae(r),a=i.success?JSON.stringify(i.value):`invalid-selection`,o=D(()=>i.success?i.value:[],[i.success,a]),[s,c]=O(vt,void 0,()=>i.success?Ct(e,o):{phase:`loading`,revision:0}),l=k(void 0),u=k(0),d=k(s.phase===`ready`?a:void 0),f=k(s.phase===`error`?a:void 0),p=n===`submitting`||n===`success`||n===`unresolved`;w(()=>{if(!i.success||p||$(f.current,a)||$(l.current,a))return;let n=!0;l.current=a;let r=d.current===a;r||c({type:`loading`});function s(e){n&&c(e)}function m(){n&&(l.current=void 0,f.current=a)}let h;function g(e){if(!n||(l.current=void 0,f.current=a,r&&h!==void 0&&u.current!==h))return;let t=bt(e);if(t===`This option is sold out.`){c({failure:t,type:`error`});return}c(r?{failure:t,type:`quote-error`}:{failure:t,type:`error`})}async function _(){try{h=u.current;let n=e.widget.fields.serviceFee;if(!r){let t=St(e,o);r=!0,d.current=a,s(yt({checkout:t}))}let i=await t.calculateTotal({catalog:e,includeServiceFee:n,selection:o});m(),u.current===h&&s({checkout:i,type:`checkout`})}catch(e){g(e)}}return _(),()=>{n=!1,$(l.current,a)&&(l.current=void 0)}},[e,t,i.success,p,a,o]);let m=$(d.current,a)||$(f.current,a)||$(l.current,a),h=p||m?s:{phase:`loading`,revision:s.revision};return{selectionError:i.success?void 0:i.message,session:h,updateCheckout:e=>{u.current+=1,c({checkout:e,type:`checkout`})}}}function Tt(e,t){let n=m(e?.[`--lockerverse-accent`]??t?.accentColor??`#38d77a`),r=c(n),i={...e};return(e?.[`--lockerverse-accent`]!==void 0||t?.accentColor)&&(i[`--lockerverse-accent`]=n),r&&e?.[`--lockerverse-accent-contrast`]===void 0&&(i[`--lockerverse-accent-contrast`]=r),{accent:n,rootStyle:i}}function Et({catalog:e,client:t,...n}){let{branding:r,className:i,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:s,onPaymentUncertain:c,resumePayment:l,selection:u,style:d,stripeLoader:f=tt,theme:p=`dark`,...m}=n,[h,g]=A(l),_=k(null),[v,y]=A(),[b,x]=A(`idle`),C=k(void 0),{selectionError:T,session:D,updateCheckout:O}=wt({catalog:e,client:t,paymentState:b,selection:u}),j=D.phase===`ready`?D.revision:void 0,M=S(e=>{j!==void 0&&(C.current=j),x(e)},[j]),N=S(e=>s?.(e),[s]),P=S(()=>{g(void 0)},[]);w(()=>{D.phase===`loading`&&y(void 0)},[D.phase]),E(()=>{D.phase===`ready`&&C.current!==D.revision&&x(e=>e===`success`||e===`unresolved`?e:`idle`)},[D.phase,D.revision]);let F=[`lockerverse-payment`,i].filter(Boolean).join(` `),I=r??e.community,{accent:L,rootStyle:R}=Tt(d,I);return T?U(`section`,{...m,className:F,"data-lockerverse-theme":p,role:`alert`,style:R,children:T}):D.phase===`error`&&D.failure===`This option is sold out.`||b===`sold_out`?W(`section`,{...m,className:F,"data-lockerverse-theme":p,role:`alert`,style:R,children:[U(`h1`,{children:`Sold out`}),U(`p`,{children:`This option is sold out.`})]}):D.phase===`error`?U(`section`,{...m,className:F,"data-lockerverse-theme":p,style:R,children:U(`p`,{role:`alert`,children:D.failure})}):D.phase===`ready`?W(`section`,{...m,"aria-label":`Payment`,className:F,"data-lockerverse-theme":p,"data-payment-state":b,ref:_,style:R,children:[W(`header`,{children:[e.widget.showCommunityBranding&&I?W(`div`,{className:`lockerverse-payment__branding`,children:[I.imageUrl?U(`img`,{alt:I.name,height:`48`,src:I.imageUrl,width:`48`}):null,U(`strong`,{children:I.name})]}):null,U(`h1`,{children:e.widget.title??e.widget.name}),e.widget.description?U(`p`,{children:e.widget.description}):null]}),v?U(`p`,{className:`lockerverse-payment__payment-status`,role:`status`,children:v}):null,D.quoteFailure?W(`div`,{className:`lockerverse-payment__payment-status`,role:`alert`,children:[U(`span`,{children:D.quoteFailure}),U(`span`,{children:` The final total will be checked when you submit.`})]}):null,U(K,{container:_,children:U(at,{accentColor:L,catalog:e,checkoutItems:D.checkoutItems,client:t,fontFamily:d?.[`--lockerverse-font-family`]??`ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif`,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:N,onPaymentUncertain:c,onQuoteChange:(e,t)=>{y(t),O(e)},onResumePaymentFailed:P,onStateChange:M,quote:D.displayedQuote,resumePayment:h,stripeLoader:f,theme:p,visualStyle:R},D.revision)})]}):U(`section`,{...m,"aria-busy":`true`,"aria-label":`Payment`,className:F,"data-lockerverse-theme":p,style:R,children:U(_t,{})})}function Dt({children:e,loading:t=!1,viewProps:n}){let{branding:r,className:i,metadata:a,onPaymentComplete:o,onPaymentRecoveryChange:s,onPaymentUncertain:l,resumePayment:u,selection:d,stripeLoader:f,style:p,theme:h=`dark`,...g}=n,_=m(p?.[`--lockerverse-accent`]??r?.accentColor??`#38d77a`),v=c(_),y={...p};return(p?.[`--lockerverse-accent`]!==void 0||r?.accentColor)&&(y[`--lockerverse-accent`]=_),v&&p?.[`--lockerverse-accent-contrast`]===void 0&&(y[`--lockerverse-accent-contrast`]=v),U(`section`,{...g,...t?{"aria-busy":!0,"aria-label":`Payment`}:{},className:[`lockerverse-payment`,i].filter(Boolean).join(` `),"data-lockerverse-theme":h,style:y,children:e})}function Ot({widget:e,...t}){return e.error?W(Dt,{viewProps:t,children:[U(`p`,{role:`alert`,children:e.error.message}),U(`button`,{onClick:e.refresh,type:`button`,children:`Retry`})]}):e.loading||!e.catalog?U(Dt,{loading:!0,viewProps:t,children:U(_t,{})}):U(Et,{catalog:e.catalog,client:e.client,...t})}export{nt as n,Ot as t};
2
2
  //# sourceMappingURL=lockerverse-payment.js.map