"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useHighlight = void 0;
var react_1 = require("react");
var gsap_1 = __importDefault(require("gsap"));
var ScrollTrigger_1 = __importDefault(require("gsap/ScrollTrigger"));
gsap_1.default.registerPlugin(ScrollTrigger_1.default);
// Cambia la firma a:
var useHighlight = function (highlightOptions) {
    if (highlightOptions === void 0) { highlightOptions = {}; }
    var elementRef = (0, react_1.useRef)(null);
    var textColor = highlightOptions.textColor, highlightColor = highlightOptions.highlightColor, start = highlightOptions.start, end = highlightOptions.end;
    (0, react_1.useEffect)(function () {
        var element = elementRef.current;
        if (!element)
            return;
        var defaultTextColor = "#FFFFFF";
        var defaultHighlightColor = "#6D00C7";
        var defaultStart = "bottom 98%";
        var defaultEnd = "bottom 65%";
        var finalTextColor = textColor || defaultTextColor;
        var finalHighlightColor = highlightColor || defaultHighlightColor;
        var finalStart = start || defaultStart;
        var finalEnd = end || defaultEnd;
        if (!element.classList.contains("react-scroll-text-highlight")) {
            element.classList.add("react-scroll-text-highlight");
        }
        var text = element.textContent || "";
        element.setAttribute("highlight-text", text);
        element.style.setProperty("--text-color", finalTextColor);
        element.style.setProperty("--highlight-color", finalHighlightColor);
        gsap_1.default.to(element, {
            keyframes: [
                {
                    "--animate-padding-X": "0.3em",
                    "padding-left": "0.3em",
                    "padding-right": "0.3em",
                    "--animate-width": "20%",
                    duration: 0.3,
                },
                {
                    "--animate-width": "100%",
                    duration: 0.7,
                },
            ],
            scrollTrigger: {
                trigger: element,
                start: finalStart,
                end: finalEnd,
                scrub: true,
            },
        });
        return function () {
            var _a;
            (_a = ScrollTrigger_1.default.getById(element.id)) === null || _a === void 0 ? void 0 : _a.kill();
            gsap_1.default.killTweensOf(element);
            element.classList.remove("custom-highlight");
            element.removeAttribute("highlight-text");
            element.style.removeProperty("--text-color");
            element.style.removeProperty("--highlight-color");
        };
    }, [textColor, highlightColor]);
    return elementRef;
};
exports.useHighlight = useHighlight;
