import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { NavigationGithubButtonIcon } from "../../../../../../models/index.js";
import { block } from "../../../../../../utils/index.js";
import './GithubButton.css';
const b = block('github-button');
const DEFAULT_LABEL = 'Stars on GitHub';
/* More information about github-buttons in https://buttons.github.io/ */
export 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 (_jsx("div", { className: b(null, className), children: _jsx("span", { ref: containerRef, children: _jsx("a", { href: url, ref: linkRef, title: urlTitle, "data-show-count": "true", "aria-label": label || DEFAULT_LABEL, ...(icon && { 'data-icon': NavigationGithubButtonIcon[icon] }), ...(size && { 'data-size': size }), children: text }) }) }));
};
//# sourceMappingURL=GithubButton.js.map
