import { h } from "@stencil/core";
import { linker } from '../../../utils/input-linker';
export class BceElementDownloadTemplate {
    constructor() {
        this.metadata = {};
        this.text = '';
        this.location = '';
        this.placeholderText = 'File description';
        this.placeholderLocation = 'File URL';
        this._link = linker(this, this.handleInput);
        this._text = this._link('text');
        this._location = this._link('location');
    }
    handleInput(name, event) {
        const input = event.target;
        if (!input)
            return;
        event.cancelBubble = true;
        this[name] = input.value;
        this.value = this.updateValue({ [name]: input.value });
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    updateValue(part = {}) {
        const current = {
            text: this.text,
            location: this.location,
            metadata: Object.assign({}, this.metadata)
        };
        return Object.assign({}, current, part);
    }
    componentDidLoad() {
        this.value = this.updateValue();
        this.el.dispatchEvent(new Event('input', { bubbles: true }));
    }
    render() {
        const buttons = {
            labelUploadButton: this.labelUploadButton,
            labelDeleteButton: this.labelDeleteButton
        };
        return [
            h("bce-input", Object.assign({ type: "text" }, this._text)),
            h("bce-upload-input", Object.assign({}, this._location, buttons))
        ];
    }
    static get is() { return "bce-element-download-template"; }
    static get properties() { return {
        "value": {
            "type": "unknown",
            "mutable": true,
            "complexType": {
                "original": "DownloadTemplate",
                "resolved": "undefined | { readonly text: string; readonly location: string; readonly metadata: ElementMetadata; }",
                "references": {
                    "DownloadTemplate": {
                        "location": "local"
                    }
                }
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            }
        },
        "metadata": {
            "type": "unknown",
            "mutable": false,
            "complexType": {
                "original": "Block.ElementMetadata",
                "resolved": "ElementMetadata",
                "references": {
                    "Block": {
                        "location": "import",
                        "path": "../../../models/block"
                    }
                }
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "defaultValue": "{}"
        },
        "text": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "text",
            "reflect": false,
            "defaultValue": "''"
        },
        "location": {
            "type": "string",
            "mutable": true,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "location",
            "reflect": false,
            "defaultValue": "''"
        },
        "labelUploadButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string | undefined",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-upload-button",
            "reflect": false
        },
        "labelDeleteButton": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string | undefined",
                "references": {}
            },
            "required": false,
            "optional": true,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "label-delete-button",
            "reflect": false
        },
        "placeholderText": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-text",
            "reflect": false,
            "defaultValue": "'File description'"
        },
        "placeholderLocation": {
            "type": "string",
            "mutable": false,
            "complexType": {
                "original": "string",
                "resolved": "string",
                "references": {}
            },
            "required": false,
            "optional": false,
            "docs": {
                "tags": [],
                "text": ""
            },
            "attribute": "placeholder-location",
            "reflect": false,
            "defaultValue": "'File URL'"
        }
    }; }
    static get elementRef() { return "el"; }
}
