Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/filter/CustomTimeRangeForm.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/icon', 'frontend-js-react-web$react', 'portal-workflow-metrics-web$react-text-mask', '../../shared/components/filter/util/filterEvents.es', '../../shared/util/date.es', '../../shared/util/lang.es', './hooks/useCustomTimeRange.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.CustomTimeRangeForm = void 0;

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

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

    var _reactTextMask = _interopRequireDefault(require("portal-workflow-metrics-web$react-text-mask"));

    var _filterEvents = require("../../shared/components/filter/util/filterEvents.es");

    var _date = require("../../shared/util/date.es");

    var _lang = require("../../shared/util/lang.es");

    var _useCustomTimeRange2 = require("./hooks/useCustomTimeRange.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 };
    }

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * The contents of this file are subject to the terms of the Liferay Enterprise
     * Subscription License ("License"). You may not use this file except in
     * compliance with the License. You can obtain a copy of the License by
     * contacting Liferay, Inc. See the License for the specific language governing
     * permissions and limitations under the License, including but not limited to
     * distribution rights of the Software.
     */
    var CustomTimeRangeForm = function CustomTimeRangeForm(_ref) {
      var handleSelectFilter = _ref.handleSelectFilter,
          items = _ref.items,
          _ref$prefixKey = _ref.prefixKey,
          prefixKey = _ref$prefixKey === void 0 ? '' : _ref$prefixKey,
          setFormVisible = _ref.setFormVisible,
          withoutRouteParams = _ref.withoutRouteParams;

      var _useCustomTimeRange = (0, _useCustomTimeRange2.useCustomTimeRange)(prefixKey, withoutRouteParams),
          applyCustomFilter = _useCustomTimeRange.applyCustomFilter,
          dateEnd = _useCustomTimeRange.dateEnd,
          dateFormat = _useCustomTimeRange.dateFormat,
          dateStart = _useCustomTimeRange.dateStart,
          _useCustomTimeRange$e = _useCustomTimeRange.errors,
          errors = _useCustomTimeRange$e === void 0 ? {} : _useCustomTimeRange$e,
          setDateEnd = _useCustomTimeRange.setDateEnd,
          setDateStart = _useCustomTimeRange.setDateStart,
          validate = _useCustomTimeRange.validate;

      var wrapperRef = (0, _react.useRef)();
      var dateMask = (0, _date.getMaskByDateFormat)(dateFormat);

      var activeCustomFilter = function activeCustomFilter() {
        items.forEach(function (item) {
          item.active = item.key === 'custom';
        });
      };

      var onBlur = function onBlur(_ref2) {
        var _ref2$target = _ref2.target,
            name = _ref2$target.name,
            value = _ref2$target.value;
        validate(name, value);
      };

      var onChange = function onChange(setter) {
        return function (_ref3) {
          var value = _ref3.target.value;
          setter(value);
        };
      };

      (0, _react.useEffect)(function () {
        var onClickOutside = (0, _filterEvents.handleClickOutside)(function () {
          setFormVisible(false);
        }, wrapperRef.current);
        (0, _filterEvents.addClickOutsideListener)(onClickOutside);
        return function () {
          return (0, _filterEvents.removeClickOutsideListener)(onClickOutside);
        };
      }, [setFormVisible]);
      return _react["default"].createElement("div", {
        className: "custom-range-wrapper",
        ref: wrapperRef
      }, _react["default"].createElement("form", {
        className: "custom-range-form"
      }, _react["default"].createElement("h4", {
        className: "mb-2"
      }, Liferay.Language.get('custom-range')), _react["default"].createElement("span", {
        className: "form-text mb-3 text-semi-bold"
      }, (0, _lang.sub)(Liferay.Language.get('default-date-format-is-x'), [dateFormat])), _react["default"].createElement("div", {
        className: "form-group-autofit"
      }, _react["default"].createElement(FormGroupItem, {
        error: errors['dateStart']
      }, _react["default"].createElement("label", {
        htmlFor: "dateStart"
      }, Liferay.Language.get('from')), _react["default"].createElement(_reactTextMask["default"], {
        className: "form-control",
        defaultValue: dateStart,
        mask: dateMask,
        name: "dateStart",
        onBlur: onBlur,
        onChange: onChange(setDateStart),
        placeholder: dateFormat
      })), _react["default"].createElement(FormGroupItem, {
        error: errors['dateEnd']
      }, _react["default"].createElement("label", {
        htmlFor: "dateEnd"
      }, Liferay.Language.get('to')), _react["default"].createElement(_reactTextMask["default"], {
        className: "form-control",
        defaultValue: dateEnd,
        mask: dateMask,
        name: "dateEnd",
        onBlur: onBlur,
        onChange: onChange(setDateEnd),
        placeholder: dateFormat
      })))), _react["default"].createElement("div", {
        className: "dropdown-divider"
      }), _react["default"].createElement("div", {
        className: "custom-range-footer"
      }, _react["default"].createElement("button", {
        className: "btn btn-secondary",
        onMouseDown: function onCancel() {
          setFormVisible(false);
        }
      }, Liferay.Language.get('cancel')), _react["default"].createElement("button", {
        className: "btn btn-primary ml-3",
        onClick: function onApply() {
          var _ref4 = errors || {},
              dateEndError = _ref4.dateEnd,
              dateStartError = _ref4.dateStart;

          if (!dateEndError && !dateStartError) {
            activeCustomFilter();
            applyCustomFilter(handleSelectFilter);
            setFormVisible(false);
          }
        }
      }, Liferay.Language.get('apply'))));
    };

    exports.CustomTimeRangeForm = CustomTimeRangeForm;

    var FormGroupItem = function FormGroupItem(_ref5) {
      var children = _ref5.children,
          error = _ref5.error;
      return _react["default"].createElement("div", {
        className: "form-group-item ".concat(error ? 'has-error' : '')
      }, _react["default"].createElement("div", {
        className: "input-group"
      }, _react["default"].createElement("div", {
        className: "input-group-item"
      }, children)), error && _react["default"].createElement("div", {
        className: "form-feedback-group"
      }, _react["default"].createElement("div", {
        className: "form-feedback-item"
      }, _react["default"].createElement("span", {
        className: "form-feedback-indicator mr-2"
      }, _react["default"].createElement(_icon["default"], {
        symbol: "exclamation-full"
      })), _react["default"].createElement("span", {
        className: "text-semi-bold"
      }, error))));
    };
    //# sourceMappingURL=CustomTimeRangeForm.es.js.map
  }
});
//# sourceMappingURL=CustomTimeRangeForm.es.js.map