"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TogglerSwitch = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _infoIcon = require("../info-icon");
var _togglerPulse = require("./toggler-pulse");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/** Fancy input[type=checkbox]
 * [CAPITALIZATION] Title must be in title case
 * [CAPITALIZATION] Label must be in sentence case
    @midnight-gray-supported
    @alpine-light-supported
 */
const TogglerSwitch = exports.TogglerSwitch = /*#__PURE__*/_react.default.forwardRef(({
  checked = false,
  isDisabled = false,
  noticeable,
  primary,
  labelText,
  ariaLabel,
  subText,
  onChange = () => {},
  id,
  testId,
  children,
  infoIconText,
  infoIconTestId
}, ref) =>
/*#__PURE__*/
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
(0, _jsxRuntime.jsxs)("div", {
  className: "toggler-switch",
  "test-id": testId,
  onClick: e => e.stopPropagation(),
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
    type: "checkbox",
    className: (0, _classnames.default)('toggle', {
      primary
    }),
    id: id,
    "aria-label": ariaLabel || labelText,
    "test-id": `${testId}-input`,
    checked: checked,
    disabled: isDisabled,
    onChange: e => onChange(e.target.checked),
    ref: ref
  }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
    htmlFor: id,
    "test-id": `${testId}-label`,
    children: [children, /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      children: labelText
    }), !!infoIconText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_infoIcon.InfoIcon, {
      testId: infoIconTestId,
      children: infoIconText
    })]
  }), noticeable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_togglerPulse.TogglerPulse, {}), subText && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "toggler-switch-break"
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: (0, _classnames.default)('toggler-switch-subtext', isDisabled && 'disabled'),
      children: subText
    })]
  })]
}));
TogglerSwitch.displayName = 'TogglerSwitch';