import React, { useEffect, useState } from 'react';
import classnames from 'classnames';
import TimePanel from './time-panel';
var defaultProps = {
    prefixCls: 'ty-time-picker',
    defaultValue: new Date(),
};
var TimePicker = function (props) {
    var onChange = props.onChange, prefixCls = props.prefixCls, className = props.className, style = props.style;
    var cls = classnames(prefixCls, className);
    var _a = useState(props.value ? props.value : props.defaultValue), date = _a[0], setDate = _a[1];
    var updateTime = function (type, num) {
        if (type === 'h') {
            date.setHours(num);
        }
        else if (type === 'm') {
            date.setMinutes(num);
        }
        else if (type === 's') {
            date.setSeconds(num);
        }
        setDate(date);
        !props.value && onChange && onChange(date);
    };
    useEffect(function () {
        props.value && setDate(props.value);
    });
    return (React.createElement("div", { className: cls, style: style },
        React.createElement(TimePanel, { value: date.getHours(), count: 24, onChange: function (hour) { return updateTime('h', hour); } }),
        React.createElement(TimePanel, { value: date.getMinutes(), count: 60, onChange: function (min) { return updateTime('m', min); } }),
        React.createElement(TimePanel, { value: date.getSeconds(), count: 60, onChange: function (sec) { return updateTime('s', sec); } })));
};
TimePicker.defaultProps = defaultProps;
export default TimePicker;
//# sourceMappingURL=index.js.map