'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _hover = require('../../../../_hoc/hover');

var _hover2 = _interopRequireDefault(_hover);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var Cell = function Cell(props) {
    var isDisabled = props.isDisabled,
        format = props.format,
        cellValue = props.cellValue,
        onChange = props.onChange;


    var layoutStyle = {
        display: 'inline-block',
        boxSizing: 'border-box',
        verticalAlign: 'top',
        width: 100 / 7 + '%',
        padding: '4px 0',
        background: 'transparent',
        textAlign: 'center'
    };

    return _react2.default.createElement(
        'span',
        {
            className: 'day-cell-outter',
            title: cellValue.format(format),
            style: layoutStyle,
            onClick: isDisabled ? null : function () {
                onChange(cellValue);
            }
        },
        _react2.default.createElement(
            'div',
            {
                style: applyStyle(props),
                className: 'day-cell'
            },
            cellValue.date(),
            ' '
        )
    );
};

Cell.propTypes = {
    widgetValue: _react.PropTypes.instanceOf(_moment2.default),
    shadowValue: _react.PropTypes.instanceOf(_moment2.default),
    cellValue: _react.PropTypes.instanceOf(_moment2.default).isRequired,
    onChange: _react.PropTypes.func.isRequired,
    format: _react.PropTypes.string,
    isDisabled: _react.PropTypes.bool
};

exports.default = (0, _hover2.default)(Cell);


function applyStyle(_ref) {
    var style = _ref.style,
        cellValue = _ref.cellValue,
        shadowValue = _ref.shadowValue,
        isHovered = _ref.isHovered,
        isDisabled = _ref.isDisabled,
        widgetValue = _ref.widgetValue;

    var shadowSelectedDay = style.shadowSelectedDay,
        selectedDay = style.selectedDay,
        todayStyle = style.today,
        prevMonthCell = style.prevMonthCell,
        nextMonthCell = style.nextMonthCell,
        disabledStyle = style.disabled,
        _style$Hover = style[':hover'],
        selectedDayHover = _style$Hover.selectedDay,
        disabledHover = _style$Hover.disabled,
        restHoverStyle = _objectWithoutProperties(_style$Hover, ['selectedDay', 'disabled']),
        restStyle = _objectWithoutProperties(style, ['shadowSelectedDay', 'selectedDay', 'today', 'prevMonthCell', 'nextMonthCell', 'disabled', ':hover']);

    var today = (0, _moment2.default)().locale(shadowValue.locale()).utcOffset(shadowValue.utcOffset());

    var isShadowValue = cellValue.isSame(shadowValue, 'day');
    var isCellFromPrevMonth = cellValue.isBefore(shadowValue, 'month');
    var isCellFromNextMonth = cellValue.isAfter(shadowValue, 'month');
    var isToday = cellValue.isSame(today, 'day');
    var isWidgetValue = cellValue.isSame(widgetValue, 'day');

    var hoverStyle = _extends({}, restHoverStyle, isWidgetValue ? selectedDayHover : {}, isDisabled ? disabledHover : {});

    return _extends({
        textAlign: 'center',
        boxSizing: 'border-box',
        display: 'block',
        padding: 0
    }, restStyle, isToday ? todayStyle : {}, isCellFromPrevMonth ? prevMonthCell : {}, isCellFromNextMonth ? nextMonthCell : {}, isHovered ? hoverStyle : {}, isDisabled ? disabledStyle : {}, isShadowValue ? shadowSelectedDay : {}, isWidgetValue ? selectedDay : {});
}
//# sourceMappingURL=DayCell.js.map