'use strict';

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

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _defineProperty2 = require('babel-runtime/helpers/defineProperty');

var _defineProperty3 = _interopRequireDefault(_defineProperty2);

exports["default"] = wrapPicker;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _Panel = require('rc-time-picker/lib/Panel');

var _Panel2 = _interopRequireDefault(_Panel);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _zh_CN = require('./locale/zh_CN');

var _zh_CN2 = _interopRequireDefault(_zh_CN);

var _objectAssign = require('object-assign');

var _objectAssign2 = _interopRequireDefault(_objectAssign);

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

function wrapPicker(Picker, defaultFormat) {
    var PickerWrapper = _react2["default"].createClass({
        displayName: 'PickerWrapper',
        getDefaultProps: function getDefaultProps() {
            return {
                format: defaultFormat || 'YYYY-MM-DD',
                transitionName: 'slide-up',
                popupStyle: {},
                onChange: function onChange() {},
                onOk: function onOk() {},
                toggleOpen: function toggleOpen() {},

                locale: {},
                align: {
                    offset: [0, -9]
                },
                prefixCls: 'ant-calendar',
                inputPrefixCls: 'ant-input'
            };
        },

        contextTypes: {
            antLocale: _react.PropTypes.object
        },
        getLocale: function getLocale() {
            var props = this.props;
            var context = this.context;
            var locale = _zh_CN2["default"];
            if (context.antLocale && context.antLocale.DatePicker) {
                locale = context.antLocale.DatePicker;
            }
            // 统一合并为完整的 Locale
            var result = (0, _objectAssign2["default"])({}, locale, props.locale);
            result.lang = (0, _objectAssign2["default"])({}, locale.lang, props.locale.lang);
            return result;
        },
        toggleOpen: function toggleOpen(_ref) {
            var open = _ref.open;

            this.props.toggleOpen({ open: open });
        },
        render: function render() {
            var _classNames2;

            var props = this.props;
            var prefixCls = props.prefixCls;
            var inputPrefixCls = props.inputPrefixCls;

            var pickerClass = (0, _classnames2["default"])((0, _defineProperty3["default"])({}, prefixCls + '-picker', true));
            var pickerInputClass = (0, _classnames2["default"])((_classNames2 = {}, (0, _defineProperty3["default"])(_classNames2, prefixCls + '-range-picker', true), (0, _defineProperty3["default"])(_classNames2, inputPrefixCls, true), (0, _defineProperty3["default"])(_classNames2, inputPrefixCls + '-lg', props.size === 'large'), (0, _defineProperty3["default"])(_classNames2, inputPrefixCls + '-sm', props.size === 'small'), _classNames2));
            var locale = this.getLocale();
            var timeFormat = props.showTime && props.showTime.format;
            var rcTimePickerProps = {
                format: timeFormat || 'HH:mm:ss',
                showSecond: timeFormat && timeFormat.indexOf('ss') >= 0,
                showHour: timeFormat && timeFormat.indexOf('HH') >= 0
            };
            var timePicker = props.showTime ? _react2["default"].createElement(_Panel2["default"], (0, _extends3["default"])({}, rcTimePickerProps, props.showTime, { prefixCls: prefixCls + '-time-picker', placeholder: locale.timePickerLocale.placeholder, transitionName: 'slide-up' })) : null;
            return _react2["default"].createElement(Picker, (0, _extends3["default"])({}, props, { pickerClass: pickerClass, pickerInputClass: pickerInputClass, locale: locale, timePicker: timePicker, toggleOpen: this.toggleOpen }));
        }
    });
    return PickerWrapper;
}
module.exports = exports['default'];