"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var antd_1 = require("antd");
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1(props) {
        var _this = _super.call(this, props) || this;
        _this.opend = false;
        _this.format = 'YYYY-MM-DD';
        _this.state = {
            endOpen: false,
        };
        if (_this.props.showTime) {
            _this.format = 'YYYY-MM-DD HH:mm:ss';
        }
        return _this;
    }
    default_1.prototype.disabledStartDate = function (date) {
        if (this.props.end) {
            return date.valueOf() > this.props.end.valueOf();
        }
        return false;
    };
    default_1.prototype.disabledEndDate = function (date) {
        if (this.props.start) {
            return date.valueOf() <= this.props.start.valueOf();
        }
        return false;
    };
    default_1.prototype.onStartChange = function (date) {
        this.props.onChange(date, this.props.end);
    };
    default_1.prototype.onEndChange = function (date) {
        this.props.onChange(this.props.start, date);
    };
    default_1.prototype.handleStartOpenChange = function (open) {
        if (!open) {
            this.setState({ endOpen: true });
        }
        else {
            if (!this.opend) {
                this.opend = true;
            }
        }
    };
    default_1.prototype.handleEndOpenChange = function (open) {
        this.setState({ endOpen: open });
        if (!open) {
            this.opend = false;
        }
    };
    default_1.prototype.render = function () {
        var _this = this;
        return React.createElement(React.Fragment, null,
            React.createElement(antd_1.DatePicker, { className: "date-range-start", value: this.props.start, allowClear: this.props.allowClear, disabledDate: function (val) { return _this.disabledStartDate(val); }, showTime: this.props.showTime, format: this.format, placeholder: this.props.showTime ? '开始时间' : '开始日期', onChange: function (val) { return _this.onStartChange(val); }, onOpenChange: function (open) { return _this.handleStartOpenChange(open); }, size: "default", style: { borderRight: 'none' } }),
            React.createElement(antd_1.DatePicker, { className: "date-range-end", value: this.props.end, allowClear: this.props.allowClear, disabledDate: function (val) { return _this.disabledEndDate(val); }, showTime: this.props.showTime, format: this.format, placeholder: this.props.showTime ? '结束时间' : '结束日期', onChange: function (val) { return _this.onEndChange(val); }, open: this.state.endOpen, onOpenChange: function (open) { return _this.handleEndOpenChange(open); }, size: "default", style: { borderLeft: 'none' } }));
    };
    return default_1;
}(React.PureComponent));
exports.default = default_1;
