"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ButtonPrimitive = exports.ButtonContent = exports.ButtonLoading = exports.ButtonIcon = exports.ButtonText = exports.ButtonRoot = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = tslib_1.__importStar(require("react"));
const react_native_1 = require("react-native");
// Button root primitive - handles all touch interactions
exports.ButtonRoot = (0, react_1.forwardRef)(({ children, disabled = false, loading = false, onPress, onPressIn, onPressOut, onLongPress, accessibilityRole = "button", accessibilityLabel, accessibilityHint, accessibilityState, testID, style, hoverStyle, ...props }, ref) => {
    const [isHovered, setIsHovered] = (0, react_1.useState)(false);
    const handlePress = react_1.default.useCallback((event) => {
        if (!disabled && !loading && onPress) {
            onPress(event);
        }
    }, [disabled, loading, onPress]);
    const handlePressIn = react_1.default.useCallback((event) => {
        if (!disabled && !loading && onPressIn) {
            onPressIn(event);
        }
    }, [disabled, loading, onPressIn]);
    const handlePressOut = react_1.default.useCallback((event) => {
        if (!disabled && !loading && onPressOut) {
            onPressOut(event);
        }
    }, [disabled, loading, onPressOut]);
    const handleLongPress = react_1.default.useCallback((event) => {
        if (!disabled && !loading && onLongPress) {
            onLongPress(event);
        }
    }, [disabled, loading, onLongPress]);
    const handleHoverIn = react_1.default.useCallback(() => {
        if (!disabled && !loading) {
            setIsHovered(true);
        }
    }, [disabled, loading]);
    const handleHoverOut = react_1.default.useCallback(() => {
        setIsHovered(false);
    }, []);
    return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { ref: ref, onPress: handlePress, onPressIn: handlePressIn, onPressOut: handlePressOut, onLongPress: handleLongPress, onHoverIn: handleHoverIn, onHoverOut: handleHoverOut, disabled: disabled || loading, accessibilityRole: accessibilityRole, accessibilityLabel: accessibilityLabel, accessibilityHint: accessibilityHint, accessibilityState: {
            disabled: disabled || loading,
            busy: loading,
            ...accessibilityState,
        }, testID: testID, style: [
            primitiveStyles.button,
            primitiveStyles.transition,
            (disabled || loading) && primitiveStyles.disabled,
            style,
            isHovered && hoverStyle,
        ], ...props, children: children }));
});
exports.ButtonRoot.displayName = "ButtonRoot";
exports.ButtonText = (0, react_1.forwardRef)(({ children, disabled, loading, style, ...props }, ref) => {
    return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { ref: ref, style: [
            primitiveStyles.text,
            (disabled || loading) && primitiveStyles.textDisabled,
            style,
        ], ...props, children: children }));
});
exports.ButtonText.displayName = "ButtonText";
exports.ButtonIcon = (0, react_1.forwardRef)(({ children, position = "left", disabled, loading, style, ...props }, ref) => {
    return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: ref, style: [
            primitiveStyles.icon,
            (disabled || loading) && primitiveStyles.iconDisabled,
            style,
        ], ...props, children: children }));
});
exports.ButtonIcon.displayName = "ButtonIcon";
exports.ButtonLoading = (0, react_1.forwardRef)(({ children, visible = false, style, ...props }, ref) => {
    if (!visible)
        return null;
    return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: ref, style: [primitiveStyles.loading, style], ...props, children: children }));
});
exports.ButtonLoading.displayName = "ButtonLoading";
exports.ButtonContent = (0, react_1.forwardRef)(({ children, direction = "row", align = "center", justify = "center", style, ...props }, ref) => {
    return ((0, jsx_runtime_1.jsx)(react_native_1.View, { ref: ref, style: [
            primitiveStyles.content,
            {
                flexDirection: direction,
                alignItems: align,
                justifyContent: justify,
            },
            style,
        ], ...props, children: children }));
});
exports.ButtonContent.displayName = "ButtonContent";
// Primitive styles (minimal, unstyled)
const primitiveStyles = react_native_1.StyleSheet.create({
    button: {
        flexDirection: "row",
        alignItems: "center",
        justifyContent: "center",
    },
    transition: react_native_1.Platform.OS === "web"
        ? // probably fine if web-only
            {
                transitionDuration: "150ms",
                transitionProperty: "background-color, border-color, color",
            }
        : undefined,
    disabled: {
        opacity: 0.5,
    },
    content: {
        flexDirection: "row",
        alignItems: "center",
        justifyContent: "center",
    },
    text: {
        textAlign: "center",
    },
    textDisabled: {
        opacity: 0.5,
    },
    icon: {
        alignItems: "center",
        justifyContent: "center",
    },
    iconDisabled: {
        opacity: 0.5,
    },
    loading: {
        position: "absolute",
        alignItems: "center",
        justifyContent: "center",
    },
});
// Export primitive collection
exports.ButtonPrimitive = {
    Root: exports.ButtonRoot,
    Text: exports.ButtonText,
    Icon: exports.ButtonIcon,
    Loading: exports.ButtonLoading,
    Content: exports.ButtonContent,
};
//# sourceMappingURL=button.js.map