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: '467efdebf394aca2734bce2755e10b84638fe5a4', class: `input-field` }, h("label", { key: '8dc6200b52f0d97f7360c3856056eb5d85c6d299' }, this.label && (h("div", { key: '006018a6ec21a7780b78686feecf09f50357a871', class: "input-label" }, this.label + ':', this.required && h("span", { key: '44882599b166ed99a3f3abb3276f03cf7c3702cc', class: "required" }, "*"))), h("div", { key: '390990d7c2e9132949e7af69fcd464f95b275b21', class: "input-container" }, h("input", { key: '4324380a6c31b299f0f1ef0081043d8fe404e448', 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: 'ddd928e400e4fe83d0ffb2e6fc34eddff488fad1', 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",
                "attribute": "value",
                "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,
                "defaultValue": "''"
            },
            "label": {
                "type": "string",
                "attribute": "label",
                "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,
                "defaultValue": "''"
            },
            "placeholder": {
                "type": "string",
                "attribute": "placeholder",
                "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,
                "defaultValue": "''"
            },
            "helpText": {
                "type": "string",
                "attribute": "help-text",
                "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,
                "defaultValue": "''"
            },
            "disabled": {
                "type": "boolean",
                "attribute": "disabled",
                "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,
                "defaultValue": "false"
            },
            "required": {
                "type": "boolean",
                "attribute": "required",
                "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,
                "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
