"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _native = _interopRequireDefault(require("styled-components/native"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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 SwitchContainer = _native.default.Pressable`
  width: 34px;
  height: 18px;
  background-color: ${({
  isOn,
  bgColor
}) => isOn ? bgColor ? bgColor : '#0056d2' : '#8C8C8C'};
  border-radius: 100px;
  display: flex;
  transition: background-color 0.3s;
  padding: 2px;
`;
const Toggle = (0, _native.default)(_reactNative.Animated.View)`
  width: 15px;
  height: 15px;
  background-color: white;
  border-radius: 100px;
`;
const Switch = ({
  onSwitchOn,
  onSwitchOff,
  onToggle,
  bgColor
}) => {
  const [isOn, setIsOn] = (0, _react.useState)(false);
  const translateX = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
  const toggleSwitch = () => {
    const nextState = !isOn;
    _reactNative.Animated.timing(translateX, {
      toValue: nextState ? 15 : 0,
      duration: 300,
      useNativeDriver: true
    }).start();
    if (nextState) {
      onSwitchOn?.();
    } else {
      onSwitchOff?.();
    }
    setIsOn(nextState);
    onToggle(nextState);
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(SwitchContainer, {
    isOn: isOn,
    onPress: toggleSwitch,
    accessibilityRole: "switch",
    accessibilityState: {
      checked: isOn
    },
    accessibilityLabel: "Toggle switch",
    accessibilityHint: "Double tap to toggle on or off",
    bgColor: bgColor,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Toggle, {
      style: {
        transform: [{
          translateX
        }]
      }
    })
  });
};
var _default = exports.default = Switch;
//# sourceMappingURL=Switch.js.map