;
! function() {
    try {
        var e = "undefined" != typeof globalThis ? globalThis : "undefined" != typeof global ? global : "undefined" != typeof window ? window : "undefined" != typeof self ? self : {},
            n = (new e.Error).stack;
        n && ((e._debugIds || (e._debugIds = {}))[n] = "87ef89dd-f606-76a6-7a6f-74c5238b4d2a")
    } catch (e) {}
}();
(globalThis.TURBOPACK || (globalThis.TURBOPACK = [])).push(["object" == typeof document ? document.currentScript : void 0, 644245, e => {
    "use strict";
    var t = e.i(284553),
        r = e.i(221628),
        a = e.i(964974),
        i = e.i(804599),
        n = e.i(397456),
        u = e.i(606231),
        l = e.i(425010),
        s = e.i(416340),
        c = e.i(491525),
        o = e.i(170236),
        m = e.i(17780),
        p = e.i(385158),
        f = e.i(85914),
        d = e.i(96515),
        b = e.i(691872),
        y = e.i(196593),
        g = e.i(631222),
        h = e.i(672226);
    e.s(["default", 0, function({
        event: e,
        width: S,
        height: C,
        onPricesChange: v,
        onLivePriceMessage: R
    }) {
        let {
            resolvedTheme: A
        } = (0, l.useTheme)(), P = "dark" === A, T = (0, s.useMemo)(() => (function(e) {
            let t = (0, h.parseAssetFromSlug)(e);
            if (!t) return null;
            let r = e.includes("-5m") || e.includes("-15m") || e.includes("-4h");
            return { ...t,
                symbol: (0, d.getChartSymbol)(t.abbreviation, "crypto"),
                usesChainlink: r,
                filterSymbol: r ? `${t.abbreviation.toLowerCase()}/usd` : (0, d.getChartSymbol)(t.abbreviation, "crypto"),
                topic: r ? "crypto_prices_chainlink" : "crypto_prices"
            }
        })(e.slug), [e.slug]), D = T ? .abbreviation, E = T ? .color, M = T ? .symbol, N = (0, s.useRef)(null), _ = (0, s.useRef)(null), O = (0, s.useRef)(null), L = (0, s.useRef)(null), k = (0, s.useRef)([]), I = (0, s.useRef)({
            width: S,
            height: C
        }), F = (0, s.useRef)(v), U = (0, s.useRef)(R);
        F.current = v, U.current = R, I.current = {
            width: S,
            height: C
        };
        let [V, w] = (0, s.useState)(!1), x = (0, s.useRef)(null), $ = (0, s.useRef)(null), B = (0, s.useRef)(null), K = (0, s.useCallback)(() => {
            F.current ? .(x.current, $.current)
        }, []), W = (0, s.useCallback)(() => {
            let e = B.current;
            e && (e.timeoutId && clearTimeout(e.timeoutId), e.frameId && cancelAnimationFrame(e.frameId), B.current = null)
        }, []), X = (0, s.useCallback)((e, t, r, a) => {
            let i = _.current,
                n = O.current;
            if (!i || !n) return;
            let u = Date.now(),
                l = Math.min((u - e) / t, 1),
                s = r + (a - r) * (0, p.easeInOutCubic)(l),
                c = Math.round(u / 1e3 * 100) / 100,
                o = n.data(),
                m = o[o.length - 1];
            if ((!m || m.time < c) && n.update({
                    time: c,
                    value: s
                }), 0 === l && W(), l < 1) {
                let i = setTimeout(() => {
                    B.current = {
                        frameId: requestAnimationFrame(() => {
                            X(e, t, r, a)
                        })
                    }
                }, 1e3 / d.MAX_UPDATES_PER_SECOND);
                B.current = {
                    timeoutId: i
                }
            }
        }, [W]), j = (0, h.useActiveMarket)(e), J = (0, s.useMemo)(() => (0, h.getVariantFromSlug)(e.slug), [e.slug]), {
            data: q
        } = (0, h.useCarouselTargetPrice)(e), {
            data: H
        } = (0, a.useQuery)({
            queryKey: ["carousel-price-history", M, j ? .eventStartTime, J, j ? .endDate],
            queryFn: async () => {
                let e = new URLSearchParams;
                D && e.set("symbol", D.toUpperCase()), j ? .eventStartTime && e.set("eventStartTime", j.eventStartTime), e.set("variant", J), j ? .endDate && e.set("endDate", j.endDate);
                let t = await fetch(`/api/crypto/price-history?${e.toString()}`);
                return t.ok ? t.json() : null
            },
            enabled: !!D && !!j ? .eventStartTime,
            staleTime: 6e4,
            gcTime: 3e5
        });
        (0, s.useEffect)(() => {
            let e = q ? .openPrice;
            null != e && Number.isFinite(e) && ($.current = e, L.current ? .setPrice(e), K())
        }, [q ? .openPrice, K]), (0, s.useEffect)(() => {
            if (!H ? .length || k.current.length > 0) return;
            let e = (0, f.dedupePoints)(H.filter(e => Number.isFinite(e.timestamp) && Number.isFinite(e.value)).sort((e, t) => e.timestamp - t.timestamp).map(f.toLineDataPoint));
            if (0 === e.length) return;
            k.current = e;
            let t = e[e.length - 1];
            t && (x.current = t.value, K()), O.current && _.current && (O.current.setData((0, b.interpolateSeriesData)(e, d.MAX_UPDATES_PER_SECOND)), _.current.timeScale().fitContent(), (0, f.applyChartOffset)(_.current), w(!0))
        }, [H, K]);
        let z = (0, s.useCallback)(() => {
            let e, t;
            if (!N.current || !D || !E) return;
            let {
                width: r,
                height: a
            } = I.current;
            if (r <= 0 || a <= 0) return;
            let n = (0, h.getAssetDecimals)(D),
                u = (0, i.createChart)(N.current, (0, f.createPriceChartConfig)(r, a, P)),
                l = u.addSeries(i.LineSeries, (e = (0, h.getAssetDecimals)(D), t = D === d.PriceMarketAssetAbbr.Bitcoin ? 20 : .05, {
                    lineType: i.LineType.Curved,
                    lineWidth: 2,
                    color: E,
                    lastValueVisible: !1,
                    priceLineVisible: !1,
                    lastPriceAnimation: i.LastPriceAnimationMode.Continuous,
                    crosshairMarkerVisible: !0,
                    crosshairMarkerRadius: 4,
                    priceScaleId: "overlay",
                    autoscaleInfoProvider: e => {
                        let r = e ? .();
                        if (r ? .priceRange) {
                            let e = Math.max(r.priceRange.maxValue - r.priceRange.minValue, t);
                            r.priceRange.minValue -= Math.max(.2 * e, 0), r.priceRange.maxValue += .2 * e
                        }
                        return r
                    },
                    priceFormat: {
                        type: "custom",
                        formatter: t => (0, y.formatCurrency)(t, {
                            decimals: e
                        })
                    }
                }));
            l.attachPrimitive(new m.Tooltip({
                lineColor: P ? "#97A5B466" : "#aeb4bc80",
                lineTopMargin: 35,
                topMargin: 0,
                asset: D,
                decimals: n
            })), l.attachPrimitive(new o.OverlayPriceScale({
                textColor: P ? "#7b8996" : "#77808d",
                backgroundColor: "rgba(255, 255, 255, 0.0)",
                pageBackgroundColor: P ? "#181D21" : "#ffffff",
                side: "right",
                decimals: n,
                gridLinesVisible: !0
            }));
            let s = new c.PriceLine(u, l, {
                annotation: {
                    textColor: "#ffffff",
                    backgroundColor: P ? "#586879" : "#939aa5"
                },
                priceLine: {
                    color: P ? "#97a5b466" : "#aeb4bc80"
                }
            });
            L.current = s, null != $.current && s.setPrice($.current), _.current = u, O.current = l, k.current.length > 0 && (l.setData((0, b.interpolateSeriesData)(k.current, d.MAX_UPDATES_PER_SECOND)), u.timeScale().fitContent(), (0, f.applyChartOffset)(u))
        }, [D, E, P]);
        (0, s.useEffect)(() => (z(), k.current.length > 0 && w(!0), () => {
            W(), L.current && L.current.remove(), _.current && _.current.remove(), _.current = null, O.current = null, L.current = null
        }), [z, W]), (0, s.useEffect)(() => {
            if (!(S <= 0) && !(C <= 0)) {
                if (!_.current) {
                    z(), k.current.length > 0 && w(!0);
                    return
                }
                _.current.resize(S, C), (0, f.applyChartOffset)(_.current)
            }
        }, [S, C, z]);
        let G = (0, s.useCallback)(e => {
                k.current.push(e), x.current = e.value, K(), W();
                let t = O.current;
                if (t) {
                    let r = t.data(),
                        a = r[r.length - 1];
                    a && e.time - a.time > f.GAP_FILL_THRESHOLD && (0, f.fillMissingSeconds)(e => t.update(e), a, e.time);
                    let i = a ? a.value : e.value;
                    X(Date.now(), f.ANIMATION_DURATION, i, e.value)
                }
            }, [K, W, X]),
            Q = (0, s.useMemo)(() => T ? {
                topic: T.topic,
                type: "update",
                filters: JSON.stringify({
                    symbol: T.filterSymbol
                })
            } : null, [T]),
            Y = M ? g.LIVE_DATA_WEBSOCKET_URL : null,
            {
                readyState: Z,
                sendMessage: ee
            } = (0, u.useWebSocket)({
                url: Y,
                shouldReconnect: () => !!Y,
                maxReconnectAttempts: 5,
                reconnectInterval: 1e4,
                onMessage: e => {
                    if (!e.data) return;
                    U.current ? .();
                    let t = JSON.parse(e.data);
                    if ("subscribe" === t.type && Array.isArray(t.payload ? .data)) {
                        let e = (0, f.dedupePoints)(t.payload.data.filter(e => Number.isFinite(e.timestamp) && Number.isFinite(e.value)).sort((e, t) => e.timestamp - t.timestamp).map(f.toLineDataPoint));
                        k.current = e;
                        let r = e[e.length - 1];
                        r && (x.current = r.value, K()), O.current && _.current && (O.current.setData((0, b.interpolateSeriesData)(e, d.MAX_UPDATES_PER_SECOND)), _.current.timeScale().fitContent(), (0, f.applyChartOffset)(_.current), w(!0))
                    }
                    "update" === t.type && t.payload ? .timestamp && t.payload ? .value && G((0, f.toLineDataPoint)(t.payload))
                }
            });
        (0, s.useEffect)(() => {
            Z === n.ReadyState.OPEN && Q && ee(JSON.stringify({
                action: "subscribe",
                subscriptions: [Q]
            }))
        }, [Z, Q, ee]);
        let et = t.default.env.NEXT_PUBLIC_CHAINLINK_STREAMS_WS || "",
            er = D ? `${D.toLowerCase()}-usd` : "",
            ea = (0, s.useMemo)(() => {
                if (!T ? .usesChainlink || !et || !er) return null;
                let e = `symbol=${encodeURIComponent(er)}`;
                return et.includes("?") ? `${et}&${e}` : `${et}?${e}`
            }, [T ? .usesChainlink, et, er]);
        return ((0, u.useWebSocket)({
            url: ea,
            shouldReconnect: () => !!ea,
            maxReconnectAttempts: 50,
            reconnectInterval: 2e3,
            onMessage: e => {
                if (!ea) return;
                U.current ? .();
                let t = "string" == typeof e.data ? JSON.parse(e.data) : e.data;
                if (!t) return;
                let r = t.price ? ? t.data ? .price ? ? ("update" === t.type ? t.value : null),
                    a = t.timestamp ? ? t.data ? .timestamp ? ? t.ts;
                if ("number" != typeof r || !a || !Number.isFinite(r)) return;
                let i = Math.floor(Number(a) / 1e3);
                Number.isFinite(i) && G({
                    time: i,
                    value: r
                })
            }
        }), (0, s.useEffect)(() => W, [W]), D) ? (0, r.jsx)("div", {
            style: {
                width: S,
                height: C,
                position: "relative"
            },
            className: `transition-opacity duration-300 ${V?"opacity-100":"opacity-0"}`,
            children: (0, r.jsx)("div", {
                ref: N,
                className: "absolute inset-0"
            })
        }) : null
    }])
}, 584710, e => {
    e.n(e.i(644245))
}]);

//# debugId=87ef89dd-f606-76a6-7a6f-74c5238b4d2a