"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Link = exports.LinkBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const t_1 = __importDefault(require("../t"));
const utils_1 = require("../utils");
const context_1 = require("./context");
const linkIcon_1 = __importDefault(require("./linkIcon"));
const linkText_1 = __importDefault(require("./linkText"));
const linkSwipeAnimation = `
  @keyframes linkSwipe {
    from {
      background-size: 0 1px;
    }
    to {
      background-size: 100% 1px;
    }
  }
`;
exports.LinkBase = core_1.styled.aBox.attrs((props) => ({
    isUnderlined: props.isUnderlined || false,
})) `
  ${linkSwipeAnimation}
  display: inline;
  cursor: pointer;
  position: relative;
  line-height: 1.5;
  outline: none;
  width: fit-content;
  text-decoration: none;

  &:not(.vui-linkNoUnderline) span {
    position: relative;
    background: linear-gradient(to right, currentcolor, currentcolor);
    background-size: ${({ isUnderlined }) => (isUnderlined ? '100% 1px' : '0 1px')};
    background-position: 0 100%;
    background-repeat: no-repeat;
    text-decoration: none;
    padding-bottom: 2px;
    line-height: 1;
  }

  &:hover span {
    animation: linkSwipe 0.3s ease forwards;
    background-size: 100% 1px;
  }
`;
exports.Link = (0, core_1.vui)((props, ref) => {
    const { children, className, fontWeight, iconLeft, iconRight, isExternal, isUnderlined, size, text, variant, weight } = props, rest = __rest(props, ["children", "className", "fontWeight", "iconLeft", "iconRight", "isExternal", "isUnderlined", "size", "text", "variant", "weight"]);
    const styles = (0, core_1.useStyleConfig)('Link', props);
    const context = (0, react_1.useMemo)(() => (0, utils_1.filterUndefined)({ size, variant }), [size, variant]);
    const aliasedProps = (0, utils_1.filterUndefined)({
        fontWeight: weight || fontWeight,
        rel: isExternal ? 'noopener' : undefined,
        target: isExternal ? '_blank' : undefined,
    });
    return ((0, jsx_runtime_1.jsx)(context_1.LinkProvider, { value: context, children: (0, jsx_runtime_1.jsxs)(exports.LinkBase, Object.assign({ alignItems: iconLeft || iconRight ? 'center' : undefined, className: (0, utils_1.cs)('vui-link', className), display: iconLeft || iconRight ? 'inline-flex' : 'inline', focusRing: 2, isUnderlined: isUnderlined, ref: ref }, styles.container, aliasedProps, rest, { children: [(0, utils_1.isString)(iconLeft) ? (0, jsx_runtime_1.jsx)(linkIcon_1.default, { mr: 1, name: iconLeft }) : iconLeft, (0, jsx_runtime_1.jsx)(t_1.default, { children: children !== null && children !== void 0 ? children : ((0, utils_1.isReactText)(text) ? (0, jsx_runtime_1.jsx)(linkText_1.default, { text: text }) : text) }), (0, utils_1.isString)(iconRight) ? (0, jsx_runtime_1.jsx)(linkIcon_1.default, { ml: 1, name: iconRight }) : iconRight] })) }));
});
exports.Link.Icon = linkIcon_1.default;
exports.Link.Text = linkText_1.default;
exports.Link.displayName = 'Link';
exports.default = exports.Link;
//# sourceMappingURL=link.js.map