import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { AnchorContext } from './anchor-context';
var AnchorLink = React.forwardRef(function (props, ref) {
    var _a;
    var href = props.href, title = props.title, children = props.children, prefixCls = props.prefixCls, otherProps = __rest(props, ["href", "title", "children", "prefixCls"]);
    var anchorContext = useContext(AnchorContext);
    var cls = classNames(prefixCls + "__link", (_a = {},
        _a[prefixCls + "__link_active"] = "#" + anchorContext.activeId === href,
        _a));
    var onLinkClick = function (e) {
        e.preventDefault();
        var onClick = anchorContext.onClick;
        onClick && onClick(e, href.replace('#', ''));
    };
    return (React.createElement("li", { title: title, className: cls },
        React.createElement("a", __assign({}, otherProps, { className: prefixCls + "__link-title", ref: ref, href: href, onClick: onLinkClick, target: 'target' in props ? props.target : undefined }), title),
        children && (React.createElement("ul", { className: prefixCls }, React.Children.map(children, function (child) { return (React.createElement(AnchorLink, __assign({}, child.props, { prefixCls: prefixCls }))); })))));
});
AnchorLink.displayName = 'AnchorLink';
export default AnchorLink;
//# sourceMappingURL=anchor-link.js.map