Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/sla/form-page/sections/DurationSection.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/layout', 'frontend-js-react-web$react', 'portal-workflow-metrics-web$react-text-mask', 'portal-workflow-metrics-web$text-mask-addons/dist/createNumberMask', '../../../../shared/components/form/FieldLabel.es', '../../../../shared/components/form/FormGroupWithStatus.es', '../SLAFormConstants.es', '../SLAFormPageProvider.es', '../util/slaFormUtil.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.DurationSection = void 0;

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

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

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

    var _createNumberMask = _interopRequireDefault(require("portal-workflow-metrics-web$text-mask-addons/dist/createNumberMask"));

    var _FieldLabel = _interopRequireDefault(require("../../../../shared/components/form/FieldLabel.es"));

    var _FormGroupWithStatus = _interopRequireDefault(require("../../../../shared/components/form/FormGroupWithStatus.es"));

    var _SLAFormConstants = require("../SLAFormConstants.es");

    var _SLAFormPageProvider = require("../SLAFormPageProvider.es");

    var _slaFormUtil = require("../util/slaFormUtil.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 ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var DurationSection = function DurationSection(_ref) {
      var onChangeHandler = _ref.onChangeHandler;

      var _useContext = (0, _react.useContext)(_SLAFormPageProvider.SLAFormContext),
          calendars = _useContext.calendars,
          defaultCalendar = _useContext.defaultCalendar,
          errors = _useContext.errors,
          setErrors = _useContext.setErrors,
          _useContext$sla = _useContext.sla,
          _useContext$sla$calen = _useContext$sla.calendarKey,
          calendarKey = _useContext$sla$calen === void 0 ? defaultCalendar.key : _useContext$sla$calen,
          days = _useContext$sla.days,
          hours = _useContext$sla.hours;

      var daysMask = (0, _react.useMemo)(function () {
        return (0, _createNumberMask["default"])({
          allowLeadingZeroes: true,
          includeThousandsSeparator: false,
          integerLimit: 4,
          prefix: ''
        });
      }, []);
      var onDurationChanged = (0, _react.useCallback)(function (newDays) {
        var _objectSpread2;

        setErrors(_objectSpread({}, errors, (_objectSpread2 = {}, _defineProperty(_objectSpread2, _SLAFormConstants.ALERT_MESSAGE, ''), _defineProperty(_objectSpread2, _SLAFormConstants.DURATION, (0, _slaFormUtil.validateDuration)(newDays, hours)), _defineProperty(_objectSpread2, _SLAFormConstants.HOURS, ''), _objectSpread2)));
      }, [errors, hours, setErrors]);
      var onHoursBlurred = (0, _react.useCallback)(function () {
        if (days && Number(days) > 0 && (!hours || hours === '00:00')) {
          var _objectSpread3;

          setErrors(_objectSpread({}, errors, (_objectSpread3 = {}, _defineProperty(_objectSpread3, _SLAFormConstants.ALERT_MESSAGE, ''), _defineProperty(_objectSpread3, _SLAFormConstants.HOURS, ''), _objectSpread3)));
        } else {
          var _objectSpread4;

          var newErrors = _objectSpread({}, errors, (_objectSpread4 = {}, _defineProperty(_objectSpread4, _SLAFormConstants.ALERT_MESSAGE, ''), _defineProperty(_objectSpread4, _SLAFormConstants.HOURS, (0, _slaFormUtil.validateHours)(hours)), _objectSpread4));

          if (hours && hours === '00:00') {
            newErrors[_SLAFormConstants.HOURS] = Liferay.Language.get('value-must-be-an-hour-below');
          }

          if (errors[_SLAFormConstants.HOURS] !== newErrors[_SLAFormConstants.HOURS]) {
            setErrors(newErrors);
          }
        }
      }, [days, errors, hours, setErrors]);
      return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement("h3", {
        className: "sheet-subtitle"
      }, _react["default"].createElement(_FieldLabel["default"], {
        required: true,
        text: Liferay.Language.get('duration').toUpperCase()
      })), _react["default"].createElement("div", {
        className: "sheet-text"
      }, calendars.length > 1 ? Liferay.Language.get('define-the-sla-duration-and-calendar-format') : Liferay.Language.get('define-the-sla-duration')), _react["default"].createElement(_layout["default"].Row, null, _react["default"].createElement(_layout["default"].Col, {
        sm: "3"
      }, _react["default"].createElement(_FormGroupWithStatus["default"], {
        className: "form-group",
        description: Liferay.Language.get('enter-a-whole-number'),
        error: errors[_SLAFormConstants.DURATION],
        htmlFor: "slaDurationDays",
        label: Liferay.Language.get('days')
      }, _react["default"].createElement(_reactTextMask["default"], {
        className: "form-control",
        id: "slaDurationDays",
        mask: daysMask,
        maxLength: 4,
        name: _SLAFormConstants.DAYS,
        onChange: onChangeHandler(onDurationChanged),
        value: days
      }))), _react["default"].createElement(_layout["default"].Col, {
        sm: "3"
      }, _react["default"].createElement(_FormGroupWithStatus["default"], {
        className: "form-group",
        error: errors[_SLAFormConstants.DURATION] || errors[_SLAFormConstants.HOURS],
        htmlFor: "slaDurationHours",
        label: Liferay.Language.get('hours')
      }, _react["default"].createElement(_reactTextMask["default"], {
        className: "form-control",
        id: "slaDurationHours",
        mask: [/\d/, /\d/, ':', /\d/, /\d/],
        name: _SLAFormConstants.HOURS,
        onBlur: onHoursBlurred,
        onChange: onChangeHandler(onDurationChanged),
        placeholder: "00:00",
        value: hours
      }))), calendars.length > 1 && _react["default"].createElement(_layout["default"].Col, {
        sm: "6"
      }, _react["default"].createElement(_FormGroupWithStatus["default"], {
        className: "form-group",
        htmlFor: "slaCalendarKey",
        label: Liferay.Language.get('calendar')
      }, _react["default"].createElement("select", {
        className: "form-control",
        id: "slaCalendarKey",
        name: _SLAFormConstants.CALENDAR_KEY,
        onChange: onChangeHandler(),
        value: calendarKey
      }, calendars.map(function (calendar, index) {
        return _react["default"].createElement("option", {
          key: index,
          value: calendar.key
        }, calendar.title, ' ', calendar.defaultCalendar && "(".concat(Liferay.Language.get('system-default'), ")"));
      }))))));
    };

    exports.DurationSection = DurationSection;
    //# sourceMappingURL=DurationSection.es.js.map
  }
});
//# sourceMappingURL=DurationSection.es.js.map