import { p as proxyCustomElement, H, c as createEvent, h, d as Host, F as Fragment } from './p-D16h8pzh.js';
import { getRGBA } from '@verdocs/js-sdk';
import { S as SettingsIcon } from './p-7LXbcjVz.js';
import { S as Store } from './p-DmsV595e.js';
import { d as defineCustomElement$c } from './p-BNrp2UP2.js';
import { d as defineCustomElement$b } from './p-wYGYhfrp.js';
import { d as defineCustomElement$a } from './p-DsCKNQPC.js';
import { d as defineCustomElement$9 } from './p-CZTe2XIO.js';
import { d as defineCustomElement$8 } from './p-BGZ_owBm.js';
import { d as defineCustomElement$7 } from './p-Bv-L0hsU.js';
import { d as defineCustomElement$6 } from './p-CQ-UXlBO.js';
import { d as defineCustomElement$5 } from './p-Boia1Nbz.js';
import { d as defineCustomElement$4 } from './p-Cy-AXBKH.js';
import { d as defineCustomElement$3 } from './p-vCuIwe1D.js';
import { d as defineCustomElement$2 } from './p-C_SISdpZ.js';
import { d as defineCustomElement$1 } from './p-CcglHGeY.js';

const verdocsFieldAttachmentCss = "@-webkit-keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}@keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}verdocs-field-attachment{font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif;-webkit-box-sizing:border-box;box-sizing:border-box;width:24px;height:24px;display:block;font-size:11px;position:relative;scroll-margin:20px 0;background-color:transparent;-webkit-transform-origin:bottom left;transform-origin:bottom left}verdocs-field-attachment.focused{-webkit-animation:verdocs-field-pulse 0.4s 1;animation:verdocs-field-pulse 0.4s 1}verdocs-field-attachment label{top:-14px;left:-1px;height:14px;color:white;padding:0 4px;font-size:9px;line-height:13px;position:absolute;background:#4a4a99;border-top-left-radius:2px;border-top-right-radius:2px}verdocs-field-attachment svg{width:16px;height:16px}verdocs-field-attachment.disabled svg{opacity:0.5}verdocs-field-attachment.disabled svg span{cursor:inherit}verdocs-field-attachment .attach{cursor:inherit;width:24px;height:24px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}verdocs-field-attachment.required .attach{border:1px solid #cc0000}verdocs-field-attachment verdocs-button-panel{top:1px;left:-19px;opacity:0.5;z-index:1000;cursor:pointer;position:absolute;-webkit-transform:scale(0.6);transform:scale(0.6)}verdocs-field-attachment verdocs-button-panel[data-active],verdocs-field-attachment verdocs-button-panel:hover{opacity:1}verdocs-field-attachment verdocs-button-panel .icon svg{fill:#333333}verdocs-field-attachment verdocs-button-panel .icon:hover svg{fill:#000000}verdocs-field-attachment .settings-icon{position:absolute;top:-3px;left:-20px;display:inline-block;cursor:pointer;opacity:0.3}verdocs-field-attachment .settings-icon svg{fill:#707ae5}verdocs-field-attachment .settings-icon:hover{opacity:1}@keyframes verdocs-field-pulse{0%{background-color:rgba(0, 0, 0, 0.35)}50%{background-color:rgba(0, 0, 0, 0)}100%{background-color:rgba(0, 0, 0, 0.35)}}";

const PaperclipIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13" /></svg>`;
const AttachedIcon = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#339933" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-file-check"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="m9 15 2 2 4-4"/></svg>`;
const VerdocsFieldAttachment = /*@__PURE__*/ proxyCustomElement(class VerdocsFieldAttachment extends H {
    constructor() {
        super();
        this.__registerHost();
        this.settingsChanged = createEvent(this, "settingsChanged");
        this.attached = createEvent(this, "attached");
        this.deleted = createEvent(this, "deleted");
        /**
         * Fields may be attached to templates or envelopes, but only template fields may be edited.
         */
        this.source = 'template';
        /**
         * The source template or envelope ID the field is found in.
         */
        this.sourceid = '';
        /**
         * The name of the field to display.
         */
        this.fieldname = '';
        /**
         * Override the field's settings. This is intended to be used during signing when fields are being
         * mutated.
         */
        this.field = null;
        /**
         * If set, overrides the field's settings object. Primarily used to support "preview" modes where all fields are disabled.
         */
        this.disabled = false;
        /**
         * If set, a settings icon will be displayed on hover. The settings shown allow the field's recipient and other settings to be
         * changed, so it should typically only be enabled in the Builder.
         */
        this.editable = false;
        /**
         * If set, the field may be dragged to a new location. This should only be enabled in the Builder, or for self-placed fields.
         */
        this.moveable = false;
        /**
         * If set, the field is considered "done" and is drawn in a display-final-value state.
         */
        this.done = false;
        /**
         * If set, the field will be be scaled horizontally by this factor.
         */
        this.xscale = 1;
        /**
         * If set, the field will be be scaled vertically by this factor.
         */
        this.yscale = 1;
        /**
         * The page the field is on
         */
        this.pagenumber = 1;
        this.showingProperties = false;
        this.dialogOpen = false;
        this.selectedFile = null;
        this.focused = false;
        this.handleUploadNext = (e) => {
            var _a;
            console.log('Upload next', e);
            this.dialogOpen = false;
            this.selectedFile = e.detail[0];
            (_a = this.attached) === null || _a === void 0 ? void 0 : _a.emit(e.detail[0]);
        };
        this.handleUploadRemove = (e) => {
            var _a;
            e.preventDefault();
            e.stopPropagation();
            this.dialogOpen = false;
            this.selectedFile = null;
            (_a = this.deleted) === null || _a === void 0 ? void 0 : _a.emit({ fieldName: this.fieldname });
        };
    }
    async focusField() {
        // Our input field is fake, so we fake the flash too
        this.focused = true;
        this.dialogOpen = true;
        setTimeout(() => {
            this.focused = false;
        }, 500);
    }
    async showSettingsPanel() {
        const settingsPanel = document.getElementById(`verdocs-settings-panel-${this.fieldname}`);
        if (settingsPanel && settingsPanel.showPanel) {
            settingsPanel.showPanel();
        }
    }
    async hideSettingsPanel() {
        const settingsPanel = document.getElementById(`verdocs-settings-panel-${this.fieldname}`);
        if (settingsPanel && settingsPanel.hidePanel) {
            settingsPanel.hidePanel();
        }
    }
    handleShow() {
        this.dialogOpen = true;
    }
    render() {
        const { source, sourceid, fieldname, editable = false, done = false, disabled = false, focused, xscale = 1, yscale = 1 } = this;
        const { index, field } = Store.getField(source, sourceid, fieldname, this.field);
        const { required = false, value = '', label = '', settings = {} } = field || {};
        const backgroundColor = getRGBA(index);
        const hasFile = value || !!this.selectedFile;
        if (done) {
            return (h(Host, { class: { done } }, h("div", { class: "attach", innerHTML: hasFile ? AttachedIcon : PaperclipIcon })));
        }
        return (h(Host, { class: { required, disabled, done, focused }, style: { backgroundColor } }, label && h("label", null, label), h("div", { class: "attach", innerHTML: hasFile ? AttachedIcon : PaperclipIcon, onClick: () => !disabled && this.handleShow() }), editable && (h(Fragment, null, h("div", { id: `verdocs-settings-panel-trigger-${fieldname}`, style: { transform: `scale(${Math.floor((1 / xscale) * 1000) / 1000}, ${Math.floor((1 / yscale) * 1000) / 1000})` }, class: "settings-icon", innerHTML: SettingsIcon, onClick: (e) => {
                e.stopPropagation();
                this.showingProperties = !this.showingProperties;
            } }), this.showingProperties && (h("verdocs-portal", { anchor: `verdocs-settings-panel-trigger-${fieldname}`, onClickAway: () => (this.showingProperties = false) }, h("verdocs-template-field-properties", { templateId: sourceid, fieldName: fieldname, onClose: () => (this.showingProperties = false), onDelete: () => {
                var _a;
                (_a = this.deleted) === null || _a === void 0 ? void 0 : _a.emit({ fieldName: fieldname });
                return this.hideSettingsPanel();
            }, onSettingsChanged: e => {
                var _a;
                (_a = this.settingsChanged) === null || _a === void 0 ? void 0 : _a.emit(e.detail);
                return this.hideSettingsPanel();
            }, helpText: 'Attachments allow the user to attach their own documents (e.g. resumes or disclosures) to a signing flow.' }))))), this.dialogOpen && (h("verdocs-portal", null, h("verdocs-upload-dialog", { existingFile: settings, onNext: e => this.handleUploadNext(e), onRemove: e => this.handleUploadRemove(e), onExit: () => (this.dialogOpen = false) })))));
    }
    get el() { return this; }
    static get style() { return verdocsFieldAttachmentCss; }
}, [256, "verdocs-field-attachment", {
        "source": [513],
        "sourceid": [513],
        "fieldname": [513],
        "field": [16],
        "disabled": [516],
        "editable": [516],
        "moveable": [516],
        "done": [516],
        "xscale": [514],
        "yscale": [514],
        "pagenumber": [514],
        "showingProperties": [32],
        "dialogOpen": [32],
        "selectedFile": [32],
        "focused": [32],
        "focusField": [64],
        "showSettingsPanel": [64],
        "hideSettingsPanel": [64]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["verdocs-field-attachment", "verdocs-button", "verdocs-checkbox", "verdocs-component-error", "verdocs-dialog", "verdocs-help-icon", "verdocs-loader", "verdocs-ok-dialog", "verdocs-portal", "verdocs-select-input", "verdocs-template-field-properties", "verdocs-text-input", "verdocs-upload-dialog"];
    components.forEach(tagName => { switch (tagName) {
        case "verdocs-field-attachment":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, VerdocsFieldAttachment);
            }
            break;
        case "verdocs-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$c();
            }
            break;
        case "verdocs-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "verdocs-component-error":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "verdocs-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "verdocs-help-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "verdocs-loader":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "verdocs-ok-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "verdocs-portal":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "verdocs-select-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "verdocs-template-field-properties":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "verdocs-text-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "verdocs-upload-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}

export { VerdocsFieldAttachment as V, defineCustomElement as d };
//# sourceMappingURL=p-CTzrE2_W.js.map

//# sourceMappingURL=p-CTzrE2_W.js.map