import { VerdocsEndpoint } from "@verdocs/js-sdk";
import { h, Host } from "@stencil/core";
import { unicodeNBSP } from "../../../utils/Icons";
/**
 * Displays a file picker to upload an attachment. This component is just the picker - the host application or component should
 * provide the actual upload functionality.
 *
 * ```ts
 * <verdocs-file-chooser onFileSelected={(e) => console.log('File Selected', e.detail)} />
 * ```
 */
export class VerdocsFileChooser {
    constructor() {
        /**
         * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
         */
        this.endpoint = VerdocsEndpoint.getDefault();
    }
    handleFileChanged(e) {
        var _a, _b;
        this.file = ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0]) || null;
        (_b = this.fileSelected) === null || _b === void 0 ? void 0 : _b.emit({ file: this.file });
        console.debug('[CHOOSER] Selected file', this.file);
    }
    handleSelectFile(e) {
        var _a, _b;
        e.stopPropagation();
        this.file = null;
        (_a = this.fileSelected) === null || _a === void 0 ? void 0 : _a.emit({ file: null });
        (_b = document.getElementById('verdocs-file-chooser')) === null || _b === void 0 ? void 0 : _b.click();
    }
    render() {
        const buttonlabel = this.file ? 'Select a different file' : 'Select a file from your computer';
        return (h(Host, { key: '9bbcded830636b89e0b47dd545c15117c5b9f8b8' }, h("input", { key: '0d8fb69380eb9391ad2e704e07abf29483ed7a01', type: "file", multiple: true, id: "verdocs-file-chooser", accept: "application/pdf,.pdf,.doc,.docx,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document", style: { display: 'none' }, onChange: e => this.handleFileChanged(e) }), h("div", { key: 'ac5d2a127e5653ed80effd71e7d5b41024b931a7', class: "upload-box" }, h("div", { key: 'bfe87d0804272452b31461e4eb714e9336157394', class: "selected-filename" }, this.file ? this.file.name : 'Drag a file here'), h("div", { key: '0999c21ef1c212435cbabd7eca81f8a7463055fe', class: "or-prefer" }, this.file ? unicodeNBSP : 'Or, if you prefer...'), h("verdocs-button", { key: 'd0b299a80d0cede99f92b06ab512053de0441011', label: buttonlabel, size: "small", onClick: e => this.handleSelectFile(e) }))));
    }
    static get is() { return "verdocs-file-chooser"; }
    static get originalStyleUrls() {
        return {
            "$": ["verdocs-file-chooser.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["verdocs-file-chooser.css"]
        };
    }
    static get properties() {
        return {
            "endpoint": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "VerdocsEndpoint",
                    "resolved": "VerdocsEndpoint",
                    "references": {
                        "VerdocsEndpoint": {
                            "location": "import",
                            "path": "@verdocs/js-sdk",
                            "id": "node_modules::VerdocsEndpoint"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": "The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used."
                },
                "getter": false,
                "setter": false,
                "defaultValue": "VerdocsEndpoint.getDefault()"
            }
        };
    }
    static get states() {
        return {
            "file": {}
        };
    }
    static get events() {
        return [{
                "method": "fileSelected",
                "name": "fileSelected",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": "Event fired when a file has been selected. Note that the file may be null if the user is choosing a different file.\nHost applications should use this event to enable/disable buttons to upload or otherwise process the selected file."
                },
                "complexType": {
                    "original": "{file: File | null}",
                    "resolved": "{ file: File; }",
                    "references": {
                        "File": {
                            "location": "global",
                            "id": "global::File"
                        }
                    }
                }
            }];
    }
}
//# sourceMappingURL=verdocs-file-chooser.js.map
