UNPKG

@sprig-technologies/sprig-browser

Version:

npm package for the sprig web sdk

502 lines (501 loc) 68 kB
import { a as X, h as z, u as e, c as H, f as Be, b as te, F as ve, p as re, g as fe, e as he, _ as ne, T as Te, A as or, M as we, D as Ee, i as dr, P as cr, o as ur, q as pr, r as ue, s as Ke, v as mr, m as gr, x as hr, j as br, k as vr, l as yr, z as fr, B as Sr, t as Pe, n as He } from "./view-CDrJuRMn.js"; import { t as oe } from "./metricsReporter-0HbKrvkx.js"; import { b as Re, D as Ae, g as Xe, A as xr } from "./core-YTxB8B8q.js"; import { b as ae, a as le, H as Ne, M as ge, Q as me, O as xe, B as ee, L as Ce, S as kr, u as Ir, g as _r, p as Tr, v as Cr, R as se, c as Nr, s as wr, d as qr } from "./videoPlayer-HNloD0SJ.js"; const Lr = ({ className: n, message: i, next: c, properties: r, questionId: t, type: a }) => { const { useMobileStyling: g, border: v, isLongFormSurvey: u, focusedQuestionId: h } = X((m) => ({ useMobileStyling: m.useMobileStyling, border: m.border, isLongFormSurvey: oe(m.studyType), focusedQuestionId: m.focusedQuestionId })), [o, b] = z(!1), [d, N] = z(""), [l, y] = z(!1), p = u && h === t, k = r == null ? void 0 : r.collectName, f = (r == null ? void 0 : r.nameLabelText) || "Full Name", C = (r == null ? void 0 : r.consentText) || "I agree to the stated conditions", q = (r == null ? void 0 : r.submitButtonText) || "Submit", Q = !!d.trim(), P = o && (!k || Q), A = (m, x = !1) => { m.preventDefault(), m.stopPropagation(); let L = null; if (!x) { if (!P) return void y(!0); L = { submitted: !0 }, k && (L.name = d); } c({ value: L, questionId: t, type: a }, P); }; return e("div", { className: H(n, u && !p && "ul-card--unfocused", "ul-card__consent-legal", "fade-in-transition"), children: [e(ae, { isRequired: u && (r == null ? void 0 : r.required), message: i, properties: { questionHtml: r.questionHtml } }), r != null && r.richTextBody ? e(le, { children: e(Ne, { className: "ul-rich-text-body", html: r.richTextBody, id: "ul-card__consent-legal-body-container" }) }) : null, e(ge, { embeddedType: "pdf", properties: r, children: e(me, { children: [e("div", { className: "sprig-stretch", children: [e(xe, { allowTextEntry: !1, border: v, error: l && !o, id: "consent", isRadio: !1, isSelected: o, label: C, onUserInputChanged: ({ selected: m }) => { m !== o && b(!o); }, useMobileStyling: g }), k && e("input", { "aria-label": f, "aria-placeholder": f, className: H(te("ul-consent-legal__name-input", g)), "data-gramm": "false", maxLength: 250, name: "name", onBlur: (m) => { m.currentTarget.style.borderColor = l && !Q ? Re : Ae; }, onFocus: (m) => { m.currentTarget.style.borderColor = l && !Q ? Re : v; }, onInput: (m) => { m.preventDefault(), m.stopPropagation(), N(m.currentTarget.value); }, placeholder: f, style: l && !Q ? { borderColor: Re } : {}, tabIndex: 0, value: d })] }), e("div", { className: "ul-card__button-wrapper ul-card-vertical__button-wrapper", children: [e(ee, { className: P ? "" : "sprig-button-disabled", onClick: A, children: q }), r.required === !1 && !u && e("button", { className: "ul-card-skip__button", onClick: (m) => A(m, !0), children: Be(r) })] })] }) })] }, t); }, _e = (n) => (i) => { i.pointerType !== "touch" && n(); }, Dr = ({ activeValue: n, border: i, icon: c, isPressed: r, onSubmit: t, range: a, scaleLabelType: g, selectedValue: v, setSelectedValue: u, setActiveValue: h, setIsPressed: o, useMobileStyling: b, value: d, viewDocument: N }) => { const { isLongFormSurvey: l, enableCspTrustedTypes: y } = X((x) => ({ isLongFormSurvey: oe(x.studyType), enableCspTrustedTypes: x.enableCspTrustedTypes })), p = `option-${d}`, k = g === "number", f = g === "star", C = g === "smiley", q = k && d === n || d === v, [Q, P] = (() => { const x = f && v !== null && d <= v; return f && d <= n || C && d === n || x || d === n || d === v ? [i, r || x || d === v ? 1 : 0.3] : ["", 1]; })(), A = ve(() => { const x = v === d, L = { borderColor: q && !b || x ? Q : "", fillOpacity: q ? "" : P, zIndex: q ? 3 : "auto", color: x ? "#fff" : "" }; return k ? { ...L, backgroundColor: x ? Q : "" } : { ...L, color: f || C || x ? Q : "" }; }, [q, Q, P, v, d, k, f, C, b]), m = ve(() => Xe((({ icon: x, scaleLabelType: L, value: M, selectedValue: O }) => { if (L === "smiley" && M === O) { let w = 0; return x.replace(/black/g, () => ++w == 1 ? "black" : "white"); } return x; })({ icon: c, scaleLabelType: g, value: d, selectedValue: v }), y), [y, c, g, v, d]); return e("button", { "aria-label": k ? void 0 : String(d), className: (() => { switch (g) { case "star": return H(te("likert-star", b), te(`likert-star-${d}`, b)); case "smiley": return H(te("likert-smiley", b), te(`likert-smiley-${d}`, b)); default: return d === a ? H(te("likert-number", b), te(`likert-number-${d}`, b), te("likert-last-option", b)) : H(te("likert-number", b), te(`likert-number-${d}`, b)); } })(), dangerouslySetInnerHTML: { __html: m }, id: p, onClick: (x) => { l && (x.preventDefault(), x.stopPropagation(), u(d)), t(); }, onKeyDown: (x) => { var O, w; const L = N.querySelectorAll(`.likert-${g ?? "number"}`), M = d - 1; x.key === "ArrowRight" ? (O = L[M + 1]) == null || O.focus() : x.key === "ArrowLeft" ? (w = L[M - 1]) == null || w.focus() : x.key !== "Enter" && x.key !== " " || (l && (x.preventDefault(), x.stopPropagation(), u(d)), t()); }, onPointerCancel: _e(() => o(!1)), onPointerDown: _e(() => { o(!0), h(d); }), onPointerEnter: _e(() => h(d)), onPointerLeave: _e(() => { h(-1), o(!1); }), onPointerUp: _e(() => o(!1)), style: A, tabIndex: 0 }); }, Pr = ({ className: n, labels: i, message: c, next: r, properties: t, questionId: a, type: g }) => { const { border: v, useMobileStyling: u, viewDocument: h, isLongFormSurvey: o, focusedQuestionId: b } = X((M) => ({ border: M.border, useMobileStyling: M.useMobileStyling, viewDocument: M.viewDocument, isLongFormSurvey: oe(M.studyType), focusedQuestionId: M.focusedQuestionId })), [d, N] = z(-1), [l, y] = z(!1), [p, k] = z(null); re(() => { N(-1), y(!1), k(null); }, [a]); const f = o && b === a, C = i && i.left, q = i && i.right; let Q; const { range: P, scaleLabelType: A, ratingIcons: m } = t; P && (Q = Number(P)); const x = Q || 5, L = (M) => { var O, w; switch (A) { case "star": return (O = m[0]) == null ? void 0 : O.svg; case "smiley": return (w = m[M]) == null ? void 0 : w.svg; default: return String(M + 1); } }; return e("form", { className: H(n, "ul-card--likert", "fade-in-transition", o && !f && "ul-card--unfocused"), children: [e(ae, { isRequired: o && (t == null ? void 0 : t.required), message: c, properties: t }), e(ge, { properties: t, children: e(fe, { children: [e(le, { children: [e("div", { "aria-label": `Rating (1 - ${x})`, className: "ul-card--likert__numbers", role: "radiogroup", children: [...Array(x)].map((M, O) => { const w = O + 1; return e(Dr, { activeValue: d, border: v, icon: L(O), isPressed: l, onSubmit: () => r({ value: w, questionId: a, type: g }, !0), range: x, scaleLabelType: A, selectedValue: p, setActiveValue: N, setIsPressed: y, setSelectedValue: k, useMobileStyling: u, value: w, viewDocument: h }, O); }) }), e("div", { className: "ul-card--likert__labels", children: [e("span", { children: C }), e("span", { children: q })] })] }), !t.required && !o && e(me, { children: e("div", { className: "ul-vertical-centered-container", children: e(ee, { onClick: (M) => { M.preventDefault(), M.stopPropagation(), r({ value: null, questionId: a, type: g }, !0); }, children: he(t) }) }) })] }) })] }, a); }, Rr = ({ columns: n, onSelect: i, options: c, selectedOptions: r }) => { const t = ne([]), { border: a, useMobileStyling: g, cards: v, index: u } = X((l) => ({ border: l.border, useMobileStyling: l.useMobileStyling, cards: l.cards, index: l.index })), h = c.findIndex((l) => r[l.id] === null), [o, b] = z(h), d = Te((l, y) => { var f; i(l, y); const p = o + 1, k = c[p]; if (k && r[k.id] === null) { b(p); const C = v[u]; (C == null ? void 0 : C.groupId) != null || ((f = t.current[p]) == null || f.scrollIntoView({ block: "nearest", behavior: "smooth" })); } }, [i, c, r, o, v, u]), N = Te((l, y) => { const p = o === l; return e(or, { animate: !0, header: y.label, isOpen: p, onClick: () => { var k; return b(p && !((k = window.UserLeap) != null && k.isMobileSDK) ? -1 : l); }, ref: (k) => { k && (t.current[l] = k); }, showHeaderCheck: r[y.id] !== null, children: e("div", { style: { paddingTop: "12px" }, children: n.map((k) => e(xe, { allowTextEntry: !1, ariaLabel: `${y.label}-${k.label}`, border: a, error: !1, id: `${y.id}-${k.value}`, isRadio: !0, isSelected: r[y.id] === k.value, label: k.label, onUserInputChanged: () => d(y.id, k.value), useMobileStyling: g }, k.label)) }) }, y.id); }, [a, n, o, d, r, g]); return e("div", { children: c.map((l, y) => N(y, l)) }); }, Mr = ({ columns: n, onSelect: i, options: c, selectedOptions: r }) => { const { border: t, useMobileStyling: a, isLongFormSurvey: g } = X((l) => ({ border: l.border, useMobileStyling: l.useMobileStyling, isLongFormSurvey: oe(l.studyType) })), v = c.length, u = n.length, h = ne(null), [o, b] = z(!1), [d, N] = z(!1); return re(() => { const l = h.current, y = new ResizeObserver((p) => { window.requestAnimationFrame(() => { l && (b(Math.round(p[0].contentRect.width) < l.scrollWidth), N(Math.round(p[0].contentRect.width) < l.scrollWidth)); }); }); return l && y.observe(l), () => { l && y.unobserve(l); }; }, []), e("div", { className: "ul-card--matrix_question_container", children: [e("div", { className: H("ul-card--matrix_container", o && "ul-matrix-scroll-gradient"), onScroll: () => { (() => { const l = h.current; l && b(l.clientWidth + Math.abs(l.scrollLeft) < l.scrollWidth); })(); }, ref: h, children: e("div", { className: H(g && "ul-card--matrix_grid_longform", "ul-card--matrix_grid"), style: `--numColumns: ${u}; --numRows: ${v + 1};`, children: [e("div", {}), " ", n.map((l) => e("div", { className: "ul-matrix-column-label", children: l.label }, l.label)), c.map((l) => e(fe, { children: [e("div", { "aria-label": l.label, className: "ul-matrix-row-label", children: l.label }, l.label), e("div", { className: "ul-matrix-row-options", role: "radiogroup", children: n.map((y, p) => e("div", { className: H("ul-matrix-option-wrapper", p === u - 1 && "ul-matrix-last-option"), children: e(xe, { allowTextEntry: !1, ariaLabel: `${l.label}-${y.label}`, border: t, choiceStyle: { background: "transparent", border: "none", marginBottom: "0", padding: "0" }, error: !1, id: `${l.id}-${y.value}`, isRadio: !0, isSelected: r[l.id] === y.value, onUserInputChanged: () => i(l.id, y.value), useMobileStyling: a }) }, y.value)) })] }))] }) }), (o || d) && e("button", { className: d && !o ? "ul-matrix-scroll-arrow left" : "ul-matrix-scroll-arrow", onClick: d && !o ? (l) => { l.preventDefault(); const y = h.current; if (y) { const p = getComputedStyle(y).direction === "rtl"; y.scrollTo({ left: p ? y.scrollWidth - y.clientWidth : 0, behavior: "smooth" }); } } : (l) => { l.preventDefault(); const y = h.current; if (y) { const p = getComputedStyle(y).direction === "rtl"; y.scrollTo({ left: p ? y.clientWidth - y.scrollWidth : y.scrollWidth, behavior: "smooth" }); } }, children: e(d && !o ? Er : Ur, {}) })] }); }, Er = () => e("svg", { fill: "currentColor", height: "32", transform: "matrix(-1,0,0,1,0,0)", version: "1.1", viewBox: "0 0 256 256", width: "32", xmlns: "http://www.w3.org/2000/svg", children: e("path", { d: "M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z" }) }), Ur = () => e("svg", { fill: "currentColor", height: "32", viewBox: "0 0 256 256", width: "32", xmlns: "http://www.w3.org/2000/svg", children: e("path", { d: "M221.66,133.66l-72,72a8,8,0,0,1-11.32-11.32L196.69,136H40a8,8,0,0,1,0-16H196.69L138.34,61.66a8,8,0,0,1,11.32-11.32l72,72A8,8,0,0,1,221.66,133.66Z" }) }), Fr = ({ className: n, message: i, next: c, options: r, properties: t, questionId: a, type: g, showIndividualSubmit: v = !1, onSubmitButtonClick: u }) => { const { useMobileStyling: h, isLongFormSurvey: o, focusedQuestionId: b, setFocusedQuestionId: d } = X((m) => ({ useMobileStyling: m.useMobileStyling, isLongFormSurvey: oe(m.studyType), focusedQuestionId: m.focusedQuestionId, setFocusedQuestionId: m.setFocusedQuestionId })), N = t.matrixColumn, l = t.required, y = o && b === a, p = (m) => Object.values(m).every((x) => x == null), k = (m) => l && p(m), f = (m) => { if (m.preventDefault(), m.stopPropagation(), c({ value: q, questionId: a, type: g }, !0), u) { const x = !p(q); u(x); } }, C = r.reduce((m, x) => (m[x.id] = null, m), {}), [q, Q] = z(C), P = (m, x) => { o && c({ value: { ...q, [m]: x }, questionId: a, type: g }, !k({ ...q, [m]: x })), Q((L) => ({ ...L, [m]: x })); }, A = t.displayMatrixAsAccordion || h; return e("form", { className: H(n, !o && "ul-card__matrix", "fade-in-transition", o && !y && "ul-card--unfocused"), id: "text-form", onClick: () => { y && d(a); }, onSubmit: f, children: [e(ae, { isRequired: o && (t == null ? void 0 : t.required), message: i, properties: t }), e(ge, { properties: t, children: [e(le, { children: [e(A ? Rr : Mr, { columns: N, onSelect: P, options: r, selectedOptions: q }), v && e(Ce, { handleSubmit: f, isSubmitDisabled: k(q) })] }), !o && e(me, { children: e("div", { className: "ul-card__button-wrapper", children: e(ee, { disabled: k(q), children: he(t) }) }) })] })] }, a); }, Je = ({ className: n, message: i, onSubmit: c, options: r = [], properties: t, questionId: a, type: g, showIndividualSubmit: v = !1, onSubmitButtonClick: u }) => { const { border: h, useMobileStyling: o, isLongFormSurvey: b, focusedQuestionId: d, setFocusedQuestionId: N } = X((_) => ({ border: _.border, useMobileStyling: _.useMobileStyling, isLongFormSurvey: oe(_.studyType), focusedQuestionId: _.focusedQuestionId, setFocusedQuestionId: _.setFocusedQuestionId })), l = b && d === a, y = r.reduce((_, B) => (_[B.id] = { isSelected: !1 }, _), {}), [p, k] = z(y), f = g === "multiplechoice", C = t.required, q = r.find((_) => { var B; return (B = _.optionProperties) == null ? void 0 : B.noneOfTheAbove; }), Q = (_) => Object.entries(_).some(([B, G]) => { var D; const s = r.find((E) => `${E.id}` === B), S = G.userText === void 0 || G.userText.trim() === ""; return ((D = s == null ? void 0 : s.optionProperties) == null ? void 0 : D.allowsTextEntry) && S && G.isSelected; }), P = (_) => Object.values(_).filter((B) => B.isSelected).length, A = (_) => { const { minSelect: B = 0, maxSelect: G = 1 / 0, maxSelectMode: s } = t, S = P(_); switch (s) { case we.Maximum: return S <= G; case we.Range: return S === 0 || S >= B; default: return !0; } }, m = t.minSelect && t.minSelect > 0 && t.maxSelectMode === we.Range && P(p) < t.minSelect && (C || P(p) > 0), x = (_) => Q(_) || C && !P(_) || !A(_), L = (_) => A(_) && !Q(_) && P(_) > 0, M = Object.entries(p).some(([_, B]) => { var G, s; return B.isSelected && ((s = (G = r.find((S) => `${S.id}` === _)) == null ? void 0 : G.optionProperties) == null ? void 0 : s.allowsTextEntry); }), O = v && (!f || M), w = (_) => { $(_.id, _.selected, _.userText, _.noneOfTheAbove), _.selected && b && !f && !l && N(a); }, U = (_) => { var B; return (t == null ? void 0 : t.maxSelectMode) !== we.Unlimited && P(p) === (t == null ? void 0 : t.maxSelect) && !((B = p[_]) != null && B.isSelected); }, I = (_) => { if (_.preventDefault(), _.stopPropagation(), c(p, !0), u) { const B = L(p); u(B); } }, $ = (_, B, G, s) => { const S = Object.assign({}, p); if ((f || s) && B) for (const R of Object.values(S)) R.isSelected = !1, delete R.userText; else q && !s && p[q.id].isSelected && (S[q.id].isSelected = !1); S[_] = { isSelected: B, userText: G }; const D = f && Object.entries(S).some(([R, Z]) => { var W, ie; return Z.isSelected && ((ie = (W = r.find((ce) => `${ce.id}` === R)) == null ? void 0 : W.optionProperties) == null ? void 0 : ie.allowsTextEntry); }), E = !x(S); if (b && (c(S, E), f && !D && E && u)) { const R = L(S); u(R); } k(S); }; return e("form", { className: H(n, "ul-card--multiple", "fade-in-transition", b && !l && "ul-card--unfocused"), id: "text-form", onClick: g === "multipleselect" ? () => { b && d !== a && g === "multipleselect" && N(a); } : void 0, onSubmit: I, children: [e(ae, { isRequired: b && (t == null ? void 0 : t.required), message: i, properties: t }), e(ge, { properties: t, children: e(fe, { children: [e(le, { children: [t.isDropdown ? e(kr, { disabledOptions: r.filter((_) => U(_.id)), dropdownFooter: m ? e("div", { className: "ul-card__min-select-counter", style: { marginLeft: "16px" }, children: [P(p), "/", t.minSelect] }) : void 0, isMultiSelect: !f, multiselectText: t.dropdownMultiselectedText ?? "choices selected", onChange: (_) => { const B = { ...p }; for (const G of r) _.includes(G) ? B[G.id].isSelected = !0 : B[G.id].isSelected = !1; b && c(B, !x(B)), k(B); }, options: r, placeholderText: t.dropdownPlaceholderText ?? (f ? "Select choice" : "Select choice(s)"), value: r.filter((_) => p[_.id].isSelected) }) : e("div", { className: H(te("ul-card__choices", o)), role: f ? "radiogroup" : "group", children: [r.map(({ id: _, label: B, value: G, optionProperties: s }) => { var R, Z; const S = `${_}`, { allowsTextEntry: D, noneOfTheAbove: E } = { allowsTextEntry: !1, noneOfTheAbove: !1, ...s }; return e(xe, { allowTextEntry: D, border: h, disabled: U(S), error: Q(p), id: S, isRadio: f, isSelected: !!((R = p[S]) != null && R.isSelected), label: B, noneOfTheAbove: E, onUserInputChanged: w, promptText: (s == null ? void 0 : s.otherOptionPlaceholder) || "Please specify", text: (Z = p[_]) == null ? void 0 : Z.userText, useMobileStyling: o, value: G }, S); }), !!m && e("div", { className: "ul-card__min-select-counter", children: [P(p), "/", t.minSelect] })] }), O && e(Ce, { handleSubmit: I, isSubmitDisabled: x(p) })] }), !b && e(me, { children: e("div", { className: "ul-card__button-wrapper", children: e(ee, { disabled: x(p), onClick: I, children: he(t) }) }) })] }) })] }, a); }, Qr = (n) => { const { questionId: i, type: c, next: r, options: t } = n, { setFocusedQuestionId: a } = X((g) => ({ setFocusedQuestionId: g.setFocusedQuestionId })); return e(Je, { ...n, onSubmit: (g, v) => { var N; const u = Object.entries(g).find(([, l]) => l.isSelected) || [void 0, void 0], [h, o] = u, b = t.find((l) => `${l.id}` === h); !((N = b == null ? void 0 : b.optionProperties) != null && N.allowsTextEntry) || o != null && o.userText && o.userText.trim() !== "" || a(i); const d = o != null && o.userText ? { [h]: { userText: o.userText } } : null; r({ value: b && h ? { [h]: b.value } : {}, secondaryValue: d, questionId: i, type: c }, v); } }); }, Br = (n) => { const { questionId: i, type: c, next: r } = n; return e(Je, { ...n, onSubmit: (t, a) => { const g = Object.entries(t).reduce((u, [h, o]) => (u[h] = o.isSelected, u), {}), v = Object.entries(t).reduce((u, [h, o]) => { if (!o.userText) return u; const b = u || {}; return b[h] = { userText: o.userText }, b; }, null); r({ value: g, secondaryValue: v, questionId: i, type: c }, a); } }); }, Ar = ({ className: n, labels: i, message: c, properties: r, next: t, questionId: a, type: g }) => { const [v, u] = z(null), { border: h, useMobileStyling: o, viewDocument: b, isLongFormSurvey: d, focusedQuestionId: N } = X((k) => ({ border: k.border, useMobileStyling: k.useMobileStyling, viewDocument: k.viewDocument, isLongFormSurvey: oe(k.studyType), focusedQuestionId: k.focusedQuestionId })), l = d && N === a, y = i && i.left, p = i && i.right; return e("form", { className: H(n, "ul-card--nps", "fade-in-transition", d && !l && "ul-card--unfocused"), children: [e(ae, { isRequired: d && (r == null ? void 0 : r.required), message: c, properties: r }), e(ge, { properties: r, children: [e(le, { children: [e("div", { className: "ul-card--nps__numbers", children: [...Array(11)].map((k, f) => e("button", { className: H(te("nps-number", o), te(`nps-number-${f}`, o)), id: `option-${f}`, onClick: (C) => { d && (C.preventDefault(), C.stopPropagation(), u(f)), t({ value: f, questionId: a, type: g }, !0); }, onKeyDown: (C) => { var Q, P; const q = b.querySelectorAll("button.nps-number"); C.key === "ArrowRight" ? (Q = q[f + 1]) == null || Q.focus() : C.key === "ArrowLeft" ? (P = q[f - 1]) == null || P.focus() : C.key !== "Enter" && C.key !== " " || (d && (C.preventDefault(), C.stopPropagation(), u(f)), t({ value: f, questionId: a, type: g }, !0)); }, onPointerDown: (C) => { C.currentTarget.style.zIndex = "2", C.currentTarget.style.borderColor = h; }, onPointerLeave: (C) => { C.currentTarget.style.zIndex = "auto", C.currentTarget.style.borderColor = Ae; }, style: v === f ? { backgroundColor: h, color: "#fff" } : void 0, tabIndex: 0, children: f }, f)) }), e("div", { className: "ul-card--nps__labels", children: [e("span", { children: y }), e("span", { children: p })] })] }), !r.required && !d && e(me, { children: e("div", { className: "ul-vertical-centered-container", children: e(ee, { onClick: (k) => { k.preventDefault(), k.stopPropagation(), t({ value: null, questionId: a, type: g }, !0); }, children: he(r) }) }) })] })] }, a); }, Or = (n) => { const { className: i, message: c, next: r, properties: t, questionId: a, type: g, showIndividualSubmit: v = !1, onSubmitButtonClick: u } = n, h = g === "aidynamicfollowup" || g === "aidynamicstandalone", o = h ? n.loading : void 0, { border: b, useMobileStyling: d, update: N, isLongFormSurvey: l, focusedQuestionId: y, setFocusedQuestionId: p, isPreview: k } = X((w) => ({ border: w.border, useMobileStyling: w.useMobileStyling, update: w.update, isLongFormSurvey: oe(w.studyType), focusedQuestionId: w.focusedQuestionId, setFocusedQuestionId: w.setFocusedQuestionId, isPreview: w.isPreview })), [f, C] = z(""), q = ne(null), Q = l && y === a; re(() => { var w, U; l && !k && (Q ? (w = q.current) == null || w.focus() : (U = q.current) == null || U.blur()); }, [l, Q, k]); const P = f.trim(), A = t.required === !0 && !P, m = Ir(q, () => N()), x = (w) => { w.preventDefault(), w.stopPropagation(); const U = P.length > 0, I = !t.required || U; r({ value: f, questionId: a, type: g }, I), u && u(U); }, L = t && t.openTextPlaceholder ? t.openTextPlaceholder : ""; if ((o === Ee.failure || o === void 0) && h) return e(fe, {}); const M = o === Ee.inFlight, O = M ? "Preparing your next question" : c; return e("form", { className: H(i, "ul-card-text", "fade-in-transition", l && !Q && "ul-card--unfocused"), id: "text-form", onClick: () => { l && y !== a && p(a); }, children: [e(ae, { isRequired: l && (t == null ? void 0 : t.required), message: O, properties: t }), e(ge, { properties: t, children: e("div", { className: "ul-card-text", children: e(le, { children: [e("div", { className: "ul-card-text__container", children: e("textarea", { "aria-describedby": "ul-caption", "aria-labelledby": "ul-question", "aria-multiline": "true", "aria-placeholder": L, className: H(M && "ul-card-text__input__loading", te("ul-card-text__input", d)), "data-gramm": "false", disabled: M, maxLength: 5e3, name: "text", onBlur: (w) => { w.currentTarget.style.borderColor = Ae; }, onChange: (w) => { const { value: U } = w.currentTarget; if (m(), w.preventDefault(), w.stopPropagation(), C(U), l) { const I = U.trim().length > 0; r({ value: U, questionId: a, type: g }, I); } }, onFocus: (w) => { w.currentTarget.style.borderColor = b, p(a); }, placeholder: L, ref: q, role: "textbox", tabIndex: 0 }) }), t.footerHtml && e(Ne, { className: "footer", html: t.footerHtml }), v && e(Ce, { handleSubmit: x, isSubmitDisabled: A }), e(me, { children: !l && e(ee, { disabled: A || M, onClick: x, children: he(t) }) })] }) }) })] }, a); }, Ue = 1, er = 2, rr = 3, qe = (n) => n.type === "av_permission", Ge = (n) => n.type === "screen_permission", tr = (n, i) => n === void 0 ? Ue : n ? ((c, r) => !(qe(r) ? r.permissionDescriptors : []).includes("camera") || c.getVideoTracks().length > 0)(n, i) ? rr : Ue : er, je = { avStream: null, currentPage: null, mediaRecordingUids: null, nextQuestion: () => { }, passthroughData: void 0, recordingMediaTypes: void 0, screenPermissionRequested: !1, type: void 0 }, pe = dr((n) => ({ ...je, reset: () => { n(je); }, updatePage: (i) => { n(i); } })); function Fe({ currentPage: n, pages: i }) { const { avStream: c, recordingMediaTypes: r, updatePage: t } = pe.getState(), { recorderEventEmitter: a } = X.getState(); a.emit("av.permission", { "permission.descriptors": n.permissionDescriptors, "stream.ready": (g, v) => { if (c === g) return; let u = n; if (g && !n.permissionDescriptors.includes("camera")) { const h = i.indexOf(n), o = v != null && v.active ? h + 2 : h + 1; v != null && v.active && r && a.emit("begin.recording", { "recording.media.types": r, "start.recording.callback": (b) => t({ mediaRecordingUids: b }) }), u = i[o]; } t({ currentPage: u, avStream: g }); } }); } function Qe({ status: n }) { const { nextQuestion: i, passthroughData: c, mediaRecordingUids: r, reset: t } = pe.getState(), { recorderEventEmitter: a, handleUploadUpdate: g, index: v } = X.getState(), u = { value: { taskStatus: n }, type: "recordedtask", questionId: (c == null ? void 0 : c.questionId) || 1 }; c && a.emit("finish.task", { "begin.callback": (h) => { g({ mediaRecordingUid: h, isSubmitted: !0, progressPct: 0, isComplete: !1 }); }, "progress.callback": (h, o) => { g({ mediaRecordingUid: h, progressPct: o.detail, isSubmitted: !1, isComplete: !1 }); }, "upload.callback": (h) => { h && g({ mediaRecordingUid: h, isComplete: !0, isSubmitted: !0, progressPct: 100 }); }, "passthrough.data": c, "current.index": v, "task.response": u, "task.complete.callback": (h) => { u.value.taskDurationMillisecond = h, r && (u.value.mediaRecordingUids = r), t(), i(u); } }); } function Oe({ pages: n, setIsRequestingPermission: i }) { const { recorderEventEmitter: c, eventEmitFn: r } = X.getState(), { updatePage: t, currentPage: a, recordingMediaTypes: g, screenPermissionRequested: v } = pe.getState(); if (!a) return; const u = n.indexOf(a); switch (a.type) { case "av_permission": { const h = v ? u + 2 : u + 1; return v && g && c.emit("begin.recording", { "recording.media.types": g, "start.recording.callback": (o) => { t({ mediaRecordingUids: o }); } }), void t({ currentPage: n[h] }); } case "screen_permission": return void c.emit("screen.permission", { "screen.permission.requested": i, "stream.ready.callback": (h, o) => { const b = o ? n[u + 1] : a; o && g && c.emit("begin.recording", { "recording.media.types": g, "start.recording.callback": (d) => { t({ captureStream: o, mediaRecordingUids: d }); } }), t({ currentPage: b, screenPermissionRequested: !0, captureStream: o }); } }); case "start_task": return r("recorded.task.start"), c.emit("recorded.task.start"), c.emit("start.task"), void t({ currentPage: n[u + 1], screenPermissionRequested: !0 }); case "complete_task": return; } } const nr = "ul-permission-graphics-container", ir = "ul-permission-body", sr = H(nr, "ul_recorded-task-inset-spacing"), Le = H("ul-horizontal-button-container", "ul-horizontal-button-container-left"), ar = ({ richTextBody: n }) => e(Ne, { className: "ul-rich-text-body", html: n, id: "ul-task-detail-container" }), De = ({ required: n, skipButtonText: i, bottom: c = !1 }) => n ? null : e(ee, { className: H(c && "ul-skip-button-below", "ul-button-inactive"), onClick: Qe.bind(null, { status: "abandoned" }), children: i || "Skip" }), $e = (n) => { const { avStream: i, captureStream: c, recordingMediaTypes: r, updatePage: t } = pe.getState(), a = (r == null ? void 0 : r.includes("audio")) || (r == null ? void 0 : r.includes("video")); re(() => { const g = setInterval(() => { a && i && !i.active ? t({ avStream: null, currentPage: n[0] }) : c && c.active || t({ captureStream: void 0, currentPage: n[a ? 1 : 0] }); }, 1e3); return () => clearInterval(g); }, [i, c, a, n, r, t]); }, $r = ({ content: n, pages: i, required: c }) => { const { buttonText: r, skipButtonText: t, taskDetail: a } = n; return $e(i), e("div", { className: "ul-task-page", children: [a && e(ar, { richTextBody: a }), e("div", { className: Le, children: [e(ee, { onClick: Oe.bind(null, { pages: i }), children: r }), e(De, { required: c, skipButtonText: t })] })] }, "start-task"); }, Vr = ({ content: n, pages: i, properties: c }) => { const { buttonText: r, skipButtonText: t } = n; return $e(i), e("div", { className: "ul-task-page", children: [n.taskDetail && e(ar, { richTextBody: n.taskDetail }), e(ge, { properties: c, children: e("div", { className: Le, children: [e(ee, { className: "ul-complete-task-button", onClick: Qe.bind(null, { status: "completed" }), children: r }), e(ee, { className: H("ul-button-inactive"), onClick: Qe.bind(null, { status: "given.up" }), children: t })] }) })] }, "complete-task"); }, Hr = ({ content: n, pages: i, required: c }) => { const { buttonText: r, skipButtonText: t } = n, [a] = X((u) => [u.tabTitle]), [g, v] = z(!1); return e("div", { children: [e("div", { className: sr, children: [e("p", { style: { marginTop: "auto" }, children: n.selectTabText }), e("div", { className: "ul-select-tab-container", children: e("p", { className: ir, children: a }) })] }), e("div", { className: c ? "" : Le, children: [e(ee, { disabled: g, onClick: Oe.bind(null, { pages: i, setIsRequestingPermission: v }), children: r }), e(De, { required: c, skipButtonText: t })] })] }); }, Gr = ({ content: n }) => e(Ne, { className: H(nr, "ul_permission_svg_container", "ul_recorded-task-inset-spacing", "ul-center-horizontally"), html: n.svg }, "ul-permission-request-graphic"), jr = ({ content: n, pages: i, required: c }) => { const { permissionDeniedHeadline: r, permissionDeniedBody: t, skipButtonText: a, tryAgainButtonText: g } = n, v = qe(i[0]) ? i[0] : null; return re(() => { const u = setInterval(() => { v !== null && Fe({ currentPage: v, pages: i }); }, 1e3); return () => clearInterval(u); }, [v, i]), v ? e("div", { children: [e("div", { className: sr, children: e("p", { className: "ul-av-permission-denied-paragraph", children: [e("span", { className: "ul-av-permission-denied-headline", children: r }), e("span", { className: ir, children: t })] }) }), e("div", { className: Le, children: [e(ee, { onClick: Fe.bind(null, { currentPage: v, pages: i }), children: g }), e(De, { required: c, skipButtonText: a })] })] }) : null; }, Zr = ({ stream: n }) => e("video", { autoPlay: !0, className: H("ul_recorded-task-inset-spacing"), id: "ul-record-task-video-preview", muted: !0, ref: (i) => { i && (i.srcObject = n || null); } }), zr = ({ content: n, pages: i, required: c }) => { const { skipButtonText: r } = n, { avStream: t } = pe.getState(); return $e(i), e("div", { children: [e(Zr, { stream: t }), e("div", { className: "ul-vertical-button-container-center", children: [e(ee, { onClick: Oe.bind(null, { pages: i }), children: n.buttonText }), e(De, { bottom: !0, required: c, skipButtonText: r })] })] }); }, Wr = ({ properties: n }) => { const { pages: i, required: c } = n, { avStream: r, currentPage: t } = pe.getState(); if (t === void 0) return null; switch (t == null ? void 0 : t.type) { case "av_permission": { const a = tr(r, t); return a === Ue ? e(Gr, { content: t }) : e(a === er ? jr : zr, { content: t, pages: i, required: c }); } case "screen_permission": return e(Hr, { content: t, pages: i, required: c }); case "start_task": return e($r, { content: t, pages: i, required: c }); case "complete_task": return e(Vr, { content: t, pages: i, properties: n }); default: return null; } }, Yr = ({ className: n, properties: i, next: c, questionId: r }) => { const t = X(), { surveyId: a, responseGroupUid: g, userId: v, update: u } = t, h = pe(), { screenPermissionRequested: o } = h, b = pe((p) => p.avStream); let d = pe((p) => p.currentPage); d || (d = function({ pages: p, userId: k, responseGroupUid: f, surveyId: C, questionId: q, next: Q }) { const { updatePage: P } = pe.getState(), { eventEmitFn: A, recorderEventEmitter: m } = X.getState(), x = { questionId: q, surveyId: C, visitorId: k, responseGroupUid: f }; let L = 0; m.emit("recorded.task.permission.screen"), A("recorded.task.permission.screen"), m.emit("permission.status", { "permission.status.callback": (O, w, U, I) => { const $ = p[L], { type: _ } = $, B = ["screen"]; if (qe($)) { const { permissionDescriptors: G } = $, s = G == null ? void 0 : G.includes("microphone"), S = G == null ? void 0 : G.includes("camera"); s && B.push("audio"), S && B.push("video"), (O != null && O.active && !S || O != null && O.active && w) && L++; } Ge(p[L]) && U && (L++, m.emit("begin.recording", { "recording.media.types": B, "start.recording.callback": (G) => P({ mediaRecordingUids: G }) })), P({ currentPage: p[L], avStream: O, screenPermissionRequested: U, nextQuestion: Q, type: _, passthroughData: x, recordingMediaTypes: B, captureStream: I }); } }); const M = p[L]; return M.type === "av_permission" && Fe({ currentPage: M, pages: p }), M; }({ questionId: r, surveyId: a, next: (p) => { c(p, !0); }, pages: i.pages, responseGroupUid: g, userId: v })); let N = d.headline, l = d.captionText; const y = tr(b, d); return Ge(d) && o && (N = d.permissionDeniedHeadline, l = d.permissionDeniedCaptionText), qe(d) && y === rr && (N = d.permissionGrantedHeadline, l = d.permissionGrantedCaptionText), re(() => { u(); }, [u]), e("div", { className: H(n, "ul-center-horizontally", "fade-in-transition"), children: [e(ae, { isRequired: i == null ? void 0 : i.required, message: N, properties: { captionText: l } }), e(le, { children: e(Wr, { properties: i }) })] }); }, Kr = ({ richTextBody: n, plaintextBody: i }) => n ? e(Ne, { className: "ul-rich-text-body", html: n, id: "ul-card__text-url-body-container" }) : i ? e("div", { className: "ul-rich-text-body", id: "ul-card__text-url-body-container", children: (i ? i.split(/\n\s*\n/g) : []).map((c, r) => e("p", { children: c }, r)) }) : null, Xr = ({ className: n, message: i, next: c, properties: r, questionId: t, type: a }) => { const { visitorAttributes: g, isLongFormSurvey: v } = X((b) => ({ visitorAttributes: b.visitorAttributes, isLongFormSurvey: oe(b.studyType) })), u = (b, d = !1) => { c({ value: d ? { skipped: !0 } : void 0, questionId: t, type: a }, !0); }, h = _r(r && r.buttonUrl, g), o = v && r.promptActionType === cr.NO_BUTTON; return e("div", { className: H(n, "ul-card__text-url-prompt", "fade-in-transition"), children: [e(ae, { isRequired: v && (r == null ? void 0 : r.required), message: i, properties: { questionHtml: r.questionHtml } }), e(le, { children: e(Kr, { plaintextBody: r == null ? void 0 : r.body, richTextBody: r == null ? void 0 : r.richTextBody }) }), e(ge, { properties: r, children: !o && e(me, { children: e("div", { className: "ul-card-button-group", children: [e("a", { className: "ul-card-text__button ul-card__text-url-prompt-button", href: h, id: "ul-card-text__button", onClick: u, onKeyPress: (b) => { b.key !== "Enter" && b.key !== " " || c({ value: void 0, questionId: t, type: a }, !0); }, rel: "noreferrer", role: h ? "link" : "button", tabIndex: 0, target: "_blank", children: he(r) }), r.required === !1 && e("button", { className: "ul-card-skip__button", onClick: (b) => u(0, !0), children: Be(r) })] }) }) })] }, t); }, Jr = ({ className: n, questionId: i }) => { const { border: c, destroy: r, endCard: t, forceBrandedLogo: a, update: g } = X((h) => ({ border: h.border, destroy: h.destroy, endCard: h.endCard, forceBrandedLogo: h.forceBrandedLogo, update: h.update })); re(() => { setTimeout(() => { r(xr); }, a ? 4e3 : 2e3); }, [r, a]); const v = t && t.subheader ? e("p", { className: "ul-caption", children: t.subheader }) : null, u = t && t.headline ? t.headline : ""; return re(() => { g(); }, [g]), e("div", { className: H(n, "ul-card--thanks", "fade-in-transition"), children: e("div", { children: e("div", { className: "ul-card--thanks-content", children: [e("div", { className: "ul-thanks-check", children: e("svg", { "aria-labelledby": "title", fill: "none", height: "99", viewBox: "0 0 81 99", width: "81", xmlns: "http://www.w3.org/2000/svg", children: [e("path", { clipRule: "evenodd", d: "M40.5 77C60.9345 77 77.5 60.4345 77.5 40C77.5 19.5655 60.9345 3 40.5 3C20.0655 3 3.5 19.5655 3.5 40C3.5 60.4345 20.0655 77 40.5 77ZM80.5 40C80.5 62.0914 62.5914 80 40.5 80C18.4086 80 0.5 62.0914 0.5 40C0.5 17.9086 18.4086 0 40.5 0C62.5914 0 80.5 17.9086 80.5 40Z", fill: c, fillRule: "evenodd" }), e("path", { clipRule: "evenodd", d: "M55.025 22.9046C55.6299 23.4705 55.6616 24.4198 55.0956 25.0247C54.8724 25.2634 54.6109 25.5285 54.3157 25.8277C52.2547 27.9168 48.5549 31.667 44.8135 39.6658C43.2818 42.9406 42.0864 45.8386 41.0823 48.2729C40.6539 49.3116 40.2603 50.2659 39.8902 51.129C39.287 52.5359 38.7248 53.7508 38.1744 54.625C37.8997 55.0613 37.5806 55.4905 37.2017 55.8245C36.8201 56.1607 36.2613 56.5 35.5457 56.5C34.6742 56.5 34.0892 55.9692 33.7774 55.6083C33.4502 55.2296 33.1752 54.7511 32.9396 54.301C32.7305 53.9013 32.5088 53.4367 32.2797 52.9565C32.2429 52.8794 32.2059 52.8019 32.1688 52.7243C31.8942 52.1499 31.5959 51.534 31.2537 50.8868C29.8886 48.305 27.8539 45.2878 24.2343 43.1382C23.522 42.7152 23.2875 41.7949 23.7105 41.0826C24.1335 40.3703 25.0539 40.1358 25.7662 40.5588C30.0556 43.1062 32.4149 46.6647 33.9058 49.4845C34.2776 50.1876 34.5973 50.8487 34.8753 51.4302C34.9147 51.5124 34.9529 51.5926 34.9902 51.6707C35.2222 52.1567 35.4164 52.5637 35.5978 52.9102C35.6151 52.9434 35.6321 52.9754 35.6485 53.0061C36.0565 52.3531 36.5341 51.3434 37.133 49.9468C37.4781 49.1418 37.8572 48.2229 38.2761 47.2074C39.2886 44.7532 40.5339 41.7347 42.0961 38.3948C46.0591 29.9221 50.0641 25.8648 52.1535 23.7482C52.4423 23.4556 52.6944 23.2002 52.9048 22.9753C53.4708 22.3703 54.42 22.3387 55.025 22.9046ZM35.1994 53.5892C35.1994 53.5892 35.2 53.5888 35.2012 53.5879C35.2 53.5889 35.1994 53.5893 35.1994 53.5892ZM36.0666 53.6682C36.0732 53.674 36.0765 53.6775 36.0765 53.6777C36.0765 53.678 36.0732 53.6751 36.0666 53.6682Z", fill: c, fillRule: "evenodd" }), e("path", { d: "M69.5 97C69.5 98.1046 56.2924 99 40 99C23.7076 99 10.5 98.1046 10.5 97C10.5 95.8954 23.7076 95 40 95C56.2924 95 69.5 95.8954 69.5 97Z", fill: "black", fillOpacity: "0.2" })] }) }), e(ae, { message: u }), v] }) }) }, i); }, ye = "ul-card-video__player_recorder", Ze = "ul-video-btn", Me = 0, ze = 1, et = ({ className: n, message: i, next: c, properties: r, questionId: t, type: a }) => { const { apiURL: g, envId: v, handleUploadUpdate: u, headers: h, responseGroupUid: o, surveyId: b, update: d, viewDocument: N, visitorId: l } = X((I) => ({ apiURL: I.apiURL, envId: I.envId, handleUploadUpdate: I.handleUploadUpdate, headers: I.headers, responseGroupUid: I.responseGroupUid, surveyId: I.surveyId, update: I.update, viewDocument: I.viewDocument, visitorId: I.userId })), [y, p] = z(!1), [k, f] = z(null), [C, q] = z(null), [Q, P] = z(Me), [A, m] = z(null), [x, L] = z(null), M = r && r.videoUrl, O = Te((I) => { I && m(I); }, [m]); re(() => { const I = new ResizeObserver(() => { setTimeout(d, 0); }); return x && I.observe(x), A && I.observe(A), () => { I.disconnect(); }; }, [d, x, A]); const w = (I, $) => { I === se.UPLOAD_STARTED ? (f($[se.UPLOAD_ID]), q($[se.MEDIA_RECORDING_UID]), p(!0)) : I === se.DELETE ? (f(null), q(null), p(!1)) : I === se.UPLOAD_PROGRESS ? isNaN($[se.UPLOAD_PROGRESS_PCT]) ? u({ mediaRecordingUid: $[se.MEDIA_RECORDING_UID], isComplete: !0 }) : u({ mediaRecordingUid: $[se.MEDIA_RECORDING_UID], progressPct: $[se.UPLOAD_PROGRESS_PCT] }) : I === se.UPLOAD_FINISHED && u({ mediaRecordingUid: $[se.MEDIA_RECORDING_UID], isComplete: !0 }); }, U = (I) => { I.preventDefault(), I.stopPropagation(), document.getElementById(ye) && wr(ye), k && C ? (u({ mediaRecordingUid: C, isSubmitted: !0 }), c({ value: { mediaRecordingUid: C }, questionId: t, type: a }, !0)) : c({ value: null, questionId: t, type: a }, !0); }; return e("form", { className: H(n, "ul-card--video", "fade-in-transition"), id: "ul-video-interview-form", children: [e(ae, { isRequired: r == null ? void 0 : r.required, message: i, properties: r }), e(le, { children: [e("div", { id: "ul-question-player-container", ref: O, style: { display: Q === Me ? "" : "none" }, children: [e("div", { id: ye, ref: (I) => { if (I && I.children.length === 0 && !r.hideRecordedPrompt) { L(I); const $ = Cr(ye, { src: M, type: "application/x-mpegURL" }, void 0, r.mediaType === se.MEDIA_TYPE_AUDIO, g, N); I.appendChild($); } } }), e(ge, { properties: r, children: e("button", { className: `${Ze} ul-record-response-btn`, onClick: (I) => { I.preventDefault(), I.stopPropagation(), document.getElementById(ye) && Tr(ye), P(ze); } }) })] }), e("div", { style: { display: Q === ze ? "block" : "none" }, children: [e("button", { className: `${Ze} ul-back-question-btn`, onClick: (I) => { I.preventDefault(), I.stopPropagation(), P(Me); }, style: { display: r.hideRecordedPrompt ? "none" : "block" } }), e("div", { id: "ul-recorder-player-container", ref: (I) => { if (I && I.children.length === 0) { L(I); const $ = Nr(ye, { surveyId: b, responseGroupUid: o, questionId: t, visitorId: l, envId: v }, g, w, void 0, { ...h, "x-ul-video-recorder-origin": "sdk" }, r.mediaType === se.MEDIA_TYPE_AUDIO, N); I.appendChild($); } } })] })] }), e(me, { children: [e(ee, { disabled: !y, onClick: U, children: he(r) }), e("button", { className: "ul-card-text__button ul-button-inactive ul-card-skip__button", id: "ul-card-video__skip_button", onClick: U, style: { display: r.required ? "none" : "block", ...y ? { display: "none" } : {} }, children: Be(r) })] })] }); }, rt = ({ className: n }) => { const { uploadProgress: i } = X((a) => ({ uploadProgress: a.uploadProgress })); let c, r; Object.values(i).filter((a) => a.isSubmitted).length > 1 ? (c = "Your responses are processing", r = "Please keep this tab open until your responses are fully processed.") : (c = "Your response is processing", r = "Please keep this tab open until your response is fully processed."); const t = Math.round(Math.min(99, ...Object.values(i).filter((a) => a.isSubmitted).map((a) => a.progressPct || 0))); return e("div", { className: H(n, "ul-card--uploading", "fade-in-transition"), children: [e("div", { "aria-busy": "true", "aria-label": "Processing...", "aria-live": "polite", className: "ul-loading-spinner-container", role: "progressbar", children: e("div", { className: "ul-loading-spinner", children: [e("div", { className: "first" }), e("div", { className: "second" }), e("div", { className: "third" }), e("div", { className: "fourth" })] }) }), e(ae, { message: `${c} (${t}% complete)` }), e("p", { className: "ul-caption", children: r })] }); }, lr = ur(void 0), tt = ({ value: n, children: i }) => e(lr.Provider, { value: n, children: i }), nt = ({ isRightLabel: n, isLeftLabel: i }) => n ? ue.RIGHT : i ? ue.LEFT : null, it = "Best", st = "Worst", at = ({ className: n, labels: i, message: c, properties: r, options: t, questionId: a, type: g, next: v }) => { var q, Q, P, A; const [u, h] = z(t.map((m, x) => ({ ...m, label: m.label === "" ? `Item ${x + 1}` : m.label, isRightLabel: !1, isLeftLabel: !1 }))), o = (() => { const m = pr(lr); if (m === void 0) throw new Error("usePreviousResponses must be used within a PreviousResponsesProvider"); return m; })(), b = { padding: "24px", display: "flex", cursor: "pointer", width: "auto" }, [d, N] = z(!1); re(() => { const m = u.findIndex(($) => $.isRightLabel), x = u.findIndex(($) => $.isLeftLabel), L = m !== -1 && x !== -1; N(L); const M = !r.required || r.required && L, O = u.map(($) => ({ id: $.id, option: $.label, selected: nt($) })), w = Math.floor(a), U = Object.keys(o).filter(($) => $.startsWith(w.toString())).map(Number).sort(($, _) => $ - _).at(-1), I = []; if (typeof U == "number") { const $ = o[U], _ = JSON.parse($); I.push(..._); } I.push(O), setTimeout(() => { v({ value: I, questionId: a, type: g }, M, L), N(!1); }, L ? 500 : 0); }, [u]); const { border: l, useMobileStyling: y, enableCspTrustedTypes: p } = X((m) => ({ border: m.border, useMobileStyling: m.useMobileStyling, enableCspTrustedTypes: m.enableCspTrustedTypes })), k = (m, x) => () => { d || h((L) => ((M, O, w) => M.map((U) => U.id === O ? { ...U, isRightLabel: w === ue.RIGHT, isLeftLabel: w === ue.LEFT } : w === ue.RIGHT && U.isRightLabel || w === ue.LEFT && U.isLeftLabel ? { ...U, isRightLabel: !1, isLeftLabel: !1 } : U))(L, m, x)); }, f = (q = r.ratingIcons) == null ? void 0 : q[0].svg, C = (Q = r.ratingIcons) == null ? void 0 : Q[1].svg; return e("form", { className: H(n, "ul-card-maxdiff", "fade-in-transition"), children: [e(ae, { isRequired: r == null ? void 0 : r.required, message: c, properties: r }), e(le, { children: e("div", { className: "ul-card--maxdiff__question-inner-container", children: [e("div", { className: "ul-card-maxdiff__label", children: (i == null ? void 0 : i.left) || ((P = r == null ? void 0 : r.labels) == null ? void 0 : P.left) || it }), e("div", { children: " " }), e("div", { className: "ul-card-maxdiff__label", children: (i == null ? void 0 : i.right) || ((A = r == null ? void 0 : r.labels) == null ? void 0 : A.right) || st }), u.map(({ id: m, label: x, isLeftLabel: L, isRightLabel: M }) => e(fe, { children: [e("div", { className: "ul-card-maxdiff__option-control " + (C ? "smiley" : ""), children: C ? e(We, { ariaPressed: L, className: L ? "ul-card-maxdiff__option-btn ul-card-maxdiff__option-selected good" : "ul-card-maxdiff__option-btn", enableCspTrustedTypes: p, html: C, id: `smiley-good-${m}`, onClick: k(m, ue.LEFT) }) : e(xe, { allowTextEntry: !1, ariaLabel: `bestLabel-${x}`, border: l, choiceStyle: b, error: !1, id: `${m}`, isRadio: !0, isSelected: L, onUserInputChanged: k(m, ue.LEFT), useMobileStyling: y }) }), e("div", { className: "ul-card-maxdiff__option-label", children: x }), e("div", { className: "ul-card-maxdiff__option-control " + (f ? "smiley" : ""), children: f ? e(We, { ariaPressed: M, className: M ? "ul-card-maxdiff__option-btn ul-card-maxdiff__option-selected bad" : "ul-card-maxdiff__option-btn", enableCspTrustedTypes: p, html: f, id: `smiley-bad-${m}`, onClick: k(m, ue.RIGHT) }) : e(xe, { allowTextEntry: !1, ariaLabel: `worstLabel-${x}`, border: l, choiceStyle: b, error: !1, id: `${m}`, isRadio: !0, isSelected: M, onUserInputChanged: k(m, ue.RIGHT), useMobileStyling: y }) })] }))] }) })] }, a); }, We = ({ enableCspTrustedTypes: n, ariaPressed: i, className: c, html: r, id: t, onClick: a }) => { const g = ve(() => Xe(r, n), [n, r]); return e("span", { "aria-pressed": i, className: c, dangerouslySetInnerHTML: { __html: g }, id: t, onClick: a, tabIndex: 0, type: "button" }); }, lt = ({ className: n, labels: i, message: c, next: r, properties: t, questionId: a, type: g, onSubmitButtonClick: v, options: u, showIndividualSubmit: h = !1 }) => { const o = ne(null), b = ne(0), d = ne(0), N = ne(null), l = ne(!1), y = ne([]), [p, k] = z(() => (t == null ? void 0 : t.required) === !0), [f, C] = z(!1), [q, Q] = z(() => u.map((T) => ({ ...T, rank: null }))), P = ve(() => Array.from({ length: u.length }, (T, V) => V + 1), [u.length]), { isLongFormSurvey: A, focusedQuestionId: m, setFocusedQuestionId: x, useMobileStyling: L, isPreview: M, headers: O } = X((T) => ({ useMobileStyling: T.useMobileStyling, isLongFormSurvey: oe(T.studyType), focusedQuestionId: T.focusedQuestionId, setFocusedQuestionId: T.setFocusedQuestionId, isPreview: T.isPreview, headers: T.headers })), w = (O == null ? void 0 : O["userleap-platform"]) === "android", U = L && !M && !w, I = !U && !w, $ = A && m === a, _ = (T) => { T.preventDefault(), R(q), v && v(f); }, B = (T, V) => { Q((j) => { const F = parseInt(V), Y = j.map((K) => ({ ...K })); Y.some((K) => K.rank == null) && Y.forEach((K, Se) => K.rank = Se + 1); const de = Y.findIndex((K) => K.id === T); if (de === -1) return j; const J = Y[de].rank; return F < J ? Y.forEach((K) => { K.id !== T && K.rank >= F && K.rank < J && (K.rank = K.rank + 1); }) : F > J && Y.forEach((K) => { K.id !== T && K.rank > J && K.rank <= F && (K.rank = K.rank - 1); }), Y[de].rank = F, Y.sort((K, Se) => K.rank - Se.rank), Z(Y), Y; }); }, G = (T, V) => { for (let j = 0; j < y.current.length; j++) { const F = y.current[j]; if (!F || F === N.current) continue; const Y = F.getBoundingClientRect(); if (T >= Y.left && T <= Y.right && V >= Y.top && V <= Y.bottom) return { element: F, index: j }; } return null; }, s = (T) => (V) => { if (!U) return; V.preventDefault(), V.stopPropagation(), l.current = !0, o.current = T;