"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const Button = (0, react_1.forwardRef)(({ variant = 'solid', size = 'md', colorScheme = 'primary', leftIcon, rightIcon, isLoading = false, loadingText, isFullWidth = false, isDisabled = false, isActive = false, isFocusable = true, spinner, spinnerPlacement = 'start', form, type = 'button', name, value, className = '', wrapperClassName = '', iconClassName = '', spinnerClassName = '', children, onClick, onFocus, onBlur, onKeyDown, onKeyUp, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onTouchStart, onTouchEnd, onTouchMove, onTouchCancel, ...props }, ref) => {
    // Theme and form context would be implemented here in real usage
    const handleClick = (0, react_1.useCallback)((event) => {
        if (isDisabled || isLoading) {
            event.preventDefault();
            return;
        }
        onClick?.(event);
    }, [isDisabled, isLoading, onClick]);
    const handleKeyDown = (0, react_1.useCallback)((event) => {
        if (isDisabled || isLoading) {
            event.preventDefault();
            return;
        }
        onKeyDown?.(event);
    }, [isDisabled, isLoading, onKeyDown]);
    const handleKeyUp = (0, react_1.useCallback)((event) => {
        if (isDisabled || isLoading) {
            event.preventDefault();
            return;
        }
        onKeyUp?.(event);
    }, [isDisabled, isLoading, onKeyUp]);
    const buttonId = react_1.default.useId();
    const loadingId = react_1.default.useId();
    const ariaProps = {
        'aria-disabled': isDisabled ? true : undefined,
        'aria-busy': isLoading ? true : undefined,
        'aria-describedby': isLoading && loadingText ? loadingId : undefined,
        'aria-pressed': variant === 'solid' ? isActive : undefined
    };
    const defaultSpinner = ((0, jsx_runtime_1.jsx)("svg", { className: `bf-button-spinner ${spinnerClassName}`, viewBox: "0 0 24 24", role: "status", "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("circle", { className: "bf-button-spinner-circle", cx: "12", cy: "12", r: "10", fill: "none", stroke: "currentColor", strokeWidth: "4" }) }));
    const renderContent = () => {
        if (isLoading) {
            return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [spinnerPlacement === 'start' && (spinner || defaultSpinner), loadingText || children, spinnerPlacement === 'end' && (spinner || defaultSpinner)] }));
        }
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [leftIcon && ((0, jsx_runtime_1.jsx)("span", { className: `bf-button-icon bf-button-icon-left ${iconClassName}`, "aria-hidden": "true", children: leftIcon })), children, rightIcon && ((0, jsx_runtime_1.jsx)("span", { className: `bf-button-icon bf-button-icon-right ${iconClassName}`, "aria-hidden": "true", children: rightIcon }))] }));
    };
    return ((0, jsx_runtime_1.jsxs)("div", { className: `bf-button-wrapper ${wrapperClassName}`, "data-variant": variant, "data-size": size, "data-color-scheme": colorScheme, "data-full-width": isFullWidth, "data-disabled": isDisabled, "data-loading": isLoading, "data-active": isActive, children: [(0, jsx_runtime_1.jsx)("button", { ref: ref, id: buttonId, type: type, form: form, name: name, value: value, disabled: isDisabled, tabIndex: isFocusable ? 0 : -1, onClick: handleClick, onFocus: onFocus, onBlur: onBlur, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave, onMouseDown: onMouseDown, onMouseUp: onMouseUp, onTouchStart: onTouchStart, onTouchEnd: onTouchEnd, onTouchMove: onTouchMove, onTouchCancel: onTouchCancel, ...ariaProps, "data-loading": isLoading || undefined, className: `bf-button ${className}`, style: isFullWidth ? { width: '100%' } : undefined, ...props, children: renderContent() }), isLoading && loadingText && ((0, jsx_runtime_1.jsx)("span", { id: loadingId, className: "bf-button-loading-text", "aria-live": "assertive", children: loadingText }))] }));
});
Button.displayName = 'Button';
const MemoizedButton = (0, react_1.memo)(Button);
exports.Button = MemoizedButton;
exports.default = MemoizedButton;
//# sourceMappingURL=Button.js.map