import{p as e,H as t,c as s,h as i,d as o,t as l}from"./p-yZBlG3YQ.js";import{VerdocsEndpoint as a,getTemplate as d}from"@verdocs/js-sdk";import{S as n}from"./p-C1sRVZWv.js";import{S as r}from"./p-C7hFgM52.js";import{d as c}from"./p-CyDWJAOZ.js";import{d as p}from"./p-B-_kYJtC.js";const m=()=>`verdocs-template-build-tabs{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-align:end;align-items:flex-end;-ms-flex:0 0 50px;flex:0 0 50px;width:100%;background:#ffffff;color:#72757d;border-bottom:1px solid #dddddd;-webkit-filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));font-family:var(--verdocs-primary-font, "Inter", "Barlow", sans-serif)}verdocs-template-build-tabs .tab{position:relative;display:-ms-flexbox;display:flex;-ms-flex:1;flex:1;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;height:50px;padding:0 4px;background:#e7e7e7;font-weight:700;font-size:12px;cursor:pointer}@media (min-width: 768px){verdocs-template-build-tabs .tab{padding:0 8px 0 24px;font-size:14px}}verdocs-template-build-tabs .tab svg{position:absolute;top:0;right:-19px;z-index:10;pointer-events:none;display:none}@media (min-width: 768px){verdocs-template-build-tabs .tab svg{display:block}}verdocs-template-build-tabs .tab.active{background:#ffffff;color:#707ae5}verdocs-template-build-tabs .tab.disabled{cursor:default;color:#d1d5db}`;const f=e(class e extends t{constructor(e){super();if(e!==false){this.__registerHost()}this.sdkError=s(this,"sdkError");this.stepChanged=s(this,"stepChanged");this.templateListenerId=null;this.endpoint=a.getDefault();this.templateId=null;this.step="preview";this.loading=true;this.template=null}disconnectedCallback(){this.unlistenToTemplate()}async listenToTemplate(){this.unlistenToTemplate();r.subscribe("templates",this.templateId,(()=>d(this.endpoint,this.templateId)),false,(e=>{this.template=e;this.loading=false}))}unlistenToTemplate(){if(this.templateListenerId){r.store.delListener(this.templateListenerId);this.templateListenerId=null}}onTemplateIdChanged(e){console.log("[BUILD_TABS] Template ID changed",e);this.listenToTemplate()}onStepChanged(e){console.log("[BUILD_TABS] Step changed",e)}async componentWillLoad(){var e,t,s;try{this.endpoint.loadSession();if(!this.endpoint.session){console.log("[BUILD_TABS] Unable to start builder session, must be authenticated");return}if(!this.templateId){this.step="attachments";console.log("[BUILD_TABS] Missing required template ID, forcing view to attachments");return}this.listenToTemplate()}catch(i){console.log("[BUILD_TABS] Error loading template",i);(e=this.sdkError)===null||e===void 0?void 0:e.emit(new n(i.message,(t=i.response)===null||t===void 0?void 0:t.status,(s=i.response)===null||s===void 0?void 0:s.data))}}handleSelect(e){var t;if(e.disabled||e.id===this.step){return}this.step=e.id;(t=this.stepChanged)===null||t===void 0?void 0:t.emit(e.id)}render(){var e,t,s;if(this.loading){return i(o,null,i("verdocs-loader",null))}if(!this.endpoint.session){return i(o,null,i("verdocs-component-error",{message:"You must be authenticated to use this module."}))}const l=(((e=this.template)===null||e===void 0?void 0:e.documents)||[]).length>0;const a=l&&(((t=this.template)===null||t===void 0?void 0:t.roles)||[]).length>0;const d=a&&(((s=this.template)===null||s===void 0?void 0:s.fields)||[]).length>0;const n=[{id:"attachments",label:"Attachments",disabled:false},{id:"roles",label:"Workflow",disabled:!l},{id:"fields",label:"Fields",disabled:!a},{id:"preview",label:"Preview & Send",disabled:!d}];return i(o,null,n.map((e=>{const t=e.id===this.step;const s=["tab"];if(t)s.push("active");if(e.disabled)s.push("disabled");return i("div",{class:s.join(" "),onClick:()=>this.handleSelect(e)},i("span",null,e.label),i("svg",{"aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",width:"19",height:"50",viewBox:"0 0 19 50"},i("polygon",{points:"0,0 19,25 0,50",fill:t?"#ffffff":"#e7e7e7"})))})))}static get watchers(){return{templateId:[{onTemplateIdChanged:0}],step:[{onStepChanged:0}]}}static get style(){return m()}},[0,"verdocs-template-build-tabs",{endpoint:[16],templateId:[1537,"template-id"],step:[1537],loading:[32],template:[32]},undefined,{templateId:[{onTemplateIdChanged:0}],step:[{onStepChanged:0}]}]);function h(){if(typeof customElements==="undefined"){return}const e=["verdocs-template-build-tabs","verdocs-component-error","verdocs-loader"];e.forEach((e=>{switch(e){case"verdocs-template-build-tabs":if(!customElements.get(l(e))){customElements.define(l(e),f)}break;case"verdocs-component-error":if(!customElements.get(l(e))){c()}break;case"verdocs-loader":if(!customElements.get(l(e))){p()}break}}))}export{f as V,h as d};
//# sourceMappingURL=p-Dm9oOnhq.js.map