"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _MaterialIcons = _interopRequireDefault(require("react-native-vector-icons/MaterialIcons"));
var _theme = require("../../contexts/theme");
var _reactI18next = require("react-i18next");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const ToggleButton = ({
  isEnabled,
  isAvailable,
  toggleAction,
  testID,
  enabledIcon = 'check',
  disabledIcon = 'close',
  disabled = false
}) => {
  const {
    ColorPallet
  } = (0, _theme.useTheme)();
  const [toggleAnim] = (0, _react.useState)(new _reactNative.Animated.Value(isEnabled ? 1 : 0));
  const {
    t
  } = (0, _reactI18next.useTranslation)();
  (0, _react.useEffect)(() => {
    _reactNative.Animated.timing(toggleAnim, {
      toValue: isEnabled ? 1 : 0,
      duration: 200,
      useNativeDriver: true
    }).start();
  }, [isEnabled, toggleAnim]);
  const backgroundColor = toggleAnim.interpolate({
    inputRange: [0, 1],
    outputRange: [ColorPallet.grayscale.lightGrey, ColorPallet.brand.primary]
  });
  const translateX = toggleAnim.interpolate({
    inputRange: [0, 1],
    outputRange: [2, 25]
  });
  return /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, {
    accessible: true,
    testID: testID,
    accessibilityLabel: isEnabled ? t('Biometry.On') : t('Biometry.Off'),
    accessibilityRole: "switch",
    accessibilityState: {
      checked: isEnabled
    },
    onPress: isAvailable && !disabled ? toggleAction : undefined // Prevent onPress if not available or disabled
    ,
    disabled: !isAvailable || disabled
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: {
      width: 55,
      height: 30,
      borderRadius: 25,
      backgroundColor,
      padding: 3,
      justifyContent: 'center',
      opacity: disabled ? 0.5 : 1 // Visual feedback for disabled state
    }
  }, /*#__PURE__*/_react.default.createElement(_reactNative.Animated.View, {
    style: {
      transform: [{
        translateX
      }],
      width: 25,
      height: 25,
      borderRadius: 20,
      backgroundColor: '#FFFFFF',
      justifyContent: 'center',
      alignItems: 'center'
    }
  }, /*#__PURE__*/_react.default.createElement(_MaterialIcons.default, {
    name: isEnabled ? enabledIcon : disabledIcon,
    size: 15,
    color: isEnabled ? ColorPallet.brand.primary : ColorPallet.grayscale.mediumGrey
  }))));
};
var _default = exports.default = ToggleButton;
//# sourceMappingURL=ToggleButton.js.map