import AirDatepicker from "air-datepicker";
import { Host, h } from "@stencil/core";
import { VerdocsToast } from "../../../utils/Toast";
import localeEn from "air-datepicker/locale/en";
/**
 * Display a date input field.
 *
 * ```ts
 * <verdocs-date-input type="text" label="DOB" placeholder="Date of Birth..." value="" />
 * ```
 */
export class VerdocsDateInput {
    constructor() {
        this.picker = null;
        /**
         * The initial value for the input field.
         */
        this.value = '';
        /**
         * The label for the field.
         */
        this.label = '';
        /**
         * The placeholder for the field.
         */
        this.placeholder = '';
        /**
         * If supplied, a help icon will be displayed to provide the user more information.
         */
        this.helpText = '';
        /**
         * Should the field be disabled?
         */
        this.disabled = false;
        /**
         * Should the field be required?
         */
        this.required = false;
        this.showingPw = false;
        this.focused = false;
        this.containerId = `verdocs-date-input-${Math.random().toString(36).substring(2, 11)}`;
    }
    async focusField() {
        var _a;
        // Our input field is fake, so we fake the flash too
        this.focused = true;
        (_a = this.picker) === null || _a === void 0 ? void 0 : _a.show();
        setTimeout(() => {
            this.focused = false;
        }, 500);
    }
    componentDidLoad() {
        this.picker = new AirDatepicker(`#${this.containerId}`, {
            locale: localeEn,
            isMobile: true,
            autoClose: true,
            onShow: () => (this.focused = true),
            onHide: () => (this.focused = false),
            onSelect: ({ date, formattedDate }) => {
                const event = new CustomEvent('input', { detail: { date, formattedDate } });
                this.hostEl.dispatchEvent(event);
            },
        });
    }
    copyToClipboard() {
        this.inputEl.select();
        navigator.clipboard
            .writeText(this.value)
            .then(() => VerdocsToast('Copied!'))
            .catch(e => console.log('Error copying to clipboard', e));
    }
    render() {
        return (h(Host, { key: 'a71872f25c3fbfdb8837f546340edd2324f141f9', class: `input-field` }, h("label", { key: '68b0b363d48c045f6a6124467c81e3c8af7f6321' }, this.label && (h("div", { key: '6cfe44246b5776315772da522b27482c362df563', class: "input-label" }, this.label + ':', this.required && h("span", { key: '9c02382715b89aa7c8f1c4efd6e9e1e54cec6692', class: "required" }, "*"))), h("div", { key: '56e31da5bc7c6206a9f1045ad6317f6b95ca2206', class: "input-container" }, h("input", { key: 'bdca818f5c8df445d9e63c6597cc75d0634096f1', type: "text", value: this.value, required: this.required, class: "input-element", "data-lpignore": "true", id: this.containerId, disabled: this.disabled, placeholder: this.placeholder,
            // onBlur={(e: any) => this.blur?.emit(e.target.value)}
            ref: el => (this.inputEl = el), onInput: (e) => (this.value = e.target.value) })), this.helpText && h("verdocs-help-icon", { key: '712354ce917bb818033fa6cd95dc2bf50daf678f', text: this.helpText }))));
    }
    static get is() { return "verdocs-date-input"; }
    static get originalStyleUrls() {
        return {
            "$": ["verdocs-date-input.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["verdocs-date-input.css"]
        };
    }
    static get properties() {
        return {
            "value": {
                "type": "string",
                "mutable": true,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The initial value for the input field."
                },
                "getter": false,
                "setter": false,
                "reflect": true,
                "attribute": "value",
                "defaultValue": "''"
            },
            "label": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The label for the field."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "label",
                "defaultValue": "''"
            },
            "placeholder": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The placeholder for the field."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "placeholder",
                "defaultValue": "''"
            },
            "helpText": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "If supplied, a help icon will be displayed to provide the user more information."
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "help-text",
                "defaultValue": "''"
            },
            "disabled": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Should the field be disabled?"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "disabled",
                "defaultValue": "false"
            },
            "required": {
                "type": "boolean",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "Should the field be required?"
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "required",
                "defaultValue": "false"
            }
        };
    }
    static get states() {
        return {
            "showingPw": {},
            "focused": {},
            "containerId": {}
        };
    }
    static get methods() {
        return {
            "focusField": {
                "complexType": {
                    "signature": "() => Promise<void>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "hostEl"; }
}
//# sourceMappingURL=verdocs-date-input.js.map
