"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GithubButton = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const models_1 = require("../../../../../../models/index.js");
const utils_1 = require("../../../../../../utils/index.js");
const b = (0, utils_1.block)('github-button');
const DEFAULT_LABEL = 'Stars on GitHub';
/* More information about github-buttons in https://buttons.github.io/ */
const GithubButton = ({ text, url, className, label, size, icon, urlTitle, }) => {
    const containerRef = React.useRef(null);
    const linkRef = React.useRef(null);
    React.useEffect(() => {
        const paint = () => {
            if (containerRef.current) {
                const githubButton = containerRef.current.appendChild(document.createElement('span'));
                import(/* webpackMode: "eager" */ 'github-buttons').then(({ render }) => {
                    if (linkRef.current !== null) {
                        render(githubButton.appendChild(linkRef.current), (el) => {
                            try {
                                if (githubButton.parentNode) {
                                    githubButton.parentNode.replaceChild(el, githubButton);
                                }
                            }
                            catch { }
                        });
                    }
                });
            }
        };
        const reset = () => {
            if (containerRef?.current?.lastChild && linkRef.current) {
                containerRef.current.replaceChild(linkRef.current, containerRef.current.lastChild);
            }
        };
        paint();
        return () => {
            reset();
        };
    }, []);
    return ((0, jsx_runtime_1.jsx)("div", { className: b(null, className), children: (0, jsx_runtime_1.jsx)("span", { ref: containerRef, children: (0, jsx_runtime_1.jsx)("a", { href: url, ref: linkRef, title: urlTitle, "data-show-count": "true", "aria-label": label || DEFAULT_LABEL, ...(icon && { 'data-icon': models_1.NavigationGithubButtonIcon[icon] }), ...(size && { 'data-size': size }), children: text }) }) }));
};
exports.GithubButton = GithubButton;
//# sourceMappingURL=GithubButton.js.map
