"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Checkbox = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _tokens = require("../styles/tokens.js");
var _nativeDriver = require("../styles/native-driver.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: {
    box: 18,
    checkmark: 10,
    fontSize: 14,
    lineHeight: 20,
    descFontSize: 12
  },
  medium: {
    box: 22,
    checkmark: 12,
    fontSize: 15,
    lineHeight: 22,
    descFontSize: 13
  },
  large: {
    box: 26,
    checkmark: 14,
    fontSize: 16,
    lineHeight: 24,
    descFontSize: 14
  }
};
const CheckboxComponent = ({
  checked,
  onCheckedChange,
  label,
  description,
  size = 'medium',
  disabled = false,
  indeterminate = false,
  color,
  style,
  labelStyle,
  accessibilityLabel,
  testID
}) => {
  const theme = (0, _useTheme.useTheme)();
  const scaleAnim = (0, _react.useRef)(new _reactNative.Animated.Value(checked ? 1 : 0)).current;
  const pressAnim = (0, _react.useRef)(new _reactNative.Animated.Value(1)).current;
  const sizeConfig = SIZE_CONFIG[size];
  const checkColor = color ?? theme.colors.primary;
  // The checkmark sits on top of `checkColor`. When the box uses the theme
  // primary, use the preset's readable foreground (white for blue, black for
  // yellow). A caller-supplied custom color falls back to white.
  const checkmarkColor = color == null ? theme.colors.primaryForeground : '#fff';
  (0, _react.useEffect)(() => {
    _reactNative.Animated.spring(scaleAnim, {
      toValue: checked || indeterminate ? 1 : 0,
      useNativeDriver: _nativeDriver.SUPPORTS_NATIVE_DRIVER,
      ..._tokens.animation.spring.snappy
    }).start();
  }, [checked, indeterminate, scaleAnim]);
  const handlePress = (0, _react.useCallback)(() => {
    if (!disabled) {
      onCheckedChange(!checked);
    }
  }, [checked, disabled, onCheckedChange]);
  const onPressIn = (0, _react.useCallback)(() => {
    _reactNative.Animated.spring(pressAnim, {
      toValue: 0.9,
      useNativeDriver: _nativeDriver.SUPPORTS_NATIVE_DRIVER,
      ..._tokens.animation.spring.snappy
    }).start();
  }, [pressAnim]);
  const onPressOut = (0, _react.useCallback)(() => {
    _reactNative.Animated.spring(pressAnim, {
      toValue: 1,
      useNativeDriver: _nativeDriver.SUPPORTS_NATIVE_DRIVER,
      ..._tokens.animation.spring.gentle
    }).start();
  }, [pressAnim]);
  const boxStyle = (0, _react.useMemo)(() => {
    const base = {
      width: sizeConfig.box,
      height: sizeConfig.box,
      borderRadius: _tokens.borderRadius._2xs + 2,
      borderWidth: 2,
      alignItems: 'center',
      justifyContent: 'center'
    };
    if (checked || indeterminate) {
      base.backgroundColor = checkColor;
      base.borderColor = checkColor;
    } else {
      base.backgroundColor = 'transparent';
      base.borderColor = theme.colors.border;
    }
    return base;
  }, [sizeConfig, checked, indeterminate, checkColor, theme]);

  // Checkmark using unicode characters for zero-dependency rendering
  const checkmarkContent = indeterminate ? '\u2014' : '\u2713';
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
    style: [{
      flexDirection: 'row',
      alignItems: 'flex-start',
      gap: _tokens.space.sm,
      opacity: disabled ? 0.4 : 1
    }, style],
    onPress: handlePress,
    onPressIn: onPressIn,
    onPressOut: onPressOut,
    disabled: disabled,
    accessibilityRole: "checkbox",
    accessibilityState: {
      checked: indeterminate ? 'mixed' : checked,
      disabled
    },
    accessibilityLabel: accessibilityLabel ?? label,
    hitSlop: {
      top: 8,
      bottom: 8,
      left: 8,
      right: 8
    },
    testID: testID,
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
      style: [boxStyle, {
        transform: [{
          scale: pressAnim
        }]
      }],
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
        style: {
          opacity: scaleAnim,
          transform: [{
            scale: scaleAnim
          }]
        },
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
          style: {
            fontSize: sizeConfig.checkmark,
            color: checkmarkColor,
            fontWeight: '700',
            lineHeight: sizeConfig.checkmark + 2,
            textAlign: 'center'
          },
          children: checkmarkContent
        })
      })
    }), (label || description) && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
      style: {
        flex: 1,
        paddingTop: 1
      },
      children: [label && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: [{
          fontSize: sizeConfig.fontSize,
          lineHeight: sizeConfig.lineHeight,
          color: theme.colors.text,
          fontWeight: '500'
        }, labelStyle],
        children: label
      }), description && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
        style: {
          fontSize: sizeConfig.descFontSize,
          color: theme.colors.textSecondary,
          lineHeight: sizeConfig.descFontSize + 6,
          marginTop: 2
        },
        children: description
      })]
    })]
  });
};
const Checkbox = exports.Checkbox = /*#__PURE__*/(0, _react.memo)(CheckboxComponent);
Checkbox.displayName = 'Checkbox';
//# sourceMappingURL=Checkbox.js.map