import { _ as _extends } from '../extends-C4cduGrv.js';
import { _ as _defineProperty } from '../defineProperty-CEd-kZQW.js';
import { _ as _objectWithoutProperties } from '../objectWithoutProperties-TXwlfNxG.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import VisuallyHidden from '@reach/visually-hidden';

var _excluded = ["enabled", "onClick", "size"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var SIZES = {
  sm: "w-3 h-3",
  md: "w-5 h-5"
};
var STYLES = {
  sm: {
    padding: 2,
    width: 28
  },
  md: {
    padding: 2,
    width: 44
  }
};
var DISABLED_STYLES = {
  filter: "grayscale(100%)",
  cursor: "not-allowed",
  opacity: 0.75
};

function Toggle(_ref) {
  var enabled = _ref.enabled,
      onClick = _ref.onClick,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? "md" : _ref$size,
      props = _objectWithoutProperties(_ref, _excluded);

  var backgroundColor = enabled ? "bg-green-500" : "bg-gray-500";
  var thumbPosition = enabled ? "translate-x-full" : "translate-x-0";
  var activeStyle = props.disabled ? _objectSpread(_objectSpread({}, DISABLED_STYLES), STYLES[size]) : STYLES[size];
  var label = enabled ? "Disable" : "Enable";
  return /*#__PURE__*/React__default.createElement("button", _extends({
    onClick: onClick,
    className: "inline-flex rounded-full transition-colors duration-200 focus:outline-none focus:shadow-outline ".concat(backgroundColor),
    style: activeStyle,
    "aria-checked": enabled,
    role: "switch"
  }, props), /*#__PURE__*/React__default.createElement("div", {
    className: "bg-white rounded-full transition-all duration-200 transform ".concat(thumbPosition, " ").concat(SIZES[size])
  }), /*#__PURE__*/React__default.createElement(VisuallyHidden, null, label));
}

Toggle.propTypes = {
  enabled: PropTypes.bool.isRequired,
  onClick: PropTypes.func.isRequired,
  size: PropTypes.oneOf(["sm", "md"]),
  disabled: PropTypes.bool
};

export { Toggle as default };
