import { isReactText, isString } from "../utils/assertion.js";
import { filterUndefined } from "../utils/object.js";
import { cs } from "../utils/styles.js";
import "../utils/index.js";
import { useStyleConfig } from "../core/theme.js";
import { styled } from "../core/styled.js";
import { vui } from "../core/vui.js";
import t_default from "../t/t.js";
import "../t/index.js";
import "../core/index.js";
import { LinkProvider } from "./context.js";
import linkIcon_default from "./linkIcon.js";
import linkText_default from "./linkText.js";
import { useMemo } from "react";
import { jsx, jsxs } from "react/jsx-runtime";

//#region src/link/link.tsx
const linkSwipeAnimation = `
  @keyframes linkSwipe {
    from {
      background-size: 0 1px;
    }
    to {
      background-size: 100% 1px;
    }
  }
`;
const LinkBase = 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) > .vui-t {
    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.2;
  }

  &:not(.vui-linkNoUnderline) .vui-linkIcon {
    margin-bottom: 2px;
  }

  &:hover > .vui-t {
    animation: ${({ isUnderlined }) => isUnderlined ? "none" : "linkSwipe 0.3s ease forwards"};
    background-size: ${({ isUnderlined }) => isUnderlined ? "100% 2px" : "100% 1px"};
  }
`;
const Link = vui((props, ref) => {
	const { children, className, fontWeight, iconLeft, iconRight, isExternal, isUnderlined, size, text, variant, weight, ...rest } = props;
	const styles = useStyleConfig("Link", props);
	const context = useMemo(() => filterUndefined({
		size,
		variant
	}), [size, variant]);
	const aliasedProps = filterUndefined({
		fontWeight: weight || fontWeight,
		rel: isExternal ? "noopener" : void 0,
		target: isExternal ? "_blank" : void 0
	});
	return /* @__PURE__ */ jsx(LinkProvider, {
		value: context,
		children: /* @__PURE__ */ jsxs(LinkBase, {
			alignItems: iconLeft || iconRight ? "center" : void 0,
			className: cs("vui-link", className),
			display: iconLeft || iconRight ? "inline-flex" : "inline",
			focusRing: 2,
			isUnderlined,
			ref,
			...styles.container,
			...aliasedProps,
			...rest,
			children: [
				isString(iconLeft) ? /* @__PURE__ */ jsx(linkIcon_default, {
					mr: 1,
					name: iconLeft
				}) : iconLeft,
				children ? /* @__PURE__ */ jsx(t_default, {
					fontSize: "inherit",
					children
				}) : isReactText(text) && /* @__PURE__ */ jsx(linkText_default, { text }),
				isString(iconRight) ? /* @__PURE__ */ jsx(linkIcon_default, {
					ml: 1,
					name: iconRight
				}) : iconRight
			]
		})
	});
});
Link.Icon = linkIcon_default;
Link.Text = linkText_default;
Link.displayName = "Link";
var link_default = Link;

//#endregion
export { Link, LinkBase, link_default as default };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=link.js.map