1import{S as et}from"./D0HDmefO.js";import{e as ta,B as aa,s as na,a2 as ra,h as sa,E as y,a5 as tt,m,I as M,i as oa,c as s,a as u,M as at,F as f,r as _,l as F,t as d,g as ua,b as nt,d as ve,A as rt,D as st,a6 as la,o,n as A,z as ia}from"./D3mXZbvm.js";const ca={class:"min-h-screen bg-slate-50"},da={class:"mx-auto max-w-6xl px-4 py-10 sm:px-6 lg:px-8"},va={class:"rounded-3xl border border-slate-200 bg-white p-6 shadow-xl shadow-slate-200/40 sm:p-8"},pa={class:"relative mb-10"},ma=["disabled","onClick"],ya={class:"space-y-6"},ha={class:"text-xs font-semibold uppercase tracking-[0.28em] text-slate-400"},ga={class:"text-2xl font-bold text-slate-900"},ba={key:0,class:"mt-2 text-sm text-slate-600"},xa={key:0,class:"space-y-6"},fa={key:0,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},_a={key:1,class:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3"},ka=["onClick"],wa={class:"flex items-center gap-4"},Sa={class:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-xl border border-slate-200 bg-slate-50"},Aa=["src","alt"],Ca={key:1,class:"text-lg font-semibold text-slate-400"},Ta={class:"text-base font-semibold text-slate-900"},Va={class:"text-sm text-slate-600"},Ia={class:"flex justify-end"},Na=["disabled"],$a={key:0,class:"inline-flex items-center gap-2"},Qa={key:1},Fa={key:1},qa={key:0,class:"space-y-5"},Ea={key:0,class:"space-y-4"},La={key:1,class:"rounded-2xl border border-rose-200 bg-rose-50 px-5 py-4 text-sm text-rose-600"},ja={key:2,class:"space-y-4"},Pa={class:"flex items-center justify-between border-b border-slate-200 bg-slate-50 px-5 py-3"},Ua={class:"text-sm font-semibold uppercase tracking-[0.14em] text-slate-700"},Ba=["onClick"],za={key:0,class:"divide-y divide-slate-100"},Da={class:"text-sm text-slate-500"},Ma={key:1,class:"px-5 py-4 text-sm text-slate-500"},Oa={key:3,class:"rounded-2xl border border-dashed border-slate-200 bg-slate-50/70 px-6 py-10 text-center"},Ra={key:1,class:"space-y-6"},Ka={key:0,class:"grid gap-4 sm:grid-cols-2"},Ga={key:1,class:"rounded-2xl border border-rose-200 bg-rose-50 px-5 py-4 text-sm text-rose-600"},Wa={key:2,class:"space-y-6"},Ja=["data-template-field-id"],Ya={key:0,class:"text-xs font-semibold uppercase tracking-[0.2em] text-slate-500"},Ha={key:0,class:"text-rose-500"},Xa={key:1,class:"text-xs font-semibold text-rose-500"},Za={key:2,class:"flex flex-wrap gap-2"},en=["onClick"],tn={key:3,class:"space-y-2"},an=["max","value","onInput"],nn={class:"flex items-center justify-between text-xs text-slate-500"},rn=["onClick"],sn={key:4,class:"flex flex-wrap gap-2"},on=["onClick"],un={key:5,class:"space-y-2"},ln=["max","value","onInput"],cn={class:"flex items-center justify-between text-xs text-slate-500"},dn={key:6,class:"space-y-2"},vn=["max","value","onInput"],pn={class:"flex items-center justify-between text-xs text-slate-500"},mn=["onClick"],yn={key:7,class:"rounded-2xl border border-slate-200 bg-slate-50/40 p-4 sm:p-5"},hn={class:"relative"},gn=["disabled","onClick"],bn={class:"rounded-full bg-white px-4 py-2 text-xs font-semibold uppercase tracking-[0.12em] text-primary shadow-sm"},xn={class:"flex items-start gap-3"},fn={class:"min-w-0 flex-1 rounded-2xl border border-slate-200 bg-white px-4 py-3"},_n={key:0,class:"text-sm text-slate-700"},kn={key:1,class:"inline-flex items-center gap-1 text-slate-400","aria-label":"Generating question"},wn={class:"flex items-start justify-end gap-3"},Sn={class:"w-full max-w-3xl rounded-2xl border border-primary/25 bg-primary/5 p-2"},An=["disabled","value","onInput"],Cn={class:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-secondary text-[10px] font-bold uppercase tracking-[0.08em] text-white"},Tn={key:0,class:"text-xs font-semibold text-rose-500"},Vn={key:8,class:"space-y-3 rounded-2xl border border-slate-200 bg-slate-50/50 p-4"},In={class:"flex flex-wrap items-center gap-3"},Nn={class:"inline-flex cursor-pointer items-center rounded-btn border border-slate-200 bg-white px-4 py-2 text-sm font-semibold text-slate-700 transition hover:border-slate-300"},$n=["disabled","onChange"],Qn={key:0,class:"text-sm text-slate-600"},Fn={key:0,class:"text-xs font-semibold text-rose-500"},qn={key:9},En=["value","onInput"],Ln={key:10},jn=["value","onChange"],Pn=["value"],Un={key:11},Bn=["value","onInput"],zn={key:3,class:"rounded-2xl border border-dashed border-slate-200 bg-slate-50/70 px-6 py-10 text-center"},Dn={key:2,class:"flex flex-wrap items-center justify-between gap-3"},Mn=["disabled"],On=["disabled"],Rn={key:0,class:"inline-flex items-center gap-2"},Kn={key:1},Gn=["disabled"],Hn=ta({__name:"index",async setup(Wn){let q,H;const{get:X,request:we}=aa(),Se=ia(),C=na(),ot=ra(),E=sa(),ut=y(()=>E.user?.group==="group_default"),Ae=y(()=>{const e=C.query.templateId,a=Array.isArray(e)?e[0]:e;return a?String(a):""}),Ce=y(()=>{const e=C.query.bookTemplateId,a=Array.isArray(e)?e[0]:e;return a?String(a):""}),{data:lt}=([q,H]=tt(()=>st("template-steps",()=>X("/api/v3/templates/steps"))),q=await q,H(),q),{data:it,pending:ct}=([q,H]=tt(()=>st("templates",()=>X("/api/v3/templates"))),q=await q,H(),q),p=m(null),k=m(0),g=m(null),j=m({}),Z=m({}),P=m({}),ee=m({}),i=m({}),x=m({}),N=m({}),O=m({}),R=m({}),S=m({}),W=m({}),J=m({}),L=m({}),te=m({}),K=m({}),ae=m(!1),V=m(!1),ne=m(""),Y=m(null),pe=m(!1),G=m(""),me=m(""),dt={id:"start",name:"Template"},vt={id:"summary",name:"Summary"},pt=y(()=>lt.value??[]),w=y(()=>[dt,...pt.value,vt]),mt=y(()=>it.value??[]),re=y(()=>v.value==="start"),se=y(()=>v.value==="summary"),U=y(()=>!re.value&&!se.value),yt=y(()=>w.value.length<=1?0:k.value/(w.value.length-1)*100),ht=y(()=>({gridTemplateColumns:"repeat(auto-fit, minmax(120px, 1fr))"})),v=y(()=>String(w.value[k.value]?.id??"start")),gt=y(()=>v.value==="start"?"Choose a template":v.value==="summary"?"Review & generate":w.value[k.value]?.name||"Step"),Te=y(()=>v.value==="start"?"Pick a starting point for your book.":v.value==="summary"?"Review your template inputs, then create your book.":""),$=y(()=>j.value[v.value]?.fields??[]),Ve=y(()=>Z.value[v.value]??!1),Ie=y(()=>P.value[v.value]??""),bt=y(()=>ee.value[v.value]??!1),Ne=y(()=>$.value.some(e=>e.type!=="aiQuestion"?!1:(e.questions||[]).some(a=>Oe(e.id,a.id)))),$e=y(()=>$.value.some(e=>e.type==="sourceFile"&&fe(e.id))),Qe=y(()=>Y.value?.steps??[]),ye=[{label:"English",value:"en"},{label:"Magyar",value:"hu"},{label:"Deutsch",value:"de"},{label:"Español",value:"es"},{label:"Français",value:"fr"},{label:"Italiano",value:"it"},{label:"Português",value:"pt"},{label:"æ¥æ¬èª",value:"ja"},{label:"íêµì´",value:"ko"},{label:"Türkçe",value:"tr"}],xt=Object.fromEntries(ye.map(e=>[e.label,e.value])),ft=Object.fromEntries(ye.map(e=>[e.value,e.label])),_t=y(()=>E.user?.name?E.user.name.split(" ").map(e=>e[0]).join("").toUpperCase().substring(0,2):"?");function kt(e){return String(e.id)}function wt(e){return e.id==="start"?"Template":e.id==="summary"?"Summary":e.name}function St(e){if(!e)return"start";const a=Array.isArray(e)?e[0]:e;if(a==null)return"start";const t=String(a);return w.value.some(r=>String(r.id)===t)?t:"start"}function B(e){const a=p.value?String(p.value):Ae.value,t=g.value?String(g.value):Ce.value;C.query.step===e&&C.query.templateId===a&&C.query.bookTemplateId===t||ot.replace({query:{...C.query,step:e,templateId:a||void 0,bookTemplateId:t||void 0}})}function oe(e,a=!1){if(e<0||e>=w.value.length||e>k.value&&!a)return;const t=w.value[e];t&&(k.value=e,B(String(t.id)))}async function Fe(){if(!(k.value>=w.value.length-1)&&!(re.value&&!p.value)&&!V.value){if(U.value&&!Xt()){await At();return}V.value=!0;try{if(U.value&&!await Le())return;const e=k.value+1,a=w.value[e];a&&a.id!=="summary"&&a.id!=="start"&&await Ee(String(a.id)),a?.id==="summary"&&await qe(!0),oe(e,!0)}finally{V.value=!1}}}async function At(){const e=$.value.find(r=>!!x.value[r.id]);if(!e)return;await la();
1const a=document.querySelector(`[data-template-field-id="${e.id}"]`);if(!a)return;const n=a.getBoundingClientRect().top+window.scrollY-96;window.scrollTo({top:Math.max(0,n),behavior:"smooth"})}function Ct(){k.value<=0||oe(k.value-1)}function Tt(e){p.value=e,B(v.value)}function Vt(){return!p.value||!g.value?"":`${p.value}:${g.value}`}async function qe(e=!1){const a=Vt();if(!a){Y.value=null,G.value="";return}if(!(!e&&me.value===a&&Y.value)){pe.value=!0,G.value="";try{const t=await X(`/api/v3/templates/${p.value}/summary`,{bookTemplateId:g.value});Y.value=t,me.value=a}catch{G.value="Unable to load summary. Please try again."}finally{pe.value=!1}}}async function Ee(e){if(!(!p.value||e==="start"||e==="summary")&&!j.value[e]){Z.value[e]=!0,P.value[e]=null;try{const a=g.value?{bookTemplateId:g.value}:void 0,t=await X(`/api/v3/templates/${p.value}/step/${e}`,a);j.value[e]=t,he(t.fields)}catch{P.value[e]="Unable to load this step. Please try again."}finally{Z.value[e]=!1}}}function he(e){e.forEach(a=>{if(i.value[a.id]===void 0){if(a.type==="multiple_choice"){if(Array.isArray(a.currentValues)&&a.currentValues.length>0){i.value[a.id]=a.currentValues.map(t=>String(t));return}if(_e(a)&&a.choices?.length){const t=a.choices[0];t&&(i.value[a.id]=[h(t)])}return}if(a.type==="slider"){if(a.currentValue!==void 0&&a.currentValue!==null){const t=Number(a.currentValue);Number.isNaN(t)||(i.value[a.id]=t)}else i.value[a.id]=0;return}if(a.type==="length"){if(a.currentValue===void 0||a.currentValue===null){const t=a.choices?.[0];t&&(i.value[a.id]=h(t));return}i.value[a.id]=String(a.currentValue);return}if(a.type==="aiQuestion"){const n=(Array.isArray(a.currentValues)?a.currentValues:[]).map((r,l)=>{if(r&&typeof r=="object"&&!Array.isArray(r)){const c=String(r.question??"").trim(),b=a.questions?.[l]?.id;return b!==void 0&&c.length>0&&(N.value[Q(a.id,b)]=c),String(r.answer??"")}return String(r??"")});i.value[a.id]=n,(a.questions||[]).forEach(r=>{const l=Q(a.id,r.id);S.value[l]===void 0&&(S.value[l]=z(a.id,r.id).length>0)});return}if(a.type==="sourceFile"){if(a.currentValue&&typeof a.currentValue=="object"&&!Array.isArray(a.currentValue)){const n=a.currentValue;L.value[a.id]=n,i.value[a.id]=n.fileName||n.reference||"";return}if(a.currentValue===void 0||a.currentValue===null)return;const t=String(a.currentValue);i.value[a.id]=t,L.value[a.id]||(L.value[a.id]=null);return}if(!(a.currentValue===void 0||a.currentValue===null)){if(a.type==="language"){const t=String(a.currentValue);i.value[a.id]=xt[t]??t;return}i.value[a.id]=String(a.currentValue)}}})}async function Le(){if(!p.value||!U.value)return!0;const e=v.value;ee.value[e]=!0,P.value[e]=null;try{const t={fields:$.value.map(l=>{const c=i.value[l.id];if(l.type==="aiQuestion"){const b=Rt(l);return{fieldId:l.id,values:b}}if(l.type==="multiple_choice"){const b=Array.isArray(c)?c:[];return{fieldId:l.id,values:b}}if(l.type==="sourceFile"){const b=L.value[l.id];return b?{fieldId:l.id,value:b}:{fieldId:l.id,value:typeof c=="string"?c:null}}return{fieldId:l.id,value:c??null}})};g.value&&(t.bookTemplateId=g.value);const n=await we(`/api/v3/templates/${p.value}/step/${e}`,{method:"POST",body:t});if(!n.ok)return P.value[e]="Unable to save this step. Please try again.",!1;const r=n.data;return r?.bookTemplateId&&(g.value=r.bookTemplateId,B(e)),r?.step&&(j.value[e]=r.step,he(r.step.fields)),!0}catch{return P.value[e]="Unable to save this step. Please try again.",!1}finally{ee.value[e]=!1}}function It(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"")}function T(e){return e==null?"":String(e)}function ge(e,a=!1){if(typeof e=="boolean")return e;if(typeof e=="number")return e===1;if(typeof e=="string"){const t=e.trim().toLowerCase();if(["true","1","yes","y","on"].includes(t))return!0;if(["false","0","no","n","off"].includes(t))return!1}return a}function Nt(e){return Array.isArray(e)?e.map(a=>String(a)).filter(a=>a.trim().length>0):typeof e=="string"?e.split(/[,\n]/).map(a=>a.trim()).filter(a=>a.length>0):[]}function $t(e){const a=i.value[e.id];if(a==null)return a;
1if(e.type==="choice"){const t=String(a);return(e.choices||[]).find(r=>h(r)===t)?.name??t}if(e.type==="slider"){const t=Number(a);return!Number.isNaN(t)&&e.choices&&e.choices[t]?e.choices[t].name:t}if(e.type==="length"){const t=String(a);return(e.choices||[]).find(r=>h(r)===t)?.name??t}if(e.type==="multiple_choice")return(Array.isArray(a)?a:[]).map(r=>String(r)).map(r=>(e.choices||[]).find(c=>h(c)===r)?.name??r);if(e.type==="sourceFile"){if(a&&typeof a=="object"&&!Array.isArray(a)){const n=a;return n.fileName||n.reference||""}const t=L.value[e.id];return t?t.fileName||t.reference||"":String(a)}return a}function Qt(){const e={};return Object.values(j.value).filter(a=>!!a).forEach(a=>{a.fields.forEach(t=>{e[It(t.name)]=$t(t)})}),{bookTemplateId:g.value,title:T(e.title),subtitle:T(e.subtitle),style:T(e.style),author:T(e.author),language:T(e.language),topic:T(e.topic),publisher:T(e.publisher),link:T(e.link),dedication:T(e.dedication),acknowledgements:T(e.acknowledgements??e.acknowledgments),bibliography:T(e.bibliography),recommendedBooks:Nt(e.recommendedbooks),introduction:ge(e.introduction,!0),epilogue:ge(e.epilogue,!1),demo:ge(e.demo,!1)||ut.value}}async function Ft(){if(ne.value="",!g.value){ne.value="Missing bookTemplateId. Please go back and complete the template steps again.";return}ae.value=!0;try{const e=Qt(),a=await we("/api/v3/books/generate",{method:"POST",body:e});if(a.ok&&a.data?.id){E.isAuthenticated?await rt(`/services/generate/${a.data.id}`):(localStorage.setItem("bookId",String(a.data.id)),await rt("/registration"));return}ne.value=a.data?.message||"Failed to create book."}catch(e){ne.value=e?.message||"Failed to create book."}finally{ae.value=!1}}function qt(e){return e===k.value?"border-primary bg-primary text-white shadow-md shadow-orange-200/70":e<k.value?"border-emerald-400 bg-emerald-400 text-white":"border-slate-200 bg-white text-slate-500 group-hover:border-slate-300"}function Et(e){return e===k.value?"text-primary":e<k.value?"text-emerald-500":"text-slate-400 group-hover:text-slate-600"}function Lt(e){return p.value===e?"border-primary bg-orange-50/60 shadow-lg shadow-orange-100":"border-slate-200 bg-white hover:-translate-y-0.5 hover:border-slate-300 hover:shadow-md"}function je(e){const a=e.image?.resources??[],t=a.find(r=>r.mimeType?.startsWith("http"))?.mimeType;return t||a.find(r=>r.url?.startsWith("http"))?.url||""}function be(e){const a=i.value[e];return typeof a=="string"?a:""}function jt(e){const a=i.value[e];return typeof a=="number"?a:0}function h(e){return e.value!==void 0&&e.value!==null&&String(e.value).length>0?String(e.value):e.id!==void 0&&e.id!==null?String(e.id):e.name}function Pe(e){const a=i.value[e.id];if(a==null)return 0;const t=String(a),n=(e.choices||[]).findIndex(r=>h(r)===t);return n>=0?n:0}function Ue(e,a,t){if(!t.length){i.value[e]="";return}const n=Math.min(Math.max(a,0),t.length-1),r=t[n];r&&(i.value[e]=h(r),x.value[e]=null)}function xe(e,a){i.value[e]=a,x.value[e]=null}function fe(e){return te.value[e]??!1}function Be(e){return K.value[e]??null}function ze(e){const a=L.value[e];if(a?.fileName)return a.fileName;const t=i.value[e];return typeof t=="string"?t:""}async function Pt(e,a){const t=a.target,n=t.files?.[0];n&&(await Ut(e,n),t.value="")}async function Ut(e,a){if(!p.value||!U.value)return;if(!g.value){K.value[e.id]="Upload becomes available after the first successful step save.";return}te.value[e.id]=!0,K.value[e.id]=null;const n=`${(Se.public?.apiBaseUrl||"").replace(/\/$/,"")}/api/v3/templates/${p.value}/step/${v.value}/field/${e.id}/source-file/upload`,r=new FormData;r.append("bookTemplateId",String(g.value)),r.append("file",a);try{const l=await fetch(n,{method:"POST",headers:{...E.token?{Authorization:`Bearer ${E.token}`}:{}},body:r});if(!l.ok){K.value[e.id]="Unable to upload file right now.";return}const c=await l.json();c.bookTemplateId&&(g.value=c.bookTemplateId,B(v.value)),c.sourceFile?(L.value[e.id]=c.sourceFile,i.value[e.id]=c.sourceFile.fileName||c.sourceFile.reference||a.name,x.value[e.id]=null):(i.value[e.id]=a.name,x.value[e.id]=null),c.step&&(j.value[v.value]=c.step,he(c.step.fields))}catch{K.value[e.id]="Unable to upload file right now."}finally{te.value[e.id]=!1}}function Q(e,a){return`${e}:${String(a)}`}function ue(e,a){return`${e}:${a}`}function De(e,a){return W.value[ue(e,a)]??!1}function Me(e,a){return J.value[ue(e,a)]??!1}
1async function Bt(e){const a=ue(v.value,e.id);if(!(W.value[a]||J.value[a])){J.value[a]=!0;try{if(!await Le())return;W.value[a]=!0,(e.questions||[]).forEach(n=>{const r=Q(e.id,n.id);if(z(e.id,n.id).trim().length>0){S.value[r]=!0;return}O.value[r]||Kt(e,n)})}finally{J.value[a]=!1}}}function zt(e){const a=i.value[e.id],t=Array.isArray(a)?a.map(r=>String(r)):[],n=e.questions?.length??t.length;return n>t.length?[...t,...Array.from({length:n-t.length},()=>"")]:t}function Dt(e,a){return zt(e)[a]??""}function Mt(e,a,t,n){const r=i.value[e],l=Array.isArray(r)?r.map(D=>String(D)):[],c=Math.max(n,l.length,a+1),b=Array.from({length:c},(D,I)=>l[I]??"");b[a]=t,i.value[e]=b,x.value[e]=null}function z(e,a){return N.value[Q(e,a)]||""}function Oe(e,a){return O.value[Q(e,a)]??!1}function Re(e,a){return R.value[Q(e,a)]??null}function Ot(e,a){const t=Q(e,a);return(S.value[t]??!1)&&!Oe(e,a)}function Rt(e){const a=i.value[e.id],t=Array.isArray(a)?a.map(l=>String(l??"")):[],n=e.questions||[],r=n.length||t.length;return Array.from({length:r},(l,c)=>{const b=t[c]??"",D=n[c],I=D?z(e.id,D.id).trim():"";return I.length>0?{question:I,answer:b}:b})}function Ke(e){const t=e.replace(/\r/g,"").split(` 2`);let n="message";const r=[];return t.forEach(l=>{if(l.startsWith("event:")){n=l.slice(6).trim();return}l.startsWith("data:")&&r.push(l.slice(5).trim())}),{event:n,data:r.join(` 3`)}}async function Kt(e,a){if(!p.value||!U.value)return;const t=Q(e.id,a.id);if(O.value[t])return;O.value[t]=!0,R.value[t]=null,S.value[t]=!1,N.value[t]="";let n=!1;const l=`${(Se.public?.apiBaseUrl||"").replace(/\/$/,"")}/api/v3/templates/${p.value}/step/${v.value}/field/${e.id}/question/${a.id}/generate`;try{const c=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json",...E.token?{Authorization:`Bearer ${E.token}`}:{}},body:JSON.stringify({bookTemplateId:g.value??void 0,mode:"openai"})});if(!c.ok||!c.body){R.value[t]="Unable to generate question right now.",S.value[t]=!0;return}const b=c.body.getReader(),D=new TextDecoder;let I="";for(;;){const{value:ke,done:ie}=await b.read();if(ie)break;I+=D.decode(ke,{stream:!0}).replace(/\r/g,"");const ce=I.split(` 4 5`);I=ce.pop()??"",ce.forEach(de=>{const{event:Ye,data:He}=Ke(de);if(He)try{const Xe=JSON.parse(He);if(Ye==="chunk"&&(N.value[t]=(N.value[t]||"")+String(Xe.chunk||"")),Ye==="done"){n=!0;const Ze=String(Xe.question||"");Ze&&(N.value[t]=Ze),S.value[t]=!0}}catch{}})}if(I.trim().length>0){const{event:ke,data:ie}=Ke(I);if(ie)try{const ce=JSON.parse(ie);if(ke==="done"){n=!0;const de=String(ce.question||"");de&&(N.value[t]=de),S.value[t]=!0}}catch{}}}catch{R.value[t]="Unable to generate question right now.",S.value[t]=!0}finally{!n&&!R.value[t]&&(S.value[t]=N.value[t].trim().length>0),O.value[t]=!1}}function Gt(e,a){i.value[e]=a,x.value[e]=null}function Wt(e,a){i.value[e]=a,x.value[e]=null}function Jt(e,a){const t=i.value[e],n=Array.isArray(t)?t.slice():[],r=n.indexOf(a);r>=0?n.splice(r,1):n.push(a),i.value[e]=n,n.length&&(x.value[e]=null)}function Yt(e,a){return i.value[e]===a?"border-primary bg-orange-50 text-primary":"border-slate-200 text-slate-500 hover:border-slate-300 hover:text-slate-700"}function Ht(e,a){return(Array.isArray(i.value[e])?i.value[e]:[]).includes(a)?"border-emerald-400 bg-emerald-50 text-emerald-600":"border-slate-200 text-slate-500 hover:border-slate-300 hover:text-slate-700"}function le(e){return x.value[e]?"border-rose-300 bg-rose-50/40":"border-slate-200"}function _e(e){return e.name.trim().toLowerCase()==="length type"}function Ge(e){const t=(Array.isArray(i.value[e.id])?i.value[e.id]:[])[0];if(!t)return 0;const n=(e.choices||[]).findIndex(r=>h(r)===t);return n>=0?n:0}function We(e,a,t){if(!t.length){i.value[e]=[];return}const n=Math.min(Math.max(a,0),t.length-1),r=t[n];r&&(i.value[e]=[h(r)],x.value[e]=null)}function Xt(){const e=$.value;let a=!0;return e.forEach(t=>{if(!t.required||t.type==="aiQuestion")return;if(t.type==="slider"&&(i.value[t.id]===void 0||i.value[t.id]===null)&&(i.value[t.id]=0),t.type==="length"){const l=i.value[t.id];if((l==null||String(l).trim()==="")&&t.choices?.length){const c=t.choices[0];c&&(i.value[t.id]=h(c))}}if(t.type==="multiple_choice"&&_e(t)){const l=i.value[t.id];if(!(Array.isArray(l)?l:[]).length&&t.choices?.length){const b=t.choices[0];b&&(i.value[t.id]=[h(b)])}}const n=i.value[t.id];(Array.isArray(n)?n.length>0:n!=null&&String(n).trim()!=="")?x.value[t.id]=null:(x.value[t.id]="This field is required.",a=!1)}),a}function Je(e,a){const t=String(a),n=(e.choices||[]).find(l=>h(l)===t);if(n)return n.name;const r=(e.choices||[]).find(l=>String(l.id)===t);return r?r.name:t}function Zt(e){if(e.type==="aiQuestion"){const a=Array.isArray(e.currentValues)?e.currentValues.map(t=>t&&typeof t=="object"&&!Array.isArray(t)?String(t.answer??"").trim():String(t).trim()).filter(t=>t.length>0):[];return a.length?a:["-"]}if(e.type==="sourceFile"){if(e.currentValue===void 0||e.currentValue===null)return["-"];if(typeof e.currentValue=="object"&&!Array.isArray(e.currentValue)){const a=e.currentValue;return[a.fileName||a.reference||"-"]}return[String(e.currentValue)]}if(e.type==="multiple_choice"){const t=(Array.isArray(e.currentValues)?e.currentValues:e.currentValue!==void 0&&e.currentValue!==null&&String(e.currentValue).trim()!==""?[e.currentValue]:[]).map(n=>Je(e,n));return t.length?t:["-"]}if(e.type==="choice"||e.type==="length")return e.currentValue===void 0||e.currentValue===null||String(e.currentValue).trim()===""?["-"]:[Je(e,e.currentValue)];if(e.type==="language"){if(e.currentValue===void 0||e.currentValue===null||String(e.currentValue).trim()==="")return["-"];const a=String(e.currentValue);return[ft[a]??a]}return e.currentValue===void 0||e.currentValue===null||String(e.currentValue).trim()===""?["-"]:[String(e.currentValue)]}function ea(e){const a=w.value.findIndex(t=>String(t.id)===String(e));a<0||oe(a)}return M([w,()=>C.query.step],()=>{if(!w.value.length)return;const e=St(C.query.step),a=w.value.findIndex(t=>String(t.id)===e);a>=0&&(k.value=a),B(e)},{immediate:!0}),oa(()=>{C.query.step||B("start")}),M([p,v],async()=>{!p.value||!U.value||await Ee(v.value)},{immediate:!0}),M([v,p,g],async()=>{se.value&&await qe()},{immediate:!0}),M(()=>C.query.templateId,()=>{const e=Number(Ae.value);!e||Number.isNaN(e)||p.value!==e&&(p.value=e)},{immediate:!0}),M(()=>C.query.bookTemplateId,()=>{const e=Number(Ce.value);!e||Number.isNaN(e)||g.value!==e&&(g.value=e)},{immediate:!0}),M([()=>v.value,$,()=>p.value],()=>
5{!p.value||!U.value||$.value.forEach(e=>{if(e.type!=="aiQuestion")return;(e.questions||[]).some(t=>z(e.id,t.id).trim().length>0)&&(W.value[ue(v.value,e.id)]=!0),(e.questions||[]).forEach(t=>{z(e.id,t.id).trim().length>0&&(S.value[Q(e.id,t.id)]=!0)})})},{immediate:!0}),M(p,(e,a)=>{!a||!e||e===a||(j.value={},Z.value={},P.value={},ee.value={},i.value={},x.value={},N.value={},O.value={},R.value={},S.value={},W.value={},J.value={},L.value={},te.value={},K.value={},g.value=null,Y.value=null,G.value="",me.value="",B(v.value))}),(e,a)=>(o(),s("div",ca,[u("div",da,[u("div",va,[u("div",pa,[a[0]||(a[0]=u("div",{class:"absolute left-4 right-4 top-4 hidden h-px bg-slate-200 sm:block z-0"},null,-1)),u("div",{class:"absolute left-4 top-4 hidden h-px bg-primary sm:block z-0",style:at({width:`${yt.value}%`})},null,4),u("div",{class:"grid gap-4",style:at(ht.value)},[(o(!0),s(f,null,_(w.value,(t,n)=>(o(),s("button",{key:kt(t),type:"button",class:"group relative z-10 flex flex-col items-center gap-2 text-center",disabled:V.value,onClick:r=>oe(n)},[u("span",{class:A(["flex h-9 w-9 items-center justify-center rounded-full border text-xs font-semibold transition",qt(n)])},d(n+1),3),u("span",{class:A(["text-[11px] font-semibold uppercase tracking-[0.18em] transition",Et(n)])},d(wt(t)),3)],8,ma))),128))],4)]),u("div",ya,[u("div",null,[u("p",ha,"Step "+d(k.value+1),1),u("h2",ga,d(gt.value),1),Te.value?(o(),s("p",ba,d(Te.value),1)):F("",!0)]),re.value?(o(),s("div",xa,[ua(ct)?(o(),s("div",fa,[(o(),s(f,null,_(3,t=>u("div",{key:t,class:"h-44 animate-pulse rounded-2xl border border-slate-200 bg-slate-100"})),64))])):(o(),s("div",_a,[(o(!0),s(f,null,_(mt.value,t=>(o(),s("button",{key:t.id,type:"button",class:A(["group relative flex h-full flex-col gap-4 roun
5ded-2xl border p-5 text-left transition",Lt(t.id)]),onClick:n=>Tt(t.id)},[u("div",wa,[u("div",Sa,[je(t)?(o(),s("img",{key:0,src:je(t),alt:t.name,class:"h-full w-full object-cover"},null,8,Aa)):(o(),s("span",Ca,d(t.name?.charAt(0)||"?"),1))]),u("div",null,[u("p",Ta,d(t.name),1)])]),u("p",Va,d(t.shortDescription||"No description yet."),1)],10,ka))),128))])),u("div",Ia,[u("button",{type:"button",class:"rounded-btn bg-primary px-6 py-3 text-sm font-semibold text-white shadow-md shadow-orange-200/70 transition enabled:hover:-translate-y-0.5 disabled:opacity-50",disabled:!p.value||V.value,onClick:Fe},[V.value?(o(),s("span",$a,[nt(et,{size:"sm",color:"white"}),a[1]||(a[1]=ve(" Loading... ",-1))])):(o(),s("span",Qa,"Continue"))],8,Na)])])):(o(),s("div",Fa,[se.value?(o(),s("div",qa,[pe.value?(o(),s("div",Ea,[(o(),s(f,null,_(3,t=>u("div",{key:t,class:"h-40 animate-pulse rounded-2xl border border-slate-200 bg-slate-100"})),64))])):G.value?(o(),s("div",La,d(G.value),1)):Qe.value.length?(o(),s("div",ja,[(o(!0),s(f,null,_(Qe.value,t=>(o(),s("section",{key:t.id,class:"overflow-hidden rounded-2xl border border-slate-200 bg-white"},[u("header",Pa,[u("h3",Ua,d(t.name),1),u("button",{type:"button",class:"text-xs font-semibold text-primary transition hover:opacity-80",onClick:n=>ea(t.id)}," Edit ",8,Ba)]),t.fields.length?(o(),s("div",za,[(o(!0),s(f,null,_(t.fields,n=>(o(),s("div",{key:n.id,class:"grid gap-2 px-5 py-3 sm:grid-cols-[220px_minmax(0,1fr)] sm:items-start"},[u("p",Da,d(n.name),1),u("div",null,[(o(!0),s(f,null,_(Zt(n),(r,l)=>(o(),s("p",{key:`${n.id}:${l}`,class:"break-words text-sm font-medium text-slate-800"},d(r),1))),128))])]))),128))])):(o(),s("div",Ma,"No values in this step yet."))]))),128))])):(o(),s("div",Oa,[...a[2]||(a[2]=[u("p",{class:"text-sm text-slate-500"},"No summary data available yet.",-1)])]))])):(o(),s("div",Ra,[Ve.value?(o(),s("div",Ka,[(o(),s(f,null,_(4,t=>u("div",{key:t,class:"h-12 animate-pulse rounded-xl border border-slate-200 bg-slate-100"})),64))])):Ie.value?(o(),s("div",Ga,d(Ie.value),1)):$.value.length?(o(),s("div",Wa,[(o(!0),s(f,null,_($.value,t=>(o(),s("div",{key:t.id,"data-template-field-id":t.id,class:"space-y-3"},[t.type!=="aiQuestion"?(o(),s("p",Ya,[ve(d(t.name)+" ",1),t.required?(o(),s("span",Ha,"*")):F("",!0)])):F("",!0),t.type!=="aiQuestion"&&x.value[t.id]?(o(),s("p",Xa,d(x.value[t.id]),1)):F("",!0),t.type==="choice"?(o(),s("div",Za,[(o(!0),s(f,null,_(t.choices||[],n=>(o(),s("button",{key:h(n),type:"button",class:A(["rounded-full border px-4 py-2 text-xs font-semibold transition",Yt(t.id,h(n))]),onClick:r=>Wt(t.id,h(n))},d(n.name),11,en))),128))])):t.type==="multiple_choice"&&_e(t)?(o(),s("div",tn,[u("input",{type:"range",min:"0",max:Math.max((t.choices?.length||1)-1,0),class:"w-full accent-primary",value:Ge(t),onInput:n=>We(t.id,Number(n.target.value),t.choices||[])},null,40,an),u("div",nn,[(o(!0),s(f,null,_(t.choices||[],(n,r)=>(o(),s("button",{key:h(n),type:"button",class:A(["transition",Ge(t)===r?"text-primary font-semibold":"text-slate-500"]),onClick:l=>We(t.id,r,t.choices||[])},d(n.name),11,rn))),128))])])):t.type==="multiple_choice"?(o(),s("div",sn,[(o(!0),s(f,null,_(t.choices||[],n=>(o(),s("button",{key:h(n),type:"button",class:A(["rounded-full border px-4 py-2 text-xs font-semibold transition",Ht(t.id,h(n))]),onClick:r=>Jt(t.id,h(n))},d(n.name),11,on))),128))])):t.type==="slider"?(o(),s("div",un,[u("input",{type:"range",min:"0",max:(t.choices?.length||2)-1,class:"w-full accent-primary",value:jt(t.id),onInput:n=>Gt(t.id,Number(n.target.value))},null,40,ln),u("div",cn,[(o(!0),s(f,null,_(t.choices||[],n=>(o(),s("span",{key:h(n)},d(n.name),1))),128))])])):t.type==="length"?(o(),s("div",dn,[u("input",{type:"range",min:"0",max:Math.max((t.choices?.length||1)-1,0),class:"w-full accent-primary",value:Pe(t),onInput:n=>Ue(t.id,Number(n.target.value),t.choices||[])},null,40,vn),u("div",pn,[(o(!0),s(f,null,_(t.choices||[],(n,r)=>(o(),s("button",{key:h(n),type:"button",class:A(["transition",Pe(t)===r?"text-primary font-semibold":"text-slate-500"]),onClick:l=>Ue(t.id,r,t.choices||[])},d(n.name),11,mn))),128))])])):t.type==="aiQuestion"?(o(),s("div",yn,[a[5]||(a[5]=u("div",{class:"mb-4 flex items-center gap-3"},[u("div",{class:"h-px flex-1 bg-slate-200"}),u("p",{class:"text-[11px] font-semibold uppercase tracking-[0.22em] text-slate-500"},"AI Assistant"),u("div",{class:"h-px flex-1 bg-slate-200"})],-1)),u("div",hn,[De(v.value,t.id)?F("",!0):(o(),s("button",{key:0,t
5ype:"button",class:"absolute inset-0 z-10 flex items-center justify-center rounded-2xl border border-dashed border-primary/40 bg-white/65 px-4 text-center backdrop-blur-[1px]",disabled:Me(v.value,t.id),onClick:n=>Bt(t)},[u("span",bn,d(Me(v.value,t.id)?"Saving step...":"Click here to start AI questions"),1)],8,gn)),u("div",{class:A(["space-y-5 transition",{"pointer-events-none select-none blur-[3px] opacity-70":!De(v.value,t.id)}])},[(o(!0),s(f,null,_(t.questions||[],(n,r)=>(o(),s("div",{key:`${t.id}:${n.id}`,class:"space-y-3"},[u("div",xn,[a[4]||(a[4]=u("div",{class:"mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-primary/25 bg-primary/10 text-[10px] font-bold uppercase tracking-[0.08em] text-primary"}," AI ",-1)),u("div",fn,[z(t.id,n.id)?(o(),s("p",_n,d(z(t.id,n.id)),1)):(o(),s("span",kn,[...a[3]||(a[3]=[u("span",{class:"h-1.5 w-1.5 animate-bounce rounded-full bg-slate-400 [animation-delay:0ms]"},null,-1),u("span",{class:"h-1.5 w-1.5 animate-bounce rounded-full bg-slate-400 [animation-delay:140ms]"},null,-1),u("span",{class:"h-1.5 w-1.5 animate-bounce rounded-full bg-slate-400 [animation-delay:280ms]"},null,-1)])]))])]),u("div",wn,[u("div",Sn,[u("textarea",{class:A(["w-full rounded-xl border bg-white px-4 py-3 text-sm text-slate-700 focus:border-primary focus:outline-none",le(t.id)]),rows:"4",placeholder:"Answer...",disabled:!Ot(t.id,n.id),value:Dt(t,r),onInput:l=>Mt(t.id,r,l.target.value,(t.questions||[]).length)},null,42,An)]),u("div",Cn,d(_t.value),1)]),Re(t.id,n.id)?(o(),s("p",Tn,d(Re(t.id,n.id)),1)):F("",!0)]))),128))],2)])])):t.type==="sourceFile"?(o(),s("div",Vn,[u("div",In,[u("label",Nn,[u("input",{type:"file",class:"hidden",disabled:fe(t.id),onChange:n=>Pt(t,n)},null,40,$n),ve(" "+d(fe(t.id)?"Uploading...":"Upload source file"),1)]),ze(t.id)?(o(),s("p",Qn,d(ze(t.id)),1)):F("",!0)]),Be(t.id)?(o(),s("p",Fn,d(Be(t.id)),1)):F("",!0),a[6]||(a[6]=u("p",{class:"text-xs text-slate-500"}," The uploaded file can be used as source material for the book content. ",-1))])):t.type==="textarea"?(o(),s("div",qn,[u("textarea",{class:A(["w-full rounded-xl border px-4 py-3 text-sm text-slate-700 focus:border-primary focus:outline-none",le(t.id)]),rows:"4",value:be(t.id),onInput:n=>xe(t.id,n.target.value)},null,42,En)])):t.type==="language"?(o(),s("div",Ln,[u("select",{class:A(["w-full rounded-xl border bg-white px-4 py-3 text-sm text-slate-700 focus:border-primary focus:outline-none",le(t.id)]),value:be(t.id),onChange:n=>xe(t.id,n.target.value)},[a[7]||(a[7]=u("option",{disabled:"",value:""},"Select language",-1)),(o(),s(f,null,_(ye,n=>u("option",{key:n.value,value:n.value},d(n.label),9,Pn)),64))],42,jn)])):(o(),s("div",Un,[u("input",{type:"text",class:A(["w-full rounded-xl border px-4 py-3 text-sm text-slate-700 focus:border-primary focus:outline-none",le(t.id)]),value:be(t.id),onInput:n=>xe(t.id,n.target.value)},null,42,Bn)]))],8,Ja))),128))])):(o(),s("div",zn,[...a[8]||(a[8]=[u("p",{class:"text-sm text-slate-500"},"No fields for this step yet.",-1)])]))]))])),re.value?F("",!0):(o(),s("div",Dn,[u("button",{type:"button",class:"rounded-btn border border-slate-200 px-5 py-2.5 text-sm font-semibold text-slate-600 transition hover:border-slate-300 hover:text-slate-800",disabled:V.value,onClick:Ct}," Back ",8,Mn),se.value?(o(),s("button",{key:1,type:"button",class:"rounded-btn bg-primary px-6 py-3 text-sm font-semibold text-white shadow-md shadow-orange-200/70 transition enabled:hover:-translate-y-0.5 disabled:opacity-50",disabled:ae.value||V.value,onClick:Ft},d(ae.value?"Creating...":"Create a book"),9,Gn)):(o(),s("button",{key:0,type:"button",class:"rounded-btn bg-primary px-6 py-3 text-sm font-semibold text-white shadow-md shadow-orange-200/70 transition enabled:hover:-translate-y-0.5 disabled:opacity-50",disabled:Ve.value||bt.value||V.value||Ne.value||$e.value,onClick:Fe},[V.value||Ne.value||$e.value?(o(),s("span",Rn,[nt(et,{size:"sm",color:"white"}),a[9]||(a[9]=ve(" Loading... ",-1))])):(o(),s("span",Kn,"Continue"))],8,On))]))])])])]))}});export{Hn as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.