import { __assign, __read } from "tslib";
import weui from '../../../utils/weui';
export function timePicker(options) {
    var start = options.start, end = options.end, defaultTime = options.defaultTime;
    // start time
    var _a = __read((start || '00:00').split(':'), 2), startHour = _a[0], startMin = _a[1];
    var startTime = parseInt(startHour) * 60 + parseInt(startMin);
    // end time
    var _b = __read((end || '23:59').split(':'), 2), endHour = _b[0], endMin = _b[1];
    var endTime = parseInt(endHour) * 60 + parseInt(endMin);
    if (startTime > endTime) {
        throw 'startTime is bigger then endTime';
    }
    // init time
    var nowTime = new Date();
    var _c = __read((defaultTime || nowTime.getHours() + ":" + nowTime.getMinutes()).split(':'), 2), initHour = _c[0], initMin = _c[1];
    var initTime = parseInt(initHour) * 60 + parseInt(initMin);
    var fixInitTime = Math.max(startTime, Math.min(endTime, initTime));
    var fixInitHour = parseInt(fixInitTime / 60);
    var fixInitMin = parseInt(fixInitTime % 60);
    var hours = [];
    for (var hour = 0; hour < 24; hour++) {
        var mins = [];
        for (var min = 0; min < 60; min++) {
            var now = hour * 60 + min;
            if (now >= startTime && now <= endTime) {
                mins.push({
                    value: min < 10 ? "0" + min : "" + min,
                    label: min < 10 ? "0" + min : "" + min,
                });
            }
        }
        if (mins.length > 0) {
            hours.push({
                value: hour < 10 ? "0" + hour : "" + hour,
                label: hour < 10 ? "0" + hour : "" + hour,
                children: mins,
            });
        }
    }
    var defaultValue = [
        fixInitHour < 10 ? "0" + fixInitHour : "" + fixInitHour,
        fixInitMin < 10 ? "0" + fixInitMin : "" + fixInitMin,
    ];
    weui.picker(hours, __assign(__assign({}, options), { start: [startHour, startMin], end: [endHour, endMin], defaultValue: defaultValue }));
}
//# sourceMappingURL=time.js.map