import { p as proxyCustomElement, H, c as createEvent, h, d as Host } from './p-D16h8pzh.js';
import { VerdocsEndpoint, getTemplate } from '@verdocs/js-sdk';
import { S as SDKError } from './p-C1sRVZWv.js';
import { S as Store } from './p-DmsV595e.js';
import { d as defineCustomElement$H } from './p-BNrp2UP2.js';
import { d as defineCustomElement$G } from './p-UsZ2lpxS.js';
import { d as defineCustomElement$F } from './p-wYGYhfrp.js';
import { d as defineCustomElement$E } from './p-DsCKNQPC.js';
import { d as defineCustomElement$D } from './p-CeTLcymJ.js';
import { d as defineCustomElement$C } from './p-CZTe2XIO.js';
import { d as defineCustomElement$B } from './p-CTzrE2_W.js';
import { d as defineCustomElement$A } from './p-MX0H_yx6.js';
import { d as defineCustomElement$z } from './p-CRR4fTl9.js';
import { d as defineCustomElement$y } from './p-Clt27_Qj.js';
import { d as defineCustomElement$x } from './p-CsyhCKk4.js';
import { d as defineCustomElement$w } from './p-xIC5Vhhx.js';
import { d as defineCustomElement$v } from './p-Sk_71M_-.js';
import { d as defineCustomElement$u } from './p-BeSHNILk.js';
import { d as defineCustomElement$t } from './p-D-GZw56Q.js';
import { d as defineCustomElement$s } from './p-DF8La-N2.js';
import { d as defineCustomElement$r } from './p-DDTha7DK.js';
import { d as defineCustomElement$q } from './p-BGZ_owBm.js';
import { d as defineCustomElement$p } from './p-kCaWRqn0.js';
import { d as defineCustomElement$o } from './p-Bv-L0hsU.js';
import { d as defineCustomElement$n } from './p-BQW1cLII.js';
import { d as defineCustomElement$m } from './p-CQ-UXlBO.js';
import { d as defineCustomElement$l } from './p-Boia1Nbz.js';
import { d as defineCustomElement$k } from './p-BHeendgg.js';
import { d as defineCustomElement$j } from './p-C2M87N-a.js';
import { d as defineCustomElement$i } from './p-Cy-AXBKH.js';
import { d as defineCustomElement$h } from './p-DeoKKq-r.js';
import { d as defineCustomElement$g } from './p-DoO2XAMG.js';
import { d as defineCustomElement$f } from './p-BdSDDira.js';
import { d as defineCustomElement$e } from './p-DonwyCOM.js';
import { d as defineCustomElement$d } from './p-BV7xEuMw.js';
import { d as defineCustomElement$c } from './p-BR7qeKJV.js';
import { d as defineCustomElement$b } from './p-D646hJvk.js';
import { d as defineCustomElement$a } from './p-CNvRd0Kp.js';
import { d as defineCustomElement$9 } from './p-vCuIwe1D.js';
import { d as defineCustomElement$8 } from './p-CAJEh6K0.js';
import { d as defineCustomElement$7 } from './p-zcZJDJyB.js';
import { d as defineCustomElement$6 } from './p-OV-ZpJVv.js';
import { d as defineCustomElement$5 } from './p-DkUmJk0T.js';
import { d as defineCustomElement$4 } from './p-C_SISdpZ.js';
import { d as defineCustomElement$3 } from './p-B0-ZXlBg.js';
import { d as defineCustomElement$2 } from './p-CcglHGeY.js';

const verdocsBuildCss = "@-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-build{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;font-family:\"Inter\", -apple-system, \"Segoe UI\", \"Roboto\", \"Helvetica Neue\", sans-serif}verdocs-build .content{-ms-flex:1;flex:1;gap:20px;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-direction:column;flex-direction:column}verdocs-build verdocs-template-attachments,verdocs-build verdocs-template-roles{margin:20px}verdocs-build verdocs-template-fields{border-top:1px solid #777777}verdocs-build verdocs-template-attachments{padding:20px;background:#ffffff}verdocs-build verdocs-template-fields{width:100%}verdocs-build verdocs-preview{-ms-flex:1;flex:1}verdocs-build .preview-container{-ms-flex-direction:row;flex-direction:row;display:-ms-flexbox;display:flex;width:100%;background-color:#eeeeee;max-height:100%}@media all and (max-width: 450px){verdocs-build .preview-container{-ms-flex-direction:column;flex-direction:column}}verdocs-build .preview-send-wrapper{display:-ms-flexbox;display:flex;-ms-flex:0 0 300px;flex:0 0 300px;background-color:#ffffff;-webkit-box-shadow:1px 1px 6px -2px rgba(0, 0, 0, 0.4980392157);box-shadow:1px 1px 6px -2px rgba(0, 0, 0, 0.4980392157)}@media all and (max-width: 450px){verdocs-build .preview-send-wrapper{-ms-flex:0;flex:0}}verdocs-build .preview-preview-wrapper{display:-ms-flexbox;display:flex;-ms-flex:1;flex:1;-ms-flex-pack:center;justify-content:center;overflow-y:scroll}";

const VerdocsBuild$1 = /*@__PURE__*/ proxyCustomElement(class VerdocsBuild extends H {
    constructor() {
        super();
        this.__registerHost();
        this.cancel = createEvent(this, "cancel");
        this.sdkError = createEvent(this, "sdkError");
        this.stepChanged = createEvent(this, "stepChanged");
        this.send = createEvent(this, "send");
        this.templateUpdated = createEvent(this, "templateUpdated");
        this.templateCreated = createEvent(this, "templateCreated");
        this.rolesUpdated = createEvent(this, "rolesUpdated");
        this.templateListenerId = null;
        /**
         * The endpoint to use to communicate with Verdocs. If not set, the default endpoint will be used.
         */
        this.endpoint = VerdocsEndpoint.getDefault();
        /**
         * The ID of the template to create the document from. Unlike most other components, this is an optional parameter here.
         * If the template ID is known, `step` may also be specified to force displaying a specific step in the creation process.
         * If it is not specified, `step` will be ignored and the create step will be shown.
         */
        this.templateId = null;
        /**
         * The step in the creation process to display.
         */
        this.step = 'preview';
        this.loading = true;
        this.template = null;
    }
    onTemplateIdChanged(newTemplateId, oldTemplateId) {
        if (!oldTemplateId && newTemplateId && this.step === 'attachments') {
            this.step = 'preview';
        }
        this.loadTemplate(newTemplateId).catch((e) => console.log('Unknown Error', e));
    }
    onStepChanged() {
        // We reload the template here even if only the step changed in case
        // we were out of sync before
        this.loadTemplate(this.templateId).catch((e) => console.log('Unknown Error', e));
    }
    async componentWillLoad() {
        var _a, _b, _c, _d, _e, _f;
        try {
            this.endpoint.loadSession();
            if (!this.endpoint.session) {
                console.log('[BUILD] Unable to start builder session, must be authenticated');
                return;
            }
            if (!this.templateId) {
                console.log(`[BUILD] No template ID, activating upload mode`);
                this.step = 'attachments';
                this.loading = false;
                return;
            }
            try {
                this.loadTemplate(this.templateId).catch(e => console.log('[BUILD] Unable to load template', e));
            }
            catch (e) {
                console.log('[BUILD] Error loading template', e);
                (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(new SDKError(e.message, (_b = e.response) === null || _b === void 0 ? void 0 : _b.status, (_c = e.response) === null || _c === void 0 ? void 0 : _c.data));
            }
        }
        catch (e) {
            console.log('[BUILD] Error with builder session', e);
            (_d = this.sdkError) === null || _d === void 0 ? void 0 : _d.emit(new SDKError(e.message, (_e = e.response) === null || _e === void 0 ? void 0 : _e.status, (_f = e.response) === null || _f === void 0 ? void 0 : _f.data));
        }
    }
    async loadTemplate(templateId) {
        if (templateId) {
            Store.subscribe('templates', this.templateId, () => getTemplate(this.endpoint, this.templateId), false, (template) => {
                this.template = template;
                this.loading = false;
            });
        }
    }
    disconnectedCallback() {
        console.log('[BUILD] Disconnected');
        this.unlistenToTemplate();
    }
    unlistenToTemplate() {
        if (this.templateListenerId) {
            Store.store.delListener(this.templateListenerId);
            this.templateListenerId = null;
        }
    }
    handleCancel() {
        var _a;
        this.step = 'preview';
        (_a = this.cancel) === null || _a === void 0 ? void 0 : _a.emit();
    }
    async handleTemplateCreated(templateId) {
        var _a;
        await this.loadTemplate(templateId);
        this.templateId = templateId;
        this.step = 'roles';
        (_a = this.stepChanged) === null || _a === void 0 ? void 0 : _a.emit('roles');
    }
    async handleRolesUpdated(e) {
        var _a;
        (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit(e.detail);
    }
    async handleTemplateUpdated(e) {
        var _a;
        (_a = this.templateUpdated) === null || _a === void 0 ? void 0 : _a.emit(e.detail);
    }
    handleAttachmentsNext() {
        var _a;
        this.step = 'roles';
        (_a = this.stepChanged) === null || _a === void 0 ? void 0 : _a.emit('roles');
    }
    handleRolesNext() {
        var _a;
        this.step = 'fields';
        (_a = this.stepChanged) === null || _a === void 0 ? void 0 : _a.emit('fields');
    }
    handleStepChanged(step) {
        var _a;
        this.step = step;
        (_a = this.stepChanged) === null || _a === void 0 ? void 0 : _a.emit(step);
    }
    render() {
        if (this.loading) {
            return (h(Host, { class: "loading" }, h("verdocs-loader", null)));
        }
        if (!this.endpoint.session) {
            return (h(Host, null, h("verdocs-component-error", { message: "You must be authenticated to use this module." })));
        }
        return (h(Host, null, h("div", { class: "content" }, h("verdocs-template-build-tabs", { endpoint: this.endpoint, templateId: this.templateId, step: this.step, onSdkError: e => { var _a; return (_a = this.sdkError) === null || _a === void 0 ? void 0 : _a.emit(e.detail); }, onStepChanged: e => this.handleStepChanged(e.detail) }), this.step === 'attachments' && (h("verdocs-template-attachments", { templateId: this.templateId, endpoint: this.endpoint, onExit: () => this.handleCancel(), onNext: () => this.handleAttachmentsNext(), onTemplateUpdated: e => this.handleTemplateUpdated(e) })), this.step === 'roles' && (h("verdocs-template-roles", { templateId: this.templateId, endpoint: this.endpoint, onExit: () => this.handleCancel(), onNext: () => this.handleRolesNext(), onRolesUpdated: e => this.handleRolesUpdated(e) })), this.step === 'settings' && h("verdocs-template-settings", { templateId: this.templateId, endpoint: this.endpoint, onTemplateUpdated: e => this.handleTemplateUpdated(e) }), this.step === 'fields' && h("verdocs-template-fields", { templateId: this.templateId, endpoint: this.endpoint, onTemplateUpdated: e => this.handleTemplateUpdated(e) }), this.step === 'preview' && (h("div", { class: "preview-container" }, h("div", { class: "preview-send-wrapper" }, h("verdocs-send", { templateId: this.templateId, endpoint: this.endpoint, onSend: e => { var _a; return (_a = this.send) === null || _a === void 0 ? void 0 : _a.emit(e.detail); }, style: { width: '100%' } })), h("div", { class: "preview-preview-wrapper" }, h("verdocs-preview", { templateId: this.templateId, endpoint: this.endpoint, style: { display: 'flex', flex: '1', maxWidth: '1000px' } })))))));
    }
    get el() { return this; }
    static get watchers() { return {
        "templateId": ["onTemplateIdChanged"],
        "step": ["onStepChanged"]
    }; }
    static get style() { return verdocsBuildCss; }
}, [256, "verdocs-build", {
        "endpoint": [16],
        "templateId": [1537, "template-id"],
        "step": [1537],
        "loading": [32],
        "template": [32]
    }, undefined, {
        "templateId": ["onTemplateIdChanged"],
        "step": ["onStepChanged"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["verdocs-build", "verdocs-button", "verdocs-button-panel", "verdocs-checkbox", "verdocs-component-error", "verdocs-contact-picker", "verdocs-dialog", "verdocs-field-attachment", "verdocs-field-checkbox", "verdocs-field-date", "verdocs-field-dropdown", "verdocs-field-initial", "verdocs-field-radio", "verdocs-field-signature", "verdocs-field-textarea", "verdocs-field-textbox", "verdocs-field-timestamp", "verdocs-file-chooser", "verdocs-help-icon", "verdocs-initial-dialog", "verdocs-loader", "verdocs-menu-panel", "verdocs-ok-dialog", "verdocs-portal", "verdocs-preview", "verdocs-progress-bar", "verdocs-select-input", "verdocs-send", "verdocs-signature-dialog", "verdocs-spinner", "verdocs-switch", "verdocs-tabs", "verdocs-template-attachments", "verdocs-template-build-tabs", "verdocs-template-document-page", "verdocs-template-field-properties", "verdocs-template-fields", "verdocs-template-role-properties", "verdocs-template-roles", "verdocs-template-settings", "verdocs-text-input", "verdocs-toolbar-icon", "verdocs-upload-dialog"];
    components.forEach(tagName => { switch (tagName) {
        case "verdocs-build":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, VerdocsBuild$1);
            }
            break;
        case "verdocs-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$H();
            }
            break;
        case "verdocs-button-panel":
            if (!customElements.get(tagName)) {
                defineCustomElement$G();
            }
            break;
        case "verdocs-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$F();
            }
            break;
        case "verdocs-component-error":
            if (!customElements.get(tagName)) {
                defineCustomElement$E();
            }
            break;
        case "verdocs-contact-picker":
            if (!customElements.get(tagName)) {
                defineCustomElement$D();
            }
            break;
        case "verdocs-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$C();
            }
            break;
        case "verdocs-field-attachment":
            if (!customElements.get(tagName)) {
                defineCustomElement$B();
            }
            break;
        case "verdocs-field-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$A();
            }
            break;
        case "verdocs-field-date":
            if (!customElements.get(tagName)) {
                defineCustomElement$z();
            }
            break;
        case "verdocs-field-dropdown":
            if (!customElements.get(tagName)) {
                defineCustomElement$y();
            }
            break;
        case "verdocs-field-initial":
            if (!customElements.get(tagName)) {
                defineCustomElement$x();
            }
            break;
        case "verdocs-field-radio":
            if (!customElements.get(tagName)) {
                defineCustomElement$w();
            }
            break;
        case "verdocs-field-signature":
            if (!customElements.get(tagName)) {
                defineCustomElement$v();
            }
            break;
        case "verdocs-field-textarea":
            if (!customElements.get(tagName)) {
                defineCustomElement$u();
            }
            break;
        case "verdocs-field-textbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$t();
            }
            break;
        case "verdocs-field-timestamp":
            if (!customElements.get(tagName)) {
                defineCustomElement$s();
            }
            break;
        case "verdocs-file-chooser":
            if (!customElements.get(tagName)) {
                defineCustomElement$r();
            }
            break;
        case "verdocs-help-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$q();
            }
            break;
        case "verdocs-initial-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$p();
            }
            break;
        case "verdocs-loader":
            if (!customElements.get(tagName)) {
                defineCustomElement$o();
            }
            break;
        case "verdocs-menu-panel":
            if (!customElements.get(tagName)) {
                defineCustomElement$n();
            }
            break;
        case "verdocs-ok-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$m();
            }
            break;
        case "verdocs-portal":
            if (!customElements.get(tagName)) {
                defineCustomElement$l();
            }
            break;
        case "verdocs-preview":
            if (!customElements.get(tagName)) {
                defineCustomElement$k();
            }
            break;
        case "verdocs-progress-bar":
            if (!customElements.get(tagName)) {
                defineCustomElement$j();
            }
            break;
        case "verdocs-select-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$i();
            }
            break;
        case "verdocs-send":
            if (!customElements.get(tagName)) {
                defineCustomElement$h();
            }
            break;
        case "verdocs-signature-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$g();
            }
            break;
        case "verdocs-spinner":
            if (!customElements.get(tagName)) {
                defineCustomElement$f();
            }
            break;
        case "verdocs-switch":
            if (!customElements.get(tagName)) {
                defineCustomElement$e();
            }
            break;
        case "verdocs-tabs":
            if (!customElements.get(tagName)) {
                defineCustomElement$d();
            }
            break;
        case "verdocs-template-attachments":
            if (!customElements.get(tagName)) {
                defineCustomElement$c();
            }
            break;
        case "verdocs-template-build-tabs":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "verdocs-template-document-page":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "verdocs-template-field-properties":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "verdocs-template-fields":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "verdocs-template-role-properties":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "verdocs-template-roles":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "verdocs-template-settings":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "verdocs-text-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "verdocs-toolbar-icon":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "verdocs-upload-dialog":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}

const VerdocsBuild = VerdocsBuild$1;
const defineCustomElement = defineCustomElement$1;

export { VerdocsBuild, defineCustomElement };
//# sourceMappingURL=verdocs-build.js.map

//# sourceMappingURL=verdocs-build.js.map