/*! ratio-ui · design system for knowledge sharing · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
import { ChevronDown, LoaderCircle } from "../../icons/index.js";
import { buttonSizes, buttonStyles } from "../Button/Button2.js";
import "react";
import { jsx, jsxs } from "react/jsx-runtime";
import { Button, Menu, MenuItem, MenuTrigger, Popover } from "react-aria-components";
//#region src/core/SplitButton/SplitButton.tsx
var menuItemStyles = "cursor-pointer flex w-full items-center gap-2 px-3 py-2 hover:bg-card-hover text-(--text) outline-none";
var menuStyles = "min-w-48 origin-top-right bg-card border border-border-1 shadow-lg rounded-lg overflow-hidden";
function SplitButton({ children, onClick, actions, variant = "outline", size = "md", loading = false, disabled = false, icon, testId }) {
	const isDisabled = disabled || loading;
	const sizeClasses = buttonSizes[size];
	const variantClasses = buttonStyles[variant];
	const paddingClasses = sizeClasses.split(" ").filter((c) => c.startsWith("px-") || c.startsWith("py-")).join(" ");
	const baseClasses = `${variantClasses} ${sizeClasses.split(" ").find((c) => c.startsWith("text-")) ?? ""}`.replace("rounded-full", "");
	const disabledClasses = isDisabled ? "opacity-75 cursor-not-allowed" : "";
	return /* @__PURE__ */ jsxs("div", {
		className: "inline-flex rounded-full overflow-hidden",
		"data-testid": testId,
		children: [/* @__PURE__ */ jsxs("button", {
			type: "button",
			onClick,
			disabled: isDisabled,
			className: `${baseClasses} ${paddingClasses} ${disabledClasses} rounded-l-full border-r-0 flex items-center gap-2`,
			children: [loading ? /* @__PURE__ */ jsx(LoaderCircle, {
				className: "h-4 w-4 animate-spin shrink-0",
				"aria-hidden": "true"
			}) : icon && /* @__PURE__ */ jsx("span", {
				className: "shrink-0",
				children: icon
			}), /* @__PURE__ */ jsx("span", { children })]
		}), /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsx(Button, {
			isDisabled,
			className: `${baseClasses} px-2 ${disabledClasses} rounded-r-full border-l border-l-gray-400/30 flex items-center`,
			children: /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4" })
		}), /* @__PURE__ */ jsx(Popover, {
			placement: "bottom end",
			children: /* @__PURE__ */ jsx(Menu, {
				className: menuStyles,
				onAction: (key) => {
					const action = actions.find((a) => a.id === key);
					if (action) action.onClick();
				},
				children: actions.map((action) => /* @__PURE__ */ jsxs(MenuItem, {
					id: action.id,
					className: menuItemStyles,
					children: [action.icon && /* @__PURE__ */ jsx("span", {
						className: "shrink-0",
						children: action.icon
					}), /* @__PURE__ */ jsx("span", { children: action.label })]
				}, action.id))
			})
		})] })]
	});
}
//#endregion
export { SplitButton };

//# sourceMappingURL=SplitButton.js.map