"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const acui_1 = require("@Acme Corporation/acui");
const Link = (0, react_1.forwardRef)(({ href, to, size = 'md', weight = 'normal', color = 'primary', decoration = 'underline', variant = 'text', isExternal = false, isDisabled = false, isActive = false, isFocusable = true, isTruncated = false, noOfLines, target: propTarget, rel: propRel, onClick, onFocus, onBlur, onKeyDown, onKeyUp, onMouseEnter, onMouseLeave, className = '', wrapperClassName = '', iconClassName = '', leftIcon, rightIcon, children, ...props }, ref) => {
    const theme = (0, acui_1.useTheme)();
    const target = propTarget || (isExternal ? '_blank' : undefined);
    const rel = propRel || (isExternal ? 'noopener noreferrer' : undefined);
    const handleClick = (0, react_1.useCallback)((event) => {
        if (isDisabled) {
            event.preventDefault();
            return;
        }
        onClick?.(event);
    }, [isDisabled, onClick]);
    const handleKeyDown = (0, react_1.useCallback)((event) => {
        if (isDisabled) {
            event.preventDefault();
            return;
        }
        onKeyDown?.(event);
    }, [isDisabled, onKeyDown]);
    const handleKeyUp = (0, react_1.useCallback)((event) => {
        if (isDisabled) {
            event.preventDefault();
            return;
        }
        onKeyUp?.(event);
    }, [isDisabled, onKeyUp]);
    const style = {
        ...(noOfLines && {
            display: '-webkit-box',
            WebkitLineClamp: noOfLines,
            WebkitBoxOrient: 'vertical',
            overflow: 'hidden',
            textOverflow: 'ellipsis'
        }),
        ...(isTruncated && {
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            whiteSpace: 'nowrap'
        })
    };
    const ariaProps = {
        'aria-disabled': isDisabled ? true : undefined,
        'aria-current': isActive ? 'page' : undefined,
        'aria-label': typeof children === 'string' ? children : undefined,
        'aria-hidden': isDisabled ? true : undefined
    };
    const renderContent = () => {
        if (variant === 'icon') {
            return ((0, jsx_runtime_1.jsx)("span", { className: `bf-link-icon ${iconClassName}`, "aria-hidden": "true", children: children }));
        }
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [leftIcon && ((0, jsx_runtime_1.jsx)("span", { className: `bf-link-icon bf-link-icon-left ${iconClassName}`, "aria-hidden": "true", children: leftIcon })), children, rightIcon && ((0, jsx_runtime_1.jsx)("span", { className: `bf-link-icon bf-link-icon-right ${iconClassName}`, "aria-hidden": "true", children: rightIcon }))] }));
    };
    return ((0, jsx_runtime_1.jsx)("div", { className: `bf-link-wrapper ${wrapperClassName}`, "data-size": size, "data-weight": weight, "data-color": color, "data-decoration": decoration, "data-variant": variant, "data-external": isExternal, "data-disabled": isDisabled, "data-active": isActive, "data-truncate": isTruncated, "data-lines": noOfLines, children: (0, jsx_runtime_1.jsx)("a", { ref: ref, href: isDisabled ? undefined : (href || to), target: target, rel: rel, onClick: handleClick, onFocus: onFocus, onBlur: onBlur, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, tabIndex: isFocusable ? 0 : -1, ...ariaProps, className: `bf-link ${className}`, style: style, ...props, children: renderContent() }) }));
});
Link.displayName = 'Link';
exports.default = (0, react_1.memo)(Link);
//# sourceMappingURL=Link.js.map