"use client";
import { linkVariants } from '@heroui/styles';
import React__default, { createContext, useContext } from 'react';
import { Link } from 'react-aria-components';
import { dataAttr } from '../../utils/assertion.js';
import { composeTwRenderProps, composeSlotClassName } from '../../utils/compose.js';
import { ExternalLinkIcon } from '../icons.js';
import { jsx, Fragment } from 'react/jsx-runtime';

const LinkContext = /*#__PURE__*/createContext({});

/* ------------------------------------------------------------------------------------------------
 * Link Root
 * --------------------------------------------------------------------------------------------- */

const LinkRoot = ({
  children,
  className,
  ...props
}) => {
  const slots = React__default.useMemo(() => linkVariants(), []);
  return /*#__PURE__*/jsx(LinkContext, {
    value: {
      slots
    },
    children: /*#__PURE__*/jsx(Link, {
      ...props,
      className: composeTwRenderProps(className, slots?.base()),
      children: values => /*#__PURE__*/jsx(Fragment, {
        children: typeof children === "function" ? children(values) : children
      })
    })
  });
};

/* ------------------------------------------------------------------------------------------------
 * Link Icon
 * --------------------------------------------------------------------------------------------- */

const LinkIcon = ({
  children,
  className,
  ...rest
}) => {
  const {
    slots
  } = useContext(LinkContext);
  return /*#__PURE__*/jsx("span", {
    className: composeSlotClassName(slots?.icon, className),
    "data-default-icon": dataAttr(!children),
    "data-slot": "link-icon",
    ...rest,
    children: children ?? /*#__PURE__*/jsx(ExternalLinkIcon, {
      "data-slot": "link-default-icon"
    })
  });
};

export { LinkIcon, LinkRoot };
