Liferay.Loader.define("dynamic-data-mapping-form-field-type@5.0.83/CheckboxMultiple/CheckboxMultiple.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/form', 'frontend-js-react-web$classnames', 'frontend-js-react-web$react', '../FieldBase/ReactFieldBase.es', '../util/setters.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _form = require("@frontend-taglib-clay$clayui/form");

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _ReactFieldBase = require("../FieldBase/ReactFieldBase.es");

    var _setters = require("../util/setters.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var Switcher = function Switcher(_ref) {
      var checked = _ref.checked,
          disabled = _ref.disabled,
          inline = _ref.inline,
          label = _ref.label,
          name = _ref.name,
          onBlur = _ref.onBlur,
          onChange = _ref.onChange,
          onFocus = _ref.onFocus,
          value = _ref.value;
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: (0, _classnames.default)('lfr-ddm-form-field-checkbox-switch', {
            'lfr-ddm-form-field-checkbox-switch-inline': inline
          })
        }, /*#__PURE__*/_react.default.createElement("label", {
          className: "simple-toggle-switch toggle-switch"
        }, /*#__PURE__*/_react.default.createElement("input", {
          checked: checked,
          className: "toggle-switch-check",
          disabled: disabled,
          name: name,
          onBlur: onBlur,
          onChange: onChange,
          onFocus: onFocus,
          type: "checkbox",
          value: value
        }), /*#__PURE__*/_react.default.createElement("span", {
          "aria-hidden": "true",
          className: "toggle-switch-bar"
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "toggle-switch-handle"
        })), /*#__PURE__*/_react.default.createElement("span", {
          className: "toggle-switch-label"
        }, label)))
      );
    };

    var CheckboxMultiple = function CheckboxMultiple(_ref2) {
      var disabled = _ref2.disabled,
          inline = _ref2.inline,
          isSwitcher = _ref2.isSwitcher,
          name = _ref2.name,
          onBlur = _ref2.onBlur,
          onChange = _ref2.onChange,
          onFocus = _ref2.onFocus,
          options = _ref2.options,
          predefinedValue = _ref2.predefinedValue,
          initialValue = _ref2.value;

      var _useState = (0, _react.useState)(initialValue),
          _useState2 = _slicedToArray(_useState, 2),
          value = _useState2[0],
          setValue = _useState2[1];

      var displayValues = value && value.length > 0 ? value : predefinedValue;
      var Toggle = isSwitcher ? Switcher : _form.ClayCheckbox;

      var handleChange = function handleChange(event) {
        var target = event.target;
        var newValue = value.filter(function (currentValue) {
          return currentValue !== target.value;
        });

        if (target.checked) {
          newValue.push(target.value);
        }

        setValue(newValue);
        onChange(event, newValue);
      };

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "lfr-ddm-checkbox-multiple"
        }, options.map(function (option, index) {
          return (/*#__PURE__*/_react.default.createElement(Toggle, {
              checked: displayValues.includes(option.value),
              disabled: disabled,
              inline: inline,
              key: option.value,
              label: option.label,
              name: "".concat(name, "_").concat(index),
              onBlur: onBlur,
              onChange: handleChange,
              onFocus: onFocus,
              value: option.value
            })
          );
        }), /*#__PURE__*/_react.default.createElement("input", {
          name: name,
          type: "hidden",
          value: value
        }))
      );
    };

    var Main = function Main(_ref3) {
      var inline = _ref3.inline,
          name = _ref3.name,
          _ref3$options = _ref3.options,
          options = _ref3$options === void 0 ? [{
        label: 'Option 1',
        value: 'option1'
      }, {
        label: 'Option 2',
        value: 'option2'
      }] : _ref3$options,
          onBlur = _ref3.onBlur,
          onChange = _ref3.onChange,
          onFocus = _ref3.onFocus,
          predefinedValue = _ref3.predefinedValue,
          readOnly = _ref3.readOnly,
          _ref3$showAsSwitcher = _ref3.showAsSwitcher,
          showAsSwitcher = _ref3$showAsSwitcher === void 0 ? true : _ref3$showAsSwitcher,
          value = _ref3.value,
          otherProps = _objectWithoutProperties(_ref3, ["inline", "name", "options", "onBlur", "onChange", "onFocus", "predefinedValue", "readOnly", "showAsSwitcher", "value"]);

      return (/*#__PURE__*/_react.default.createElement(_ReactFieldBase.FieldBase, _extends({
          name: name,
          readOnly: readOnly
        }, otherProps), /*#__PURE__*/_react.default.createElement(CheckboxMultiple, {
          disabled: readOnly,
          inline: inline,
          isSwitcher: showAsSwitcher,
          name: name,
          onBlur: onBlur,
          onChange: onChange,
          onFocus: onFocus,
          options: options,
          predefinedValue: (0, _setters.setJSONArrayValue)(predefinedValue),
          value: (0, _setters.setJSONArrayValue)(value)
        }))
      );
    };

    Main.displayName = 'CheckboxMultiple';
    var _default = Main;
    exports.default = _default;
    //# sourceMappingURL=CheckboxMultiple.es.js.map
  }
});
//# sourceMappingURL=CheckboxMultiple.es.js.map