import { UiElement } from "./ui-element";

export class DateTimeInput extends UiElement {
    constructor(
        private label: string,
        private elementId: string,
        private value: any,
        private containerId: string,
        private disabled: string,
        private hidden: string,
        private required: string) {
        super(elementId, containerId, '');
        this.createElement(this.getTemplate());

    }

    formatDate() {
        let date = new Date();
        this.value = date.toISOString().slice(0, 10) + "T" + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
    }
    public getTemplate() {
        let requiredClass: string = "";
        let disaledClass = "";
        //let timeValue=null;
        //let dateValue=null;
        if (this.disabled == "N") { this.disabled = "disabled"; disaledClass = "disabled" } else { this.disabled = ""; disaledClass = "" }
        if (this.hidden == "N") { this.hidden = "display:none;" } else { this.hidden = "" }
        if (this.value == "currentDateTime") {
            this.formatDate();
        }
        if (this.required == 'Y')
            requiredClass = "requiredClass"
        // let arrayDate=val.split(" ");
        //       elem.value = this.common.reverseFormatDate(arrayDate[0]);
        //       elem.setAttribute('value', elem.value);
        //       const timeInput = document.getElementById(this.validateEitObj[i].APPLICATION_COLUMN_NAME+"Time") as HTMLInputElement;
        //       timeInput.value = arrayDate[1];
        //       timeInput.setAttribute('value', timeInput.value);
        // if(this.value){
        //     let arrayDate=this.value.split(" ");
        //     dateValue=arrayDate[0];
        //     timeValue=arrayDate[1];
        // }
        const template =
            "<ion-item>" +
            " <ion-label style='font-size: medium !important;' class='daynamicForm-Label " + requiredClass + "' id='title' >" + this.label + "</ion-label>" +
            // " <div class='daynamicForm-DateTime " + disaledClass + "'  id='" + this.elementId + "' data-dtvalue='" + this.value + "' " + this.disabled + ">" + this.value + "</div>" +
            "<ion-datetime min='1900' max='2100' displayFormat='DD/MM/YYYY' value='" + this.value + "' id='" + this.elementId + "' data-dtvalue='" + this.value + "' " + this.disabled + "></ion-datetime>" +
            // " <input class='daynamicForm-DateTime' type='text' id='" + this.elementId + "' value='" + this.value + "' "+this.disabled+" (click)='showDateTimePicker()'/>"+
            // " <input class='daynamicForm-DateTime' type='date' id='" + this.elementId + "' value='" + dateValue+ "' "+this.disabled+" />"+
            // " <input class='daynamicForm-DateTime' type='time' id='" + this.elementId + "Time' value='" + timeValue + "' "+this.disabled+" />"+
            "</ion-item>"
        return template;
    }

}