import { h, getAssetPath } from '@stencil/core';
export class EclDatepicker {
  constructor() {
    this.theme = 'ec';
    this.styleClass = undefined;
    this.disabled = false;
    this.required = false;
    this.placeholder = 'DD-MM-YYYY';
    this.inputId = undefined;
    this.invalid = false;
    this.type = undefined;
    this.name = undefined;
    this.defaultValue = undefined;
  }
  getClass() {
    const styleClasses = ['ecl-datepicker', this.styleClass];
    if (this.invalid) {
      styleClasses.push('ecl-datepicker--invalid');
    }
    if (this.disabled) {
      styleClasses.push('ecl-datepicker--disabled');
    }
    return styleClasses.join(' ');
  }
  componentDidRender() {
    const momentSrc = 'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js';
    if (document.querySelector(`script[src="${momentSrc}"]`)) {
      document.querySelector(`script[src="${momentSrc}"]`).remove();
    }
    const moment = document.createElement('script');
    moment.setAttribute('integrity', 'sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=');
    moment.setAttribute('crossorigin', 'anonymous');
    moment.src = momentSrc;
    document.body.appendChild(moment);
    const src = getAssetPath('./build/scripts/ecl-datepicker-vanilla.js');
    if (document.querySelector(`script[src="${src}"]`)) {
      document.querySelector(`script[src="${src}"]`).remove();
    }
    const script = document.createElement('script');
    script.src = src;
    script.onload = () => {
      console.log(this.el);
      const datepicker = new ECL.Datepicker(this.el.querySelector('.ecl-datepicker__field'));
      datepicker.init();
    };
    document.body.appendChild(script);
  }
  render() {
    return (h("div", { class: this.getClass() }, h("input", { class: `ecl-datepicker__field ecl-text-input ecl-text-input--s ${this.invalid ? 'ecl-text-input--invalid' : ''}`, autocomplete: "off", "data-ecl-datepicker-toggle": true, id: this.inputId, value: this.defaultValue, required: this.required, disabled: this.disabled, placeholder: this.placeholder }), h("ecl-icon", { "style-class": `ecl-datepicker__icon sc-ecl-datepicker-${this.theme}`, icon: "calendar", size: "s" })));
  }
  static get is() { return "ecl-datepicker"; }
  static get originalStyleUrls() {
    return {
      "ec": ["./build/styles/ecl-datepicker-ec.css"],
      "eu": ["./build/styles/ecl-datepicker-eu.css"]
    };
  }
  static get styleUrls() {
    return {
      "ec": ["./build/styles/ecl-datepicker-ec.css"],
      "eu": ["./build/styles/ecl-datepicker-eu.css"]
    };
  }
  static get properties() {
    return {
      "theme": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "theme",
        "reflect": false,
        "defaultValue": "'ec'"
      },
      "styleClass": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "style-class",
        "reflect": false
      },
      "disabled": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "disabled",
        "reflect": false,
        "defaultValue": "false"
      },
      "required": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "required",
        "reflect": false,
        "defaultValue": "false"
      },
      "placeholder": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "placeholder",
        "reflect": false,
        "defaultValue": "'DD-MM-YYYY'"
      },
      "inputId": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "input-id",
        "reflect": false
      },
      "invalid": {
        "type": "boolean",
        "mutable": false,
        "complexType": {
          "original": "boolean",
          "resolved": "boolean",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "invalid",
        "reflect": false,
        "defaultValue": "false"
      },
      "type": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "type",
        "reflect": false
      },
      "name": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "name",
        "reflect": false
      },
      "defaultValue": {
        "type": "string",
        "mutable": false,
        "complexType": {
          "original": "string",
          "resolved": "string",
          "references": {}
        },
        "required": false,
        "optional": false,
        "docs": {
          "tags": [],
          "text": ""
        },
        "attribute": "default-value",
        "reflect": false
      }
    };
  }
  static get elementRef() { return "el"; }
}
//# sourceMappingURL=ecl-datepicker.js.map
