"use client";
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_index = require('../../css-tokens/dist/index.cjs');
const require_styles_styler = require('../../styles/styler.cjs');
const require_utils_createSlot = require('../../utils/createSlot.cjs');
const require_components_Icon = require('../Icon.cjs');
const require_components_IconSlot = require('../IconSlot.cjs');
const require_generateDefaultClassName = require('../../automated-config/dist/utils/generateDefaultClassName.cjs');
const require_components_client_buttonConstants = require('./buttonConstants.cjs');
const require_components_client_SpringMotionConfig = require('./SpringMotionConfig.cjs');
let react = require("react");
react = require_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
let _yahoo_uds_icons = require("@yahoo/uds-icons");
let motion_react = require("motion/react");

//#region src/components/client/Button.tsx
const iconContainerMotionVariants = {
	hide: {
		display: "none",
		width: "0px",
		opacity: 0
	},
	loading: {
		display: "flex",
		width: "auto",
		opacity: 1
	},
	icon: {
		display: "flex",
		width: "auto",
		opacity: 1
	}
};
const SCALE_DOWN = .7;
const hiddenState = {
	scale: SCALE_DOWN,
	opacity: 0
};
const visibleState = {
	scale: [
		SCALE_DOWN,
		SCALE_DOWN,
		1
	],
	opacity: [
		0,
		0,
		1
	],
	transition: { times: [
		0,
		.5,
		1
	] }
};
const iconMotionVariants = {
	hide: hiddenState,
	icon: visibleState,
	loading: hiddenState
};
const loadingMotionVariants = {
	hide: hiddenState,
	icon: hiddenState,
	loading: visibleState
};
function getGapVariant({ startIcon, endIcon, loading }) {
	if (loading || startIcon || endIcon) return "withIcon";
	return "withoutIcon";
}
function getStartVariant({ loading, startIcon }) {
	if (loading) return "loading";
	if (startIcon) return "icon";
	return "hide";
}
const defaultVariantRootClass = require_generateDefaultClassName.generateDefaultClassName("button", "variant", "root");
const defaultVariantIconClass = require_generateDefaultClassName.generateDefaultClassName("button", "variant", "icon");
const defaultSizeRootClass = require_generateDefaultClassName.generateDefaultClassName("button", "size", "root");
const defaultSizeIconClass = require_generateDefaultClassName.generateDefaultClassName("button", "size", "icon");
/**
* **🖲️ A button element that can be used to trigger an action**
*
* @componentType Client component
*
* @description A button is a fundamental component used to trigger an action or event. Buttons are interactive elements that users can click, tap, or otherwise engage with to submit forms, open dialogues, or perform any other interaction within an application or website. Consider an IconButton for buttons that only contain an icon.
*
* @see The {@link https://uds.build/docs/components/button Button Docs} for more info
*
* @example
* ```tsx
* 'use client';
* import { Button, HStack } from "@yahoo/uds";
*
* export function Demo() {
*   return (
*     <HStack gap="2">
*       <Button onClick={console.log}>Save</Button>
*       <Button variant="secondary" onClick={console.log}>Cancel</Button>
*     </HStack>
*   )
* }
* ```
*
*
* @usage
* Buttons should be used to clearly indicate and initiate actions that users can take.
*
* @related [Icon](https://uds.build/docs/components/icon), [IconButton](https://uds.build/docs/components/icon-button), [Pressable](https://uds.build/docs/components/pressable)
**/
const Button = (0, react.forwardRef)(function Button({ size, variant, startIcon, endIcon, iconVariant, loading, disableEffects, children, asChild = false, type = "button", className, width, ...rest }, forwardedRef) {
	const ref = (0, react.useRef)(null);
	(0, react.useImperativeHandle)(forwardedRef, () => ref.current);
	const prefersReducedMotion = (0, motion_react.useReducedMotion)();
	const disableMotion = !!disableEffects || !!rest?.disabled;
	const layoutVariant = prefersReducedMotion ? "smooth" : "subtle";
	const endVariant = endIcon ? "icon" : "hide";
	const gapVariant = getGapVariant({
		startIcon,
		endIcon,
		loading
	});
	const startVariant = getStartVariant({
		loading,
		startIcon
	});
	const Slot = (0, react.useMemo)(() => require_utils_createSlot.createSlot(), []);
	const MotionSlot = (0, react.useMemo)(() => motion_react.m.create(Slot), [Slot]);
	const buttonVariants = (0, react.useMemo)(() => ({
		rest: { scale: disableMotion ? 1 : `var(${require_index.BUTTON_SCALE_EFFECT_REST})` },
		hover: { scale: disableMotion ? 1 : `var(${require_index.BUTTON_SCALE_EFFECT_HOVER})` },
		pressed: { scale: disableMotion ? 1 : `var(${require_index.BUTTON_SCALE_EFFECT_PRESSED})` },
		withIcon: { columnGap: `var(${require_index.BUTTON_GAP_VAR})` },
		withoutIcon: { columnGap: "0px" }
	}), [disableMotion]);
	const rootSizeClass = (0, react.useMemo)(() => size ? require_styles_styler.getStyles({ buttonSizeRoot: size }) : defaultSizeRootClass, [size]);
	const rootVariantClass = (0, react.useMemo)(() => variant ? require_styles_styler.getStyles({ buttonVariantRoot: variant }) : defaultVariantRootClass, [variant]);
	const iconSizeClass = (0, react.useMemo)(() => size ? require_styles_styler.getStyles({ buttonSizeIcon: size }) : defaultSizeIconClass, [size]);
	const iconVariantClass = (0, react.useMemo)(() => variant ? require_styles_styler.getStyles({ buttonVariantIcon: variant }) : defaultVariantIconClass, [variant]);
	const styles = (0, react.useMemo)(() => ({
		root: require_styles_styler.getStyles({
			width,
			className: require_styles_styler.cx([
				"uds-ring",
				"uds-hit-target",
				"inline-flex overflow-hidden justify-center items-center whitespace-nowrap select-none",
				"[transform-origin:center]",
				"[backface-visibility:hidden]",
				"[transition-property:color,background-color,border-color,box-shadow,text-decoration-color,fill,stroke]",
				"[transition-timing-function:cubic-bezier(0,0,0.2,1)]",
				"[transition-duration:220ms]",
				rootSizeClass,
				rootVariantClass,
				rest?.disabled && "cursor-not-allowed",
				loading && "uds-button-loading",
				disableEffects && "uds-button-without-effects",
				gapVariant === "withIcon" && "uds-button-with-gap",
				className
			])
		}),
		iconContainer: "flex overflow-clip uds-button-icon-container",
		icon: require_styles_styler.getStyles({ className: require_styles_styler.cx([iconSizeClass, iconVariantClass]) }),
		loadingIcon: require_styles_styler.getStyles({ className: require_styles_styler.cx([
			"animate-spin",
			iconSizeClass,
			iconVariantClass
		]) }),
		content: require_styles_styler.cx(["truncate"])
	}), [
		className,
		disableEffects,
		gapVariant,
		iconSizeClass,
		iconVariantClass,
		loading,
		rest?.disabled,
		rootSizeClass,
		rootVariantClass,
		width
	]);
	const startContent = (0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.m.span, {
		className: styles.iconContainer,
		initial: false,
		variants: iconContainerMotionVariants,
		animate: startVariant,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(motion_react.AnimatePresence, {
			initial: false,
			mode: "popLayout",
			children: [loading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.m.span, {
				variants: loadingMotionVariants,
				initial: "hide",
				animate: "loading",
				exit: "hide",
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_Icon.Icon, {
					className: styles.loadingIcon,
					size: require_components_client_buttonConstants.buttonIconSvgSize,
					name: _yahoo_uds_icons.Progress,
					variant: iconVariant,
					color: "current"
				})
			}, "loading"), startIcon && !loading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.m.span, {
				variants: iconMotionVariants,
				initial: "hide",
				animate: "icon",
				exit: "hide",
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
					className: styles.icon,
					icon: startIcon,
					iconProps: {
						size: require_components_client_buttonConstants.buttonIconSvgSize,
						variant: iconVariant,
						color: "current"
					}
				})
			})]
		})
	}), [
		styles,
		iconVariant,
		loading,
		startIcon,
		startVariant
	]);
	const endContent = (0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.m.span, {
		className: styles.iconContainer,
		initial: false,
		variants: iconContainerMotionVariants,
		animate: endVariant,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.AnimatePresence, {
			initial: false,
			mode: "popLayout",
			children: endIcon && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.m.span, {
				variants: iconMotionVariants,
				initial: "hide",
				animate: "icon",
				exit: "hide",
				children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_IconSlot.IconSlot, {
					className: styles.icon,
					icon: endIcon,
					iconProps: {
						size: require_components_client_buttonConstants.buttonIconSvgSize,
						variant: iconVariant,
						color: "current"
					}
				})
			})
		})
	}), [
		endIcon,
		styles,
		iconVariant,
		endVariant
	]);
	if (asChild && (0, react.isValidElement)(children)) {
		const childProps = children.props;
		return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
			layoutSpeed: "3",
			layoutVariant,
			children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MotionSlot, {
				type,
				className: styles.root,
				initial: ["rest", gapVariant],
				animate: [
					"hide",
					"rest",
					gapVariant
				],
				variants: buttonVariants,
				whileHover: "hover",
				whileTap: "pressed",
				...rest,
				children: (0, react.cloneElement)(children, childProps, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
					startContent,
					/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
						className: styles.content,
						children: children.props.children
					}),
					endContent
				] }))
			})
		});
	}
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_SpringMotionConfig.SpringMotionConfig, {
		layoutSpeed: "3",
		layoutVariant,
		children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(motion_react.m.button, {
			ref,
			type,
			className: styles.root,
			initial: ["rest", gapVariant],
			animate: [
				"hide",
				"rest",
				gapVariant
			],
			variants: buttonVariants,
			whileHover: "hover",
			whileTap: "pressed",
			...rest,
			children: [
				startContent,
				/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
					className: styles.content,
					children
				}),
				endContent
			]
		})
	});
});
Button.displayName = "Button";

//#endregion
exports.Button = Button;
exports.iconMotionVariants = iconMotionVariants;
exports.loadingMotionVariants = loadingMotionVariants;