import {
    S as K,
    a as O,
    s as G,
    T as U,
    n as R,
    f as b,
    t as u,
    C as L,
    l as f,
    D as E,
    m as h,
    z as q,
    c0 as ue,
    e as w,
    p as k,
    b as C,
    F as z,
    q as v,
    r as y,
    x as S,
    a6 as de,
    a2 as V,
    H as A,
    ba as ge,
    bC as me,
    J as D,
    K as _e,
    a3 as ce,
    G as J,
    b6 as $e,
    v as fe,
    a0 as pe,
    b7 as Z,
    c1 as be,
    c2 as he,
    E as ke,
    av as ve,
    B as x,
    bY as ye,
    o as Ie,
    bB as we,
    I as Ce,
    X as Me,
    c3 as Be,
    c4 as Pe,
    c5 as We,
    c6 as Te,
    c7 as ee,
    bK as Fe,
    ab as Ae
} from "./main-C0LpgozU.js";
import {
    M as Le,
    L as Ee,
    b as He,
    e as te,
    C as Ne,
    W as Ue,
    g as De,
    a as Se,
    F as qe,
    A as Ge,
    B as Ke,
    i as Oe
} from "./WidgetMessengerInput-9YvnQaoD.js";

function ne(l, n, r) {
    const e = l.slice();
    return e[4] = n[r], e
}

function re(l) {
    let n, r, e;
    return r = new Le({
        props: {
            $$slots: {
                default: [Re]
            },
            $$scope: {
                ctx: l
            }
        }
    }), {
        c() {
            n = w("div"), k(r.$$.fragment), C(n, "class", "text-sm leading-[22px] line-clamp-5 color-slate-800"), C(n, "data-testid", z.popupMessage)
        },
        m(t, s) {
            b(t, n, s), v(r, n, null), e = !0
        },
        p(t, s) {
            const a = {};
            s & 130 && (a.$$scope = {
                dirty: s,
                ctx: t
            }), r.$set(a)
        },
        i(t) {
            e || (u(r.$$.fragment, t), e = !0)
        },
        o(t) {
            f(r.$$.fragment, t), e = !1
        },
        d(t) {
            t && h(n), y(r)
        }
    }
}

function Re(l) {
    let n, r;
    return n = new Ee({
        props: {
            text: l[1].content.text
        }
    }), {
        c() {
            k(n.$$.fragment)
        },
        m(e, t) {
            v(n, e, t), r = !0
        },
        p(e, t) {
            const s = {};
            t & 2 && (s.text = e[1].content.text), n.$set(s)
        },
        i(e) {
            r || (u(n.$$.fragment, e), r = !0)
        },
        o(e) {
            f(n.$$.fragment, e), r = !1
        },
        d(e) {
            y(n, e)
        }
    }
}

function se(l) {
    let n = l[0].items.length,
        r, e, t = ae(l);
    return {
        c() {
            t.c(), r = R()
        },
        m(s, a) {
            t.m(s, a), b(s, r, a), e = !0
        },
        p(s, a) {
            a & 1 && G(n, n = s[0].items.length) ? (L(), f(t, 1, 1, S), E(), t = ae(s), t.c(), u(t, 1), t.m(r.parentNode, r)) : t.p(s, a)
        },
        i(s) {
            e || (u(t), e = !0)
        },
        o(s) {
            f(t), e = !1
        },
        d(s) {
            s && h(r), t.d(s)
        }
    }
}

function le(l) {
    let n, r;
    return n = new Ne({
        props: {
            card: l[4],
            isCompact: !0,
            fullWidth: l[2]
        }
    }), {
        c() {
            k(n.$$.fragment)
        },
        m(e, t) {
            v(n, e, t), r = !0
        },
        p(e, t) {
            const s = {};
            t & 1 && (s.card = e[4]), t & 4 && (s.fullWidth = e[2]), n.$set(s)
        },
        i(e) {
            r || (u(n.$$.fragment, e), r = !0)
        },
        o(e) {
            f(n.$$.fragment, e), r = !1
        },
        d(e) {
            y(n, e)
        }
    }
}

function ze(l) {
    let n, r, e = te(l[0].items),
        t = [];
    for (let a = 0; a < e.length; a += 1) t[a] = le(ne(l, e, a));
    const s = a => f(t[a], 1, 1, () => {
        t[a] = null
    });
    return {
        c() {
            for (let a = 0; a < t.length; a += 1) t[a].c();
            n = R()
        },
        m(a, i) {
            for (let o = 0; o < t.length; o += 1) t[o] && t[o].m(a, i);
            b(a, n, i), r = !0
        },
        p(a, i) {
            if (i & 5) {
                e = te(a[0].items);
                let o;
                for (o = 0; o < e.length; o += 1) {
                    const d = ne(a, e, o);
                    t[o] ? (t[o].p(d, i), u(t[o], 1)) : (t[o] = le(d), t[o].c(), u(t[o], 1), t[o].m(n.parentNode, n))
                }
                for (L(), o = e.length; o < t.length; o += 1) s(o);
                E()
            }
        },
        i(a) {
            if (!r) {
                for (let i = 0; i < e.length; i += 1) u(t[i]);
                r = !0
            }
        },
        o(a) {
            t = t.filter(Boolean);
            for (let i = 0; i < t.length; i += 1) f(t[i]);
            r = !1
        },
        d(a) {
            a && h(n), me(t, a)
        }
    }
}

function ae(l) {
    let n, r, e, t;
    return e = new He({
        props: {
            controlsTop: "4rem",
            controls: !de(),
            $$slots: {
                default: [ze]
            },
            $$scope: {
                ctx: l
            }
        }
    }), {
        c() {
            n = w("div"), r = w("div"), k(e.$$.fragment), C(r, "class", "relative w-56"), V(r, "w-full", l[2]), C(n, "class", "w-full flex-center pt-2")
        },
        m(s, a) {
            b(s, n, a), A(n, r), v(e, r, null), t = !0
        },
        p(s, a) {
            const i = {};
            a & 133 && (i.$$scope = {
                dirty: a,
                ctx: s
            }), e.$set(i), (!t || a & 4) && V(r, "w-full", s[2])
        },
        i(s) {
            t || (u(e.$$.fragment, s), t = !0)
        },
        o(s) {
            f(e.$$.fragment, s), t = !1
        },
        d(s) {
            s && h(n), y(e)
        }
    }
}

function Je(l) {
    var a;
    let n, r, e, t = ((a = l[1]) == null ? void 0 : a.content.text) && re(l),
        s = l[0] && se(l);
    return {
        c() {
            t && t.c(), n = U(), s && s.c(), r = R()
        },
        m(i, o) {
            t && t.m(i, o), b(i, n, o), s && s.m(i, o), b(i, r, o), e = !0
        },
        p(i, [o]) {
            var d;
            (d = i[1]) != null && d.content.text ? t ? (t.p(i, o), o & 2 && u(t, 1)) : (t = re(i), t.c(), u(t, 1), t.m(n.parentNode, n)) : t && (L(), f(t, 1, 1, () => {
                t = null
            }), E()), i[0] ? s ? (s.p(i, o), o & 1 && u(s, 1)) : (s = se(i), s.c(), u(s, 1), s.m(r.parentNode, r)) : s && (L(), f(s, 1, 1, () => {
                s = null
            }), E())
        },
        i(i) {
            e || (u(t), u(s), e = !0)
        },
        o(i) {
            f(t), f(s), e = !1
        },
        d(i) {
            i && (h(n), h(r)), t && t.d(i), s && s.d(i)
        }
    }
}

function Qe(l, n, r) {
    let e, t;
    q(l, ue, i => r(1, t = i));
    const s = i => {
        const o = i.find(d => d.type === ge.AttachmentType.Cards);
        return o || null
    };
    let a;
    return l.$$.update = () => {
        l.$$.dirty & 2 && r(0, e = t && s(t.attachments)), l.$$.dirty & 1 && e && r(2, a = e.items.length === 1)
    }, [e, t, a]
}
class Xe extends K {
    constructor(n) {
        super(), O(this, n, Qe, Je, G, {})
    }
}

function Ye(l) {
    let n, r, e, t, s;
    return r = new Ue({}), {
        c() {
            n = w("div"), k(r.$$.fragment)
        },
        m(a, i) {
            b(a, n, i), v(r, n, null), e = !0, t || (s = [D(n, "click", _e(l[0])), D(n, "keydown", l[1]), D(n, "keyup", l[2])], t = !0)
        },
        p: S,
        i(a) {
            e || (u(r.$$.fragment, a), e = !0)
        },
        o(a) {
            f(r.$$.fragment, a), e = !1
        },
        d(a) {
            a && h(n), y(r), t = !1, ce(s)
        }
    }
}

function je(l) {
    function n(t) {
        J.call(this, l, t)
    }

    function r(t) {
        J.call(this, l, t)
    }

    function e(t) {
        J.call(this, l, t)
    }
    return [n, r, e]
}
class Ve extends K {
    constructor(n) {
        super(), O(this, n, je, Ye, G, {})
    }
}

function ie(l) {
    var o, d, $, g;
    let n, r, e, t, s = (((o = l[4]) == null ? void 0 : o.name) || ((d = l[3]) == null ? void 0 : d.fullname)) + "",
        a, i;
    return r = new Se({
        props: {
            avatar: (($ = l[4]) == null ? void 0 : $.avatarUrl) || ((g = l[3]) == null ? void 0 : g.avatar),
            isBot: !!l[0]
        }
    }), {
        c() {
            n = w("div"), k(r.$$.fragment), e = U(), t = w("div"), a = fe(s), C(n, "class", "flex-center flex-shrink-0"), C(t, "class", "ml-3 mr-10 font-bold truncate color-slate-800")
        },
        m(c, m) {
            b(c, n, m), v(r, n, null), b(c, e, m), b(c, t, m), A(t, a), i = !0
        },
        p(c, m) {
            var I, P, W, _;
            const M = {};
            m & 24 && (M.avatar = ((I = c[4]) == null ? void 0 : I.avatarUrl) || ((P = c[3]) == null ? void 0 : P.avatar)), m & 1 && (M.isBot = !!c[0]), r.$set(M), (!i || m & 24) && s !== (s = (((W = c[4]) == null ? void 0 : W.name) || ((_ = c[3]) == null ? void 0 : _.fullname)) + "") && pe(a, s)
        },
        i(c) {
            i || (u(r.$$.fragment, c), i = !0)
        },
        o(c) {
            f(r.$$.fragment, c), i = !1
        },
        d(c) {
            c && (h(n), h(e), h(t)), y(r)
        }
    }
}

function Ze(l) {
    let n, r, e = (l[3] || l[4]) && ie(l);
    return {
        c() {
            e && e.c(), n = R()
        },
        m(t, s) {
            e && e.m(t, s), b(t, n, s), r = !0
        },
        p(t, [s]) {
            t[3] || t[4] ? e ? (e.p(t, s), s & 24 && u(e, 1)) : (e = ie(t), e.c(), u(e, 1), e.m(n.parentNode, n)) : e && (L(), f(e, 1, 1, () => {
                e = null
            }), E())
        },
        i(t) {
            r || (u(e), r = !0)
        },
        o(t) {
            f(e), r = !1
        },
        d(t) {
            t && h(n), e && e.d(t)
        }
    }
}

function xe(l, n, r) {
    let e, t, s, a = S,
        i = () => (a(), a = Z(e, m => r(3, s = m)), e),
        o, d = S,
        $ = () => (d(), d = Z(t, m => r(4, o = m)), t);
    l.$$.on_destroy.push(() => a()), l.$$.on_destroy.push(() => d());
    let {
        agentId: g
    } = n, {
        identityId: c
    } = n;
    return l.$$set = m => {
        "agentId" in m && r(5, g = m.agentId), "identityId" in m && r(0, c = m.identityId)
    }, l.$$.update = () => {
        l.$$.dirty & 32 && i(r(2, e = $e(g ? ? ""))), l.$$.dirty & 1 && $(r(1, t = De(c || "")))
    }, [c, t, e, s, o, g]
}
class et extends K {
    constructor(n) {
        super(), O(this, n, xe, Ze, G, {
            agentId: 5,
            identityId: 0
        })
    }
}

function oe(l) {
    let n, r, e, t, s, a, i, o, d, $, g, c, m, M, I, P, W, _;
    n = new qe({});
    const Q = [nt, tt],
        T = [];

    function X(p, B) {
        var H, N;
        return p[0].agentId || (N = (H = p[0]) == null ? void 0 : H.trigger) != null && N.identityId ? 0 : 1
    }
    s = X(l), a = T[s] = Q[s](l), o = new Xe({});
    const Y = [st, rt],
        F = [];

    function j(p, B) {
        return p[2] ? 0 : 1
    }
    return g = j(l), c = F[g] = Y[g](l), I = new Ce({
        props: {
            icon: Me,
            iconDescription: "Close",
            testId: z.popupButtonClose
        }
    }), I.$on("click", l[6]), {
        c() {
            k(n.$$.fragment), r = U(), e = w("div"), t = w("div"), a.c(), i = U(), k(o.$$.fragment), d = U(), $ = w("div"), c.c(), m = U(), M = w("div"), k(I.$$.fragment), C(t, "class", "flex items-center mb-2"), C($, "class", "mt-4"), C(M, "class", "absolute top-2 right-2 text-gray-500"), C(e, "class", "relative p-4 bg-white rounded-lg cursor-pointer")
        },
        m(p, B) {
            v(n, p, B), b(p, r, B), b(p, e, B), A(e, t), T[s].m(t, null), A(e, i), v(o, e, null), A(e, d), A(e, $), F[g].m($, null), A(e, m), A(e, M), v(I, M, null), l[11](e), P = !0, W || (_ = [D(e, "click", l[5]), D(e, "mouseenter", l[7]), D(e, "mouseleave", l[8])], W = !0)
        },
        p(p, B) {
            let H = s;
            s = X(p), s === H ? T[s].p(p, B) : (L(), f(T[H], 1, 1, () => {
                T[H] = null
            }), E(), a = T[s], a ? a.p(p, B) : (a = T[s] = Q[s](p), a.c()), u(a, 1), a.m(t, null));
            let N = g;
            g = j(p), g === N ? F[g].p(p, B) : (L(), f(F[N], 1, 1, () => {
                F[N] = null
            }), E(), c = F[g], c ? c.p(p, B) : (c = F[g] = Y[g](p), c.c()), u(c, 1), c.m($, null))
        },
        i(p) {
            P || (u(n.$$.fragment, p), u(a), u(o.$$.fragment, p), u(c), u(I.$$.fragment, p), P = !0)
        },
        o(p) {
            f(n.$$.fragment, p), f(a), f(o.$$.fragment, p), f(c), f(I.$$.fragment, p), P = !1
        },
        d(p) {
            p && (h(r), h(e)), y(n, p), T[s].d(), y(o), F[g].d(), y(I), l[11](null), W = !1, ce(_)
        }
    }
}

function tt(l) {
    let n, r;
    return n = new Ge({}), {
        c() {
            k(n.$$.fragment)
        },
        m(e, t) {
            v(n, e, t), r = !0
        },
        p: S,
        i(e) {
            r || (u(n.$$.fragment, e), r = !0)
        },
        o(e) {
            f(n.$$.fragment, e), r = !1
        },
        d(e) {
            y(n, e)
        }
    }
}

function nt(l) {
    var e, t;
    let n, r;
    return n = new et({
        props: {
            agentId: l[0].agentId,
            identityId: (t = (e = l[0]) == null ? void 0 : e.trigger) == null ? void 0 : t.identityId
        }
    }), {
        c() {
            k(n.$$.fragment)
        },
        m(s, a) {
            v(n, s, a), r = !0
        },
        p(s, a) {
            var o, d;
            const i = {};
            a & 1 && (i.agentId = s[0].agentId), a & 1 && (i.identityId = (d = (o = s[0]) == null ? void 0 : o.trigger) == null ? void 0 : d.identityId), n.$set(i)
        },
        i(s) {
            r || (u(n.$$.fragment, s), r = !0)
        },
        o(s) {
            f(n.$$.fragment, s), r = !1
        },
        d(s) {
            y(n, s)
        }
    }
}

function rt(l) {
    let n, r;
    return n = new Ke({
        props: {
            icon: Oe,
            isBlock: !0,
            testId: z.popupButton,
            $$slots: {
                default: [lt]
            },
            $$scope: {
                ctx: l
            }
        }
    }), {
        c() {
            k(n.$$.fragment)
        },
        m(e, t) {
            v(n, e, t), r = !0
        },
        p(e, t) {
            const s = {};
            t & 32792 && (s.$$scope = {
                dirty: t,
                ctx: e
            }), n.$set(s)
        },
        i(e) {
            r || (u(n.$$.fragment, e), r = !0)
        },
        o(e) {
            f(n.$$.fragment, e), r = !1
        },
        d(e) {
            y(n, e)
        }
    }
}

function st(l) {
    let n, r;
    return n = new Ve({}), {
        c() {
            k(n.$$.fragment)
        },
        m(e, t) {
            v(n, e, t), r = !0
        },
        p: S,
        i(e) {
            r || (u(n.$$.fragment, e), r = !0)
        },
        o(e) {
            f(n.$$.fragment, e), r = !1
        },
        d(e) {
            y(n, e)
        }
    }
}

function lt(l) {
    let n = l[4](l[3]) + "",
        r;
    return {
        c() {
            r = fe(n)
        },
        m(e, t) {
            b(e, r, t)
        },
        p(e, t) {
            t & 24 && n !== (n = e[4](e[3]) + "") && pe(r, n)
        },
        d(e) {
            e && h(r)
        }
    }
}

function at(l) {
    let n, r, e = l[0] && oe(l);
    return {
        c() {
            n = w("div"), e && e.c(), C(n, "data-testid", z.popup)
        },
        m(t, s) {
            b(t, n, s), e && e.m(n, null), r = !0
        },
        p(t, [s]) {
            t[0] ? e ? (e.p(t, s), s & 1 && u(e, 1)) : (e = oe(t), e.c(), u(e, 1), e.m(n, null)) : e && (L(), f(e, 1, 1, () => {
                e = null
            }), E())
        },
        i(t) {
            r || (u(e), r = !0)
        },
        o(t) {
            f(e), r = !1
        },
        d(t) {
            t && h(n), e && e.d()
        }
    }
}

function it(l, n, r) {
    let e, t, s, a, i, o;
    q(l, ue, _ => r(0, s = _)), q(l, be, _ => r(9, a = _)), q(l, he, _ => r(10, i = _)), q(l, ke, _ => r(4, o = _));
    let d, $ = () => Be.set(d.getBoundingClientRect().height);
    ve(() => {
        $(), x().addEventListener("visibilitychange", $)
    }), ye(() => {
        x().removeEventListener("visibilitychange", $)
    });
    const g = () => {
            Pe(), We()
        },
        c = () => {
            Te(!0)
        },
        m = () => {
            ee.set(!0)
        },
        M = () => {
            ee.set(!1)
        },
        I = async () => {
            await Fe(), $()
        },
        {
            popupTextareaEnabled: P
        } = Ie.getOptions();

    function W(_) {
        Ae[_ ? "unshift" : "push"](() => {
            d = _, r(1, d)
        })
    }
    return l.$$.update = () => {
        l.$$.dirty & 1024 && i && I(), l.$$.dirty & 512 && r(3, e = a ? "trigger.replyButton" : "trigger.openChatButton"), l.$$.dirty & 1 && r(2, t = P && s && !we(s))
    }, [s, d, t, e, o, g, c, m, M, a, i, W]
}
class ct extends K {
    constructor(n) {
        super(), O(this, n, it, at, G, {})
    }
}
export {
    ct as
    default
};
//# sourceMappingURL=WidgetPopup-RGh00qS7.js.map