"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _theming = require("../../core/theming");
var _useAnimatedValue = _interopRequireDefault(require("../../utils/useAnimatedValue"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const version = _reactNative.NativeModules.PlatformConstants ? _reactNative.NativeModules.PlatformConstants.reactNativeVersion : undefined;
const KNOB_OFFSET = 36;
const Switch = _ref => {
  let {
    value,
    disabled,
    onValueChange,
    color,
    theme,
    ...rest
  } = _ref;
  const xPosiiton = (0, _useAnimatedValue.default)(value ? KNOB_OFFSET : 0);
  React.useEffect(() => {
    _reactNative.Animated.timing(xPosiiton, {
      toValue: value ? KNOB_OFFSET : 0,
      easing: _reactNative.Easing.elastic(0.7),
      duration: 100,
      useNativeDriver: true
    }).start();
    return () => {};
  }, [value]);
  return /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.TouchableHighlight, {
    underlayColor: theme.colors.bg.muted,
    style: {
      width: 64,
      height: 24,
      borderRadius: KNOB_OFFSET,
      padding: 4,
      backgroundColor: theme.colors.bg.muted,
      justifyContent: "center"
    },
    onPress: disabled ? undefined : onValueChange
  }, /*#__PURE__*/React.createElement(_reactNative.Animated.View, {
    style: {
      width: 20,
      height: 20,
      borderRadius: 32,
      backgroundColor: "white",
      alignItems: "center",
      justifyContent: "center",
      transform: [{
        translateX: xPosiiton
      }]
    }
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: {
      width: 12,
      height: 12,
      backgroundColor: value ? theme.colors.primary.default : theme.colors.fg.subtle,
      borderRadius: 16
    }
  }))));
};
var _default = (0, _theming.withTheme)(Switch);
exports.default = _default;
//# sourceMappingURL=Switch.js.map