"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TextButton = exports.SecondaryButton = exports.PrimaryButton = exports.InverseButton = exports.IconButton = exports.GhostButton = exports.Button = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _usePressAnimation = require("../hooks/usePressAnimation.js");
var _useInteractionState = require("../hooks/useInteractionState.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const SIZE_CONFIG = {
  small: {
    paddingVertical: 6,
    paddingHorizontal: 12,
    fontSize: 14,
    minHeight: 32
  },
  medium: {
    paddingVertical: 8,
    paddingHorizontal: 16,
    fontSize: 15,
    minHeight: 40
  },
  large: {
    paddingVertical: 12,
    paddingHorizontal: 20,
    fontSize: 16,
    minHeight: 48
  }
};
const ICON_HIT_SLOP = {
  top: 10,
  bottom: 10,
  left: 10,
  right: 10
};
const PRESS_SCALE = 0.97;
const SCALE_VARIANTS = new Set(['primary', 'secondary', 'inverse']);
const ButtonComponent = ({
  onPress,
  children,
  disabled = false,
  variant = 'primary',
  size = 'medium',
  style,
  textStyle,
  icon,
  iconPosition = 'left',
  loading = false,
  loadingColor,
  accessibilityLabel,
  accessibilityHint,
  hitSlop,
  activeOpacity,
  testID,
  className
}) => {
  const theme = (0, _useTheme.useTheme)();
  const hasScaleFeedback = SCALE_VARIANTS.has(variant);
  const isInteractionBlocked = disabled || loading;
  const {
    scaleAnim,
    onPressIn: onScalePressIn,
    onPressOut: onScalePressOut
  } = (0, _usePressAnimation.usePressAnimation)(hasScaleFeedback && !isInteractionBlocked ? PRESS_SCALE : undefined);
  // Non-scale variants (icon/ghost/text) convey press feedback via an opacity
  // dip. We drive it through component state + onPressIn/onPressOut rather than
  // Pressable's function-form `style` because NativeWind v4's css-interop
  // rewrites the `style` prop of every JSX element and swallows the function
  // form, which would drop ALL base styles (background, radius, padding,
  // minHeight). A static style array is merged correctly by css-interop.
  const {
    state: pressed,
    onIn: onPressedIn,
    onOut: onPressedOut
  } = (0, _useInteractionState.useInteractionState)();
  const handlePressIn = (0, _react.useMemo)(() => {
    if (isInteractionBlocked) return undefined;
    return () => {
      onScalePressIn();
      onPressedIn();
    };
  }, [isInteractionBlocked, onScalePressIn, onPressedIn]);
  const handlePressOut = (0, _react.useMemo)(() => {
    if (isInteractionBlocked) return undefined;
    return () => {
      onScalePressOut();
      onPressedOut();
    };
  }, [isInteractionBlocked, onScalePressOut, onPressedOut]);
  const baseStyles = (0, _react.useMemo)(() => {
    const sizeConfig = SIZE_CONFIG[size];
    const styles = {
      alignItems: 'center',
      justifyContent: 'center',
      flexDirection: 'row',
      overflow: 'hidden'
    };
    if (variant !== 'icon') {
      styles.paddingVertical = sizeConfig.paddingVertical;
      styles.paddingHorizontal = sizeConfig.paddingHorizontal;
      styles.minHeight = sizeConfig.minHeight;
    }
    switch (variant) {
      case 'primary':
        styles.backgroundColor = theme.colors.primary;
        styles.borderRadius = 20;
        break;
      case 'secondary':
        styles.backgroundColor = 'transparent';
        styles.borderWidth = 1;
        styles.borderColor = theme.colors.border;
        styles.borderRadius = 20;
        break;
      case 'inverse':
        styles.backgroundColor = '#FFFFFF';
        styles.borderRadius = 20;
        break;
      case 'icon':
        styles.borderRadius = 100;
        styles.padding = 8;
        styles.width = sizeConfig.minHeight;
        styles.height = sizeConfig.minHeight;
        break;
      case 'ghost':
        styles.backgroundColor = 'transparent';
        styles.borderRadius = 8;
        break;
      case 'text':
        styles.backgroundColor = 'transparent';
        styles.paddingVertical = 4;
        styles.paddingHorizontal = 8;
        break;
    }
    return styles;
  }, [variant, size, theme]);
  const resolvedTextColor = (0, _react.useMemo)(() => {
    switch (variant) {
      case 'primary':
        return theme.colors.primaryForeground;
      case 'secondary':
        return theme.colors.text;
      case 'inverse':
        return '#000000';
      case 'ghost':
      case 'text':
        return theme.colors.primary;
      case 'icon':
      default:
        return theme.colors.text;
    }
  }, [variant, theme]);
  const computedTextStyle = (0, _react.useMemo)(() => {
    const sizeConfig = SIZE_CONFIG[size];
    return {
      fontSize: sizeConfig.fontSize,
      fontWeight: _reactNative.Platform.OS === 'web' ? 'bold' : '600',
      color: resolvedTextColor
    };
  }, [size, resolvedTextColor]);
  const defaultHitSlop = variant === 'icon' ? ICON_HIT_SLOP : undefined;
  const resolvedActiveOpacity = activeOpacity ?? (variant === 'icon' ? 0.7 : 0.8);
  const resolvedClassName = className ?? (variant === 'icon' ? 'bg-background border border-border' : undefined);
  const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [iconPosition === 'left' && icon, children != null && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
      style: [computedTextStyle, textStyle],
      children: children
    }), iconPosition === 'right' && icon]
  });
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
    style: hasScaleFeedback ? {
      transform: [{
        scale: scaleAnim
      }]
    } : undefined,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
      ...(resolvedClassName ? {
        className: resolvedClassName
      } : {}),
      style: [baseStyles, disabled && !loading && {
        opacity: 0.5
      }, pressed && !hasScaleFeedback && !isInteractionBlocked && {
        opacity: resolvedActiveOpacity
      }, style],
      onPress: isInteractionBlocked ? undefined : onPress,
      onPressIn: handlePressIn,
      onPressOut: handlePressOut,
      disabled: isInteractionBlocked,
      hitSlop: hitSlop ?? defaultHitSlop,
      accessibilityLabel: accessibilityLabel,
      accessibilityHint: accessibilityHint,
      accessibilityRole: "button",
      accessibilityState: loading ? {
        disabled: isInteractionBlocked,
        busy: true
      } : {
        disabled: isInteractionBlocked
      },
      testID: testID,
      children: loading ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
          style: styles.loadingHiddenContent,
          importantForAccessibility: "no-hide-descendants",
          accessibilityElementsHidden: true,
          children: content
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
          style: styles.loadingOverlay,
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.ActivityIndicator, {
            size: "small",
            color: loadingColor ?? resolvedTextColor
          })
        })]
      }) : content
    })
  });
};
const styles = _reactNative.StyleSheet.create({
  loadingHiddenContent: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    opacity: 0,
    pointerEvents: 'none'
  },
  loadingOverlay: {
    ..._reactNative.StyleSheet.absoluteFill,
    alignItems: 'center',
    justifyContent: 'center',
    pointerEvents: 'none'
  }
});
const Button = exports.Button = /*#__PURE__*/(0, _react.memo)(ButtonComponent);
Button.displayName = 'Button';
const PrimaryButton = exports.PrimaryButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "primary"
}));
PrimaryButton.displayName = 'PrimaryButton';
const SecondaryButton = exports.SecondaryButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "secondary"
}));
SecondaryButton.displayName = 'SecondaryButton';
const IconButton = exports.IconButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "icon"
}));
IconButton.displayName = 'IconButton';
const GhostButton = exports.GhostButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "ghost"
}));
GhostButton.displayName = 'GhostButton';
const InverseButton = exports.InverseButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "inverse"
}));
InverseButton.displayName = 'InverseButton';
const TextButton = exports.TextButton = /*#__PURE__*/(0, _react.memo)(props => /*#__PURE__*/(0, _jsxRuntime.jsx)(Button, {
  ...props,
  variant: "text"
}));
TextButton.displayName = 'TextButton';
//# sourceMappingURL=Button.js.map