'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var Check = require('@bigbinary/neeto-icons/Check');
var Close = require('@bigbinary/neeto-icons/Close');
var useId = require('./useId-DXHUzdxd.js');
require('@babel/runtime/helpers/slicedToArray');
require('react-router-dom');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
var index = require('./index-CNZKW5X0.js');
require('qs');
var Label = require('./Label.js');
var jsxRuntime = require('react/jsx-runtime');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('ramda');
require('./en-B1i-pQJm.js');
require('./index-BgzkP01c.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('i18next');
require('@bigbinary/neeto-icons/Help');
require('./Button.js');
require('./Spinner.js');
require('./Tooltip.js');
require('@tippyjs/react');
require('tippy.js');
require('./usePrefersReducedMotion-D2Ck84HM.js');
require('./Popover.js');
require('./Typography.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Check__default = /*#__PURE__*/_interopDefault(Check);
var Close__default = /*#__PURE__*/_interopDefault(Close);

var _excluded = ["label", "required", "className", "error", "onChange", "labelProps", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Switch = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    _ref$required = _ref.required,
    required = _ref$required === void 0 ? false : _ref$required,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$error = _ref.error,
    error = _ref$error === void 0 ? "" : _ref$error,
    _ref$onChange = _ref.onChange,
    onChange = _ref$onChange === void 0 ? index.noop : _ref$onChange,
    labelProps = _ref.labelProps,
    children = _ref.children,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded);
  var id = useId.useId(otherProps.id);
  var errorId = "error_".concat(id);
  var checked = otherProps.checked,
    disabled = otherProps.disabled;
  var renderLabel = label || children;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    ref: ref,
    className: classnames__default.default(["neeto-ui-switch__wrapper", className]),
    "data-testid": "nui-switch-wrapper",
    children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-ui-switch__container",
      children: [/*#__PURE__*/jsxRuntime.jsxs("label", {
        "data-testid": "nui-switch-item",
        className: classnames__default.default("neeto-ui-switch__item", {
          "neeto-ui-switch__item--checked": !!checked,
          "neeto-ui-switch__item--disabled": disabled
        }),
        children: [/*#__PURE__*/jsxRuntime.jsx("input", _objectSpread({
          id: id,
          onChange: onChange,
          "aria-describedby": error ? errorId : undefined,
          "aria-invalid": !!error,
          "aria-required": required,
          type: "checkbox"
        }, otherProps)), /*#__PURE__*/jsxRuntime.jsx("span", {
          "aria-hidden": "true",
          "data-testid": "".concat(index.hyphenize(renderLabel), "-switch"),
          className: classnames__default.default("neeto-ui-switch", {
            "neeto-ui-switch--checked": !!checked
          }),
          children: checked ? /*#__PURE__*/jsxRuntime.jsx(Check__default.default, {
            "data-testid": "check-icon",
            size: "12",
            strokeWidth: 4
          }) : /*#__PURE__*/jsxRuntime.jsx(Close__default.default, {
            "data-testid": "close-icon",
            size: "12",
            strokeWidth: 3
          })
        })]
      }), renderLabel && /*#__PURE__*/jsxRuntime.jsx(Label, _objectSpread(_objectSpread({
        required: required,
        htmlFor: id
      }, labelProps), {}, {
        "data-testid": "".concat(index.hyphenize(renderLabel).replace(/[^a-z0-9-]/gi, ""), "-switch-label"),
        children: renderLabel
      }))]
    }), !!error && /*#__PURE__*/jsxRuntime.jsx("p", {
      className: "neeto-ui-input__error",
      "data-testid": "".concat(index.hyphenize(renderLabel), "-switch-error"),
      id: errorId,
      children: error
    })]
  });
});
Switch.displayName = "Switch";

module.exports = Switch;
//# sourceMappingURL=Switch.js.map
