"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _CalendarPanelSt = require("./CalendarPanel.st.css.js");
var _DropdownLayout = _interopRequireDefault(require("../DropdownLayout"));
var _Calendar = _interopRequireDefault(require("../Calendar"));
var _DropdownLayout2 = require("../DropdownLayout/DropdownLayout.constants");
var _designSystemsLocaleUtils = require("@wix/design-systems-locale-utils");
var _excluded = ["dataHook", "presets", "footer"];
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/CalendarPanel/CalendarPanel.jsx";
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var CalendarPanel = /*#__PURE__*/function (_React$Component) {
  function CalendarPanel() {
    var _this;
    (0, _classCallCheck2["default"])(this, CalendarPanel);
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _callSuper(this, CalendarPanel, [].concat(args));
    _this.onSelectPreset = function (preset) {
      var onChange = _this.props.onChange;
      onChange(preset.selectedDays);
    };
    return _this;
  }
  (0, _inherits2["default"])(CalendarPanel, _React$Component);
  return (0, _createClass2["default"])(CalendarPanel, [{
    key: "getSelectedPresetId",
    value: function getSelectedPresetId() {
      var _this$props = this.props,
        _this$props$presets = _this$props.presets,
        presets = _this$props$presets === void 0 ? [] : _this$props$presets,
        value = _this$props.value;
      var selectedPreset = presets.find(function (preset) {
        return _Calendar["default"].areValuesEqual(preset.selectedDays, value);
      });
      return selectedPreset ? selectedPreset.id : -1;
    }
  }, {
    key: "isSubmitDisabled",
    value: function isSubmitDisabled() {
      var _this$props2 = this.props,
        selectionMode = _this$props2.selectionMode,
        value = _this$props2.value;
      if (selectionMode === 'range') {
        return !Boolean(value) || !Boolean(value.from) || !Boolean(value.to);
      }
      return !Boolean(value);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props3 = this.props,
        dataHook = _this$props3.dataHook,
        presets = _this$props3.presets,
        footer = _this$props3.footer,
        calendarProps = (0, _objectWithoutProperties2["default"])(_this$props3, _excluded);
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: _CalendarPanelSt.classes.root,
        "data-hook": dataHook,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 38,
          columnNumber: 7
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: _CalendarPanelSt.classes.calendarWithPresets,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 39,
          columnNumber: 9
        }
      }, Boolean(presets && presets.length) && /*#__PURE__*/_react["default"].createElement("div", {
        className: _CalendarPanelSt.classes.presets,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 41,
          columnNumber: 13
        }
      }, /*#__PURE__*/_react["default"].createElement(_DropdownLayout["default"], {
        visible: true,
        inContainer: true,
        onSelect: this.onSelectPreset,
        dataHook: "dropdown-layout",
        options: presets,
        maxHeightPixels: 342,
        selectedId: this.getSelectedPresetId(),
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 42,
          columnNumber: 15
        }
      })), /*#__PURE__*/_react["default"].createElement(_Calendar["default"], (0, _extends2["default"])({}, calendarProps, {
        dataHook: "calendar",
        className: _CalendarPanelSt.classes.calendar,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 53,
          columnNumber: 11
        }
      }))), footer && /*#__PURE__*/_react["default"].createElement("div", {
        className: _CalendarPanelSt.classes.footer,
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 60,
          columnNumber: 11
        }
      }, footer({
        selectedDays: calendarProps.value,
        submitDisabled: this.isSubmitDisabled()
      })));
    }
  }]);
}(_react["default"].Component);
CalendarPanel.displayName = 'CalendarPanel';
CalendarPanel.defaultProps = {
  numOfMonths: 2
};
var _default = exports["default"] = CalendarPanel;