"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useRichTextItemValues = void 0;
const useKeyframeValue_1 = require("../../common/useKeyframeValue");
const sdk_1 = require("@cntrl-site/sdk");
const useLayoutContext_1 = require("../useLayoutContext");
const DEFAULT_COLOR = 'rgba(0, 0, 0, 1)';
const useRichTextItemValues = (item, sectionId) => {
    const layoutId = (0, useLayoutContext_1.useLayoutContext)();
    const blur = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.Blur, (item, layoutId) => {
        if (!layoutId)
            return;
        const layoutParams = item.layoutParams[layoutId];
        return 'blur' in layoutParams ? layoutParams.blur : 0;
    }, (animator, scroll, value) => value !== undefined ? animator.getBlur({ blur: value }, scroll).blur : undefined, sectionId, [layoutId]);
    const letterSpacing = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.LetterSpacing, (item, layoutId) => {
        if (!layoutId)
            return;
        const layoutParams = item.layoutParams[layoutId];
        return 'letterSpacing' in layoutParams ? layoutParams.letterSpacing : 0;
    }, (animator, scroll, value) => value !== undefined ? animator.getLetterSpacing({ letterSpacing: value }, scroll).letterSpacing : undefined, sectionId, [layoutId]);
    const wordSpacing = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.WordSpacing, (item, layoutId) => {
        if (!layoutId)
            return;
        const layoutParams = item.layoutParams[layoutId];
        return 'wordSpacing' in layoutParams ? layoutParams.wordSpacing : 0;
    }, (animator, scroll, value) => value !== undefined ? animator.getWordSpacing({ wordSpacing: value }, scroll).wordSpacing : undefined, sectionId, [layoutId]);
    const color = (0, useKeyframeValue_1.useKeyframeValue)(item, sdk_1.KeyframeType.TextColor, (item, layoutId) => {
        if (!layoutId)
            return;
        const layoutParams = item.layoutParams[layoutId];
        return 'color' in layoutParams ? layoutParams.color : DEFAULT_COLOR;
    }, (animator, scroll, value) => value ? animator.getTextColor({ color: value }, scroll).color : undefined, sectionId, [layoutId]);
    const fontSize = layoutId ? item.layoutParams[layoutId].fontSize : undefined;
    const lineHeight = layoutId ? item.layoutParams[layoutId].lineHeight : undefined;
    return { blur, letterSpacing, wordSpacing, color, fontSize, lineHeight };
};
exports.useRichTextItemValues = useRichTextItemValues;
