import { cn } from "../../utils/cn.mjs";
import { ExternalLink } from "lucide-react";
import { cva } from "class-variance-authority";
import { jsx, jsxs } from "react/jsx-runtime";
import { getLocalizedUrl } from "@intlayer/core";

//#region src/components/Link/Link.tsx
/**
* Visual style variants for Link component
*
* @enum {string}
*/
let LinkVariant = /* @__PURE__ */ function(LinkVariant$1) {
	/** Default underlined link with hover effects */
	LinkVariant$1["DEFAULT"] = "default";
	/** Link without visible underline or hover effects */
	LinkVariant$1["INVISIBLE_LINK"] = "invisible-link";
	/** Button-styled link with solid background */
	LinkVariant$1["BUTTON"] = "button";
	/** Button-styled link with outlined border */
	LinkVariant$1["BUTTON_OUTLINED"] = "button-outlined";
	/** Link with subtle hover background effect */
	LinkVariant$1["HOVERABLE"] = "hoverable";
	return LinkVariant$1;
}({});
/**
* Color theme variants for Link component
*
* @enum {string}
*/
let LinkColor = /* @__PURE__ */ function(LinkColor$1) {
	/** Primary brand color */
	LinkColor$1["PRIMARY"] = "primary";
	/** Secondary brand color */
	LinkColor$1["SECONDARY"] = "secondary";
	/** Destructive/danger color for critical actions */
	LinkColor$1["DESTRUCTIVE"] = "destructive";
	/** Neutral/muted color for less prominent links */
	LinkColor$1["NEUTRAL"] = "neutral";
	/** Light color for dark backgrounds */
	LinkColor$1["LIGHT"] = "light";
	/** Dark color for light backgrounds */
	LinkColor$1["DARK"] = "dark";
	/** Default text color */
	LinkColor$1["TEXT"] = "text";
	/** Inverse text color for opposite backgrounds */
	LinkColor$1["TEXT_INVERSE"] = "text-inverse";
	/** Error/red color for error states */
	LinkColor$1["ERROR"] = "error";
	/** Success/green color for positive actions */
	LinkColor$1["SUCCESS"] = "success";
	/** Custom color - no default styling applied */
	LinkColor$1["CUSTOM"] = "custom";
	return LinkColor$1;
}({});
/**
* Underline style options for Link component
*
* @enum {string}
*/
let LinkUnderlined = /* @__PURE__ */ function(LinkUnderlined$1) {
	/** Default underline behavior based on variant */
	LinkUnderlined$1["DEFAULT"] = "default";
	/** Always show underline */
	LinkUnderlined$1["TRUE"] = "true";
	/** Never show underline */
	LinkUnderlined$1["FALSE"] = "false";
	return LinkUnderlined$1;
}({});
/**
* Class variance authority configuration for Link component styling
* Defines the visual appearance based on variant, color, and underline options
*/
const linkVariants = cva("gap-3 transition focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50", {
	variants: {
		variant: {
			[`${LinkVariant.DEFAULT}`]: "h-auto justify-start border-inherit bg-current/0 px-1 underline-offset-4 hover:bg-current/0 hover:underline",
			[`${LinkVariant.INVISIBLE_LINK}`]: "h-auto justify-start border-inherit bg-current/0 px-1 underline-offset-4 hover:bg-current/0",
			[`${LinkVariant.BUTTON}`]: "flex min-h-8 items-center justify-center gap-2 whitespace-nowrap rounded-lg bg-current px-6 font-medium text-sm transition *:text-text-opposite focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50 max-md:py-2",
			[`${LinkVariant.BUTTON_OUTLINED}`]: "flex min-h-8 items-center justify-center gap-2 whitespace-nowrap rounded-lg border-[1.5px] px-6 font-medium text-sm transition hover:bg-current/30 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50 max-md:py-2",
			[`${LinkVariant.HOVERABLE}`]: "block rounded-lg border-none bg-current/0 transition hover:bg-current/20 aria-[current]:bg-current/5"
		},
		color: {
			[`${LinkColor.PRIMARY}`]: "text-primary",
			[`${LinkColor.SECONDARY}`]: "text-secondary",
			[`${LinkColor.DESTRUCTIVE}`]: "text-destructive",
			[`${LinkColor.NEUTRAL}`]: "text-neutral",
			[`${LinkColor.LIGHT}`]: "text-white",
			[`${LinkColor.DARK}`]: "text-neutral-800",
			[`${LinkColor.TEXT}`]: "text-text",
			[`${LinkColor.TEXT_INVERSE}`]: "text-text-opposite",
			[`${LinkColor.ERROR}`]: "text-error",
			[`${LinkColor.SUCCESS}`]: "text-success",
			[`${LinkColor.CUSTOM}`]: ""
		},
		underlined: {
			[LinkUnderlined.DEFAULT]: "",
			[LinkUnderlined.TRUE]: "underline",
			[LinkUnderlined.FALSE]: "no-underline"
		}
	},
	defaultVariants: {
		variant: LinkVariant.DEFAULT,
		color: LinkColor.PRIMARY,
		underlined: LinkUnderlined.DEFAULT
	}
});
/**
* Utility function to determine if a link should be treated as external
*
* @param props - Link component props containing href and isExternalLink
* @returns {boolean} True if the link should open externally
*
* @example
* ```tsx
* checkIsExternalLink({ href: 'https://example.com' }) // true
* checkIsExternalLink({ href: '/internal-page' }) // false
* checkIsExternalLink({ href: '/page', isExternalLink: true }) // true
* ```
*/
const checkIsExternalLink = ({ href, isExternalLink: isExternalLinkProp }) => {
	const isValidHref = typeof href === "string" && href.trim() !== "";
	return isExternalLinkProp === true || typeof isExternalLinkProp === "undefined" && isValidHref && /^https?:\/\//.test(href);
};
/**
* Link Component
*
* A versatile link component that handles both internal and external navigation
* with comprehensive internationalization support and multiple visual variants.
*
* ## Key Features
* - **Multiple Variants**: Default, invisible, button, outlined button, and hoverable styles
* - **Color Themes**: Comprehensive color palette for different contexts and meanings
* - **External Link Detection**: Automatic detection and handling of external URLs
* - **Internationalization**: Built-in support for localized URLs via Intlayer
* - **Security**: Automatic security attributes for external links (noopener, noreferrer)
* - **Accessibility**: Full ARIA support with proper labels and current page indication
* - **Visual Feedback**: Hover effects, underline options, and active states
*
* ## Use Cases
* - Navigation within applications (internal links)
* - External links to other websites with security measures
* - Button-styled links for call-to-action scenarios
* - Subtle hoverable links for navigation menus
* - Multi-language website navigation with automatic URL localization
*
* ## Security Features
* External links automatically receive security attributes:
* - `rel="noopener noreferrer nofollow"` - Prevents security vulnerabilities
* - `target="_blank"` - Opens in new tab/window
* - External link icon indication for user clarity
*
* ## Internationalization
* When used with Intlayer, the component automatically:
* - Localizes internal URLs based on the current or specified locale
* - Sets appropriate `hrefLang` attributes for SEO
* - Maintains proper URL structure for multi-language sites
*
* @component
* @example
* ```tsx
* // Basic internal link
* <Link href="/about" label="Go to about page">
*   About Us
* </Link>
*
* // External link with auto-detection
* <Link href="https://example.com" label="Visit external site">
*   External Site
* </Link>
*
* // Button-styled link
* <Link
*   href="/signup"
*   variant={LinkVariant.BUTTON}
*   color={LinkColor.PRIMARY}
*   label="Sign up for account"
* >
*   Get Started
* </Link>
*
* // Localized link
* <Link
*   href="/products"
*   locale="fr"
*   label="Voir les produits"
* >
*   Produits
* </Link>
*
* // Active navigation link
* <Link
*   href="/dashboard"
*   isActive={true}
*   variant={LinkVariant.HOVERABLE}
*   label="Current page: Dashboard"
* >
*   Dashboard
* </Link>
* ```
*
* @param props - Link component props
* @param props.children - Content to display inside the link
* @param props.href - URL or path to navigate to
* @param props.label - Accessible label describing the link's purpose
* @param props.variant - Visual style variant
* @param props.color - Color theme for the link
* @param props.underlined - Underline visibility option
* @param props.isExternalLink - Override external link detection
* @param props.isActive - Whether this link represents the current page
* @param props.locale - Locale for URL internationalization
* @param props.className - Additional CSS classes
* @returns Accessible and internationalized link component
*/
const Link = (props) => {
	const { variant = LinkVariant.DEFAULT, color = LinkColor.PRIMARY, children, label, className, isActive, underlined, locale, isExternalLink: isExternalLinkProp, href: hrefProp,...otherProps } = props;
	const isExternalLink = checkIsExternalLink(props);
	const isChildrenString = typeof children === "string";
	const rel = isExternalLink ? "noopener noreferrer nofollow" : void 0;
	const target = isExternalLink ? "_blank" : "_self";
	return /* @__PURE__ */ jsxs("a", {
		href: locale && hrefProp && !isExternalLink ? getLocalizedUrl(hrefProp, locale) : hrefProp,
		"aria-label": label,
		rel,
		target,
		"aria-current": isActive ? "page" : void 0,
		className: cn(linkVariants({
			variant,
			color,
			underlined,
			className
		})),
		...otherProps,
		children: [variant === "button" ? /* @__PURE__ */ jsx("span", { children }) : children, isExternalLink && isChildrenString && /* @__PURE__ */ jsx(ExternalLink, { className: "ml-2 inline-block size-4" })]
	});
};

//#endregion
export { Link, LinkColor, LinkUnderlined, LinkVariant, checkIsExternalLink, linkVariants };
//# sourceMappingURL=Link.mjs.map