import "preact/debug";
import { Component, Fragment, h } from 'preact';
import strftime from 'strftime';
/** @jsx h */
/** @jsxFrag Fragment */

export class Config {
    static getBrowserTimezoneOffset() {
        return - new Date().getTimezoneOffset();
    }

    getDateFormatter() {
        let strftime_with_offset = strftime.timezone(this.timezoneOffset);
        if (this.time.locale != null) {
            return strftime_with_offset.localizeByIdentifier(props.locale);
        } else {
            this.state = { formatTime: strftime_with_offset }
        }
    }

    constructor() {
        this.time = {
            locale: null,
            timezoneOffset: this.constructor.getBrowserTimezoneOffset(),
            defaultDate: {
                type: "current",
                format: "%Y-%m-%d %H:%M"
            },
        }
    }

    getDefaultDate() {
        if (this.time.defaultDate.type == "current")
            return strftime(this.time.defaultDate.format, new Date())
        else
            return ""
    }
}

export class ConfigView extends Component {
    constructor(props) {
        super(props);
        this.configRef = props.config;
    }

    render() {
        return <a class="a-button" onClick={e => alert("not supported now")}>conf</a>
    }
}
