"use strict";

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

var React = _interopRequireWildcard(require("react"));

var _index = require("./index.js");

var _index2 = require("../popover/index.js");

var _index3 = require("../input/index.js");

var _examplesList = _interopRequireDefault(require("./examples-list.js"));

var _tests$SIMPLE_EXAMPLE;

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

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

function _typeof(obj) { 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); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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 suite = 'Component Test Suite';
exports.suite = suite;

var DatepickerWithInput =
/*#__PURE__*/
function (_React$Component) {
  _inherits(DatepickerWithInput, _React$Component);

  function DatepickerWithInput() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, DatepickerWithInput);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(DatepickerWithInput)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
      isOpen: false,
      value: _this.props.value || null,
      formattedValue: ''
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onChange", function (_ref) {
      var date = _ref.date;
      var isOpen = false;

      if (Array.isArray(date) && _this.props.isRange && date.length < 2) {
        isOpen = true;
      }

      _this.setState({
        value: date,
        formattedValue: _this.formatDate(date),
        isOpen: isOpen
      });
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "open", function () {
      _this.setState({
        isOpen: true
      });
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "close", function () {
      _this.setState({
        isOpen: false
      });
    });

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleKeyDown", function (event) {
      if (!_this.state.isOpen && event.keyCode === 40) {
        _this.open();
      }
    });

    return _this;
  }

  _createClass(DatepickerWithInput, [{
    key: "formatDate",
    value: function formatDate(date) {
      if (this.props.isRange) {
        // $FlowFixMe
        return date.map(function (day) {
          return (0, _index.formatDate)(day, 'YYYY/MM/dd');
        }).join(' - ');
      }

      return (0, _index.formatDate)(date, 'YYYY/MM/dd');
    }
  }, {
    key: "render",
    value: function render() {
      return React.createElement(_index2.Popover, {
        placement: _index2.PLACEMENT.bottom,
        isOpen: this.state.isOpen,
        onEsc: this.close,
        content: React.createElement(_index.Unstable_StatefulCalendar, {
          initialState: {
            value: this.state.value
          },
          isRange: this.props.isRange,
          onSelect: this.onChange
        })
      }, React.createElement(_index3.Input, {
        value: this.state.formattedValue,
        onFocus: this.open // onBlur={this.close}
        // Change the on key event types in Input
        // $FlowFixMe
        ,
        onKeyDown: this.handleKeyDown,
        placeholder: "YYYY/MM/DD"
      }));
    }
  }]);

  return DatepickerWithInput;
}(React.Component);

_defineProperty(DatepickerWithInput, "defaultProps", {
  isRange: false,
  value: null
});

var _default = (_tests$SIMPLE_EXAMPLE = {}, _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.SIMPLE_EXAMPLE, function Story1() {
  return React.createElement(_index.Unstable_Calendar, null);
}), _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.STATEFUL_EXAMPLE, function Story2() {
  return React.createElement(_index.Unstable_StatefulCalendar, null);
}), _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.STATEFUL_IN_POPOVER, function Story3() {
  return React.createElement(DatepickerWithInput, null);
}), _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.STATEFUL_RANGE_IN_POPOVER, function Story3() {
  return React.createElement(DatepickerWithInput, {
    isRange: true,
    value: []
  });
}), _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.STATEFUL_RANGE_QUICK_SELECT, function QuickSelect() {
  return React.createElement(_index.Unstable_StatefulCalendar, {
    isRange: true,
    enableQuickSelect: true
  });
}), _defineProperty(_tests$SIMPLE_EXAMPLE, _examplesList.default.WITH_OVERRIDES, function Story3() {
  var selectOverrides = {
    ControlContainer: {
      style: function style(_ref2) {
        var $theme = _ref2.$theme,
            $isFocused = _ref2.$isFocused,
            $isPseudoFocused = _ref2.$isPseudoFocused;
        return {
          backgroundColor: $isFocused || $isPseudoFocused ? $theme.colors.positive500 : $theme.colors.positive
        };
      }
    },
    OptionContent: {
      style: function style(_ref3) {
        var $theme = _ref3.$theme,
            $isHighlighted = _ref3.$isHighlighted;
        return {
          color: $isHighlighted ? $theme.colors.positive : $theme.colors.foreground
        };
      }
    }
  };
  return React.createElement(_index.Unstable_StatefulCalendar, {
    initialState: {
      value: new Date()
    },
    overrides: {
      CalendarHeader: {
        style: function style(_ref4) {
          var $theme = _ref4.$theme;
          return {
            backgroundColor: $theme.colors.positive
          };
        }
      },
      MonthSelect: {
        props: {
          overrides: selectOverrides
        }
      },
      YearSelect: {
        props: {
          overrides: selectOverrides
        }
      },
      Day: {
        style: function style(_ref5) {
          var $theme = _ref5.$theme,
              $selected = _ref5.$selected,
              $isHovered = _ref5.$isHovered,
              $isHighlighted = _ref5.$isHighlighted;
          return {
            backgroundColor: $selected ? $theme.colors.positive : $isHovered || $isHighlighted ? $theme.colors.positive100 : 'transparent'
          };
        }
      }
    }
  });
}), _tests$SIMPLE_EXAMPLE);

exports.default = _default;