import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { forwardRef } from 'react';
import classnames from 'classnames';
import Check from '@bigbinary/neeto-icons/Check';
import Close from '@bigbinary/neeto-icons/Close';
import { u as useId } from './useId-Jj9hXm-g.js';
import '@babel/runtime/helpers/slicedToArray';
import 'react-router-dom';
import '@bigbinary/neeto-hotkeys';
import './overlayManager.js';
import { h as hyphenize, n as noop } from './index-QWVp_Xt6.js';
import 'qs';
import Label from './Label.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@bigbinary/neeto-cist';
import 'ramda';
import './en-Dmu3B4Vs.js';
import './index-DyUNP5G9.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'dayjs';
import 'dayjs/plugin/localeData';
import 'dayjs/plugin/utc';
import 'dayjs/plugin/weekday';
import 'dayjs/plugin/weekOfYear';
import 'i18next';
import '@bigbinary/neeto-icons/Help';
import './Button.js';
import './Spinner.js';
import './Tooltip.js';
import '@tippyjs/react';
import 'tippy.js';
import './usePrefersReducedMotion-n4ZJtExQ.js';
import './Popover.js';
import './Typography.js';

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(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__*/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 ? noop : _ref$onChange,
    labelProps = _ref.labelProps,
    children = _ref.children,
    otherProps = _objectWithoutProperties(_ref, _excluded);
  var id = useId(otherProps.id);
  var errorId = "error_".concat(id);
  var checked = otherProps.checked,
    disabled = otherProps.disabled;
  var renderLabel = label || children;
  return /*#__PURE__*/jsxs("div", {
    ref: ref,
    className: classnames(["neeto-ui-switch__wrapper", className]),
    "data-testid": "nui-switch-wrapper",
    children: [/*#__PURE__*/jsxs("div", {
      className: "neeto-ui-switch__container",
      children: [/*#__PURE__*/jsxs("label", {
        "data-testid": "nui-switch-item",
        className: classnames("neeto-ui-switch__item", {
          "neeto-ui-switch__item--checked": !!checked,
          "neeto-ui-switch__item--disabled": disabled
        }),
        children: [/*#__PURE__*/jsx("input", _objectSpread({
          id: id,
          onChange: onChange,
          "aria-describedby": error ? errorId : undefined,
          "aria-invalid": !!error,
          "aria-required": required,
          type: "checkbox"
        }, otherProps)), /*#__PURE__*/jsx("span", {
          "aria-hidden": "true",
          "data-testid": "".concat(hyphenize(renderLabel), "-switch"),
          className: classnames("neeto-ui-switch", {
            "neeto-ui-switch--checked": !!checked
          }),
          children: checked ? /*#__PURE__*/jsx(Check, {
            "data-testid": "check-icon",
            size: "12",
            strokeWidth: 4
          }) : /*#__PURE__*/jsx(Close, {
            "data-testid": "close-icon",
            size: "12",
            strokeWidth: 3
          })
        })]
      }), renderLabel && /*#__PURE__*/jsx(Label, _objectSpread(_objectSpread({
        required: required,
        htmlFor: id
      }, labelProps), {}, {
        "data-testid": "".concat(hyphenize(renderLabel).replace(/[^a-z0-9-]/gi, ""), "-switch-label"),
        children: renderLabel
      }))]
    }), !!error && /*#__PURE__*/jsx("p", {
      className: "neeto-ui-input__error",
      "data-testid": "".concat(hyphenize(renderLabel), "-switch-error"),
      id: errorId,
      children: error
    })]
  });
});
Switch.displayName = "Switch";

export { Switch as default };
//# sourceMappingURL=Switch.js.map
