'use strict';

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

const __chunk_1 = require('./materials-f431cf7d.js');

/**
 * thanks to  https://github.com/andregoncalves/stencil-timepicker/
 */
class Timepicker {
    constructor(hostRef) {
        __chunk_1.registerInstance(this, hostRef);
        this.step = 15;
        this.clock24 = true;
        this.timeSelectedChange = __chunk_1.createEvent(this, "timeSelectedChange", 7);
    }
    _getOptions() {
        const start = 0;
        const total = Math.round((60 / this.step) * 24);
        const hours = [];
        for (let i = start; i < total; i++) {
            hours.push(i * this.step);
        }
        return hours;
    }
    _format(h, m) {
        let indicator = '';
        if (!this.clock24 && h >= 12) {
            indicator = 'PM';
            h = h - 12;
        }
        else {
            if (!this.clock24 && h < 12) {
                indicator = 'AM';
            }
        }
        if (!this.clock24 && h === 0) {
            h = 12;
        }
        if (h < 10) {
            h = `0${h}`;
        }
        if (m < 10) {
            m = `0${m}`;
        }
        if (indicator)
            m = m + ` ${indicator}`;
        return `${h}:${m}`;
    }
    _renderOption(m) {
        const base = new Date(0);
        base.setMinutes(m);
        const hours = base.getUTCHours();
        const minutes = base.getUTCMinutes();
        const formatted = this._format(hours, minutes);
        if (this.timeSelected === formatted)
            return __chunk_1.h("materials-list-item", { selected: true, onClick: () => this.timeSelectedChange.emit(formatted) }, formatted);
        else
            return __chunk_1.h("materials-list-item", { onClick: () => this.timeSelectedChange.emit(formatted) }, formatted);
    }
    render() {
        return this._getOptions().map(e => this._renderOption(e));
    }
}

exports.materials_timepicker = Timepicker;
