1import{e as be,h as ye,E as O,B as xe,m as r,i as he,c as i,a as l,l as b,F as q,r as P,y as ke,q as u,v as j,b as s,w as c,n as v,x as we,a0 as W,d as p,a1 as S,J as Z,a3 as J,t as y,p as _e,o as n,A as I}from"./D3mXZbvm.js";import{I as w}from"./CSXwf1OI.js";import{C as x}from"./1DPIgRXm.js";import{B as h}from"./CbyiM6aK.js";import{_ as Ce}from"./DlAUqK2U.js";import"./BodJxGTV.js";import"./D0HDmefO.js";const Ve={class:"min-h-screen bg-gray-50 py-8 px-4"},Be={class:"max-w-3xl mx-auto"},Se={class:"rounded-2xl border border-gray-200 bg-white p-6 md:p-8 shadow-xl"},Ie={class:"border-b border-gray-200 mb-6"},Ue={class:"-mb-px flex space-x-8"},Te=["onClick"],Ae={class:"space-y-4"},Ee={class:"space-y-1.5"},qe={class:"flex gap-2"},Pe=["value"],Fe={class:"space-y-1.5"},Me=["value"],Ne={class:"space-y-1.5"},$e={class:"flex items-center gap-1.5"},ze={class:"group relative inline-block ml-1"},Ge={class:"flex gap-2"},Le={class:"group relative"},De={key:0,class:"absolute bottom-full right-0 mb-2 w-48 p-2 bg-gray-900 text-white text-[10px] rounded shadow-lg opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10"},Re={class:"space-y-4"},Oe={class:"space-y-1.5"},je={class:"space-y-1.5"},Je={class:"space-y-1.5"},Ye={class:"flex items-center gap-2"},Xe={class:"flex items-center gap-2"},He={class:"space-y-1.5"},Ke={class:"space-y-2"},Qe=["onUpdate:modelValue"],We=["onClick"],Ze={class:"space-y-4"},et={class:"space-y-3"},tt={class:"flex items-center gap-2"},lt={class:"flex items-center gap-2"},ot={key:0,class:"ml-6"},at={class:"flex items-center gap-2"},st={key:1,class:"ml-6"},nt={key:0,class:"mt-1 text-sm text-gray-700"},rt={class:"mt-8 pt-6 border-t border-gray-200"},it={key:0,class:"relative px-4"},ut=["max"],dt={class:"relative flex justify-between mt-2 mx-[10px]"},ct={class:"absolute flex flex-col items-center -translate-x-1/2 left-1/2 w-24"},mt=["onClick"],vt={key:1,class:"text-sm text-gray-500"},pt={class:"mt-10"},gt={key:0,class:"mt-4 text-sm text-red-500 text-center font-medium"},ft={key:0,class:"fixed inset-0 z-50 flex items-center justify-center"},bt={class:"relative bg-white rounded-2xl p-6 max-w-md w-full mx-4 shadow-xl"},yt={class:"text-gray-600 mb-2"},xt={class:"flex gap-3"},ht={key:1,class:"fixed inset-0 z-50 flex items-center justify-center"},kt={class:"relative bg-white rounded-2xl p-6 max-w-md w-full mx-4 shadow-xl"},wt={class:"text-gray-700 mb-6"},_t={class:"flex gap-3"},Ct={key:2,class:"fixed inset-0 z-50 flex items-center justify-center"},Vt={class:"relative bg-white rounded-2xl p-6 max-w-md w-full mx-4 shadow-xl"},Bt={class:"flex gap-3"},St=be({__name:"index",setup(It){const $=ye(),Y=O(()=>$.user?.group==="group_default"),{request:z,get:X}=xe(),ee=[{id:"basic",name:"Basic Info"},{id:"advanced",name:"Advanced Options"},{id:"source",name:"Source"}],_=r("basic"),t=r({title:"",subtitle:"",style:"",language:"en",author:"",topic:"",publisher:"",link:"",dedication:"",acknowledgements:"",bibliography:"",introduction:!0,epilogue:!1,recommendedBooks:[]}),C=r(""),m=r("none"),G=r(""),U=r(null),te=r(null),H=r([]),K=r({}),V=r([]),B=r(0),k=r(!1),L=r(!1),f=r(null),F=r(!1),M=r(null),D=r(!1),T=r(!1),Q=r(0),A=r(!1),le=O(()=>V.value[B.value]),R=O(()=>t.value.style==="__custom__"?C.value:t.value.style);function oe(){t.value.recommendedBooks.push("")}function ae(a){t.value.recommendedBooks.splice(a,1)}function se(a){const e=a.target;if(e.files&&e.files.length>0){const g=e.files[0],o=new FileReader;o.onload=d=>{const E=d.target.result,pe=btoa(new Uint8Array(E).reduce((ge,fe)=>ge+String.fromCharCode(fe),""));U.value={name:g.name,type:g.type,content:pe}},o.readAsArrayBuffer(g)}}async function ne(){try{const a=await X("/api/v3/book/options");H.value=a.styles||[],K.value=a.languages||{}}catch(a){console.error("Failed to fetch options:",a)}}async function re(){try{const a=await X("/api/v3/book/presets");V.value=a||[];const e=V.value.findIndex(g=>g.default);e!==-1&&(B.value=e)}catch(a){console.error("Failed to fetch presets:",a)}}async function ie(){if(!(!t.value.language||!t.value.title||!t.value.subtitle)){L.value=!0;try{const a=await z("/api/v3/topics/generate",{method:"POST",body:JSON.stringify({language:t.value.language,bookTitle:t.value.title,bookSubTitle:t.value.subtitle,style:R.value||null})});a.ok&&a.data?.topics&&(t.value.topic=a.data.topics)}catch(a){console.error("Failed to generate topic:",a)}finally{L.value=!1}}}async function ue(){f.value=null,k.value=!0;try{if(!$.isAuthenticated){await N(!0);return}if(Y.value){await N(!0);return}const a=await z("/api/v3/me/books/get_incomplete");if(a.ok&&a.data?.id){M.value=a.data,F.value=!0,k.value=!1;return}await N()}catch(a){f.value=a?.message||"An error occurred",k.value=!1}}async function de(){M.value&&await I(`/services/generate/${M.value.id}`)}async function ce(){D.value=!0,F.value=!1,await N()}function me(){T.value=!1,I("/pricing")}function ve(){A.value=!1,I("/my-books")}async function N(a=!1){if(k.value=!0,f.value=null,!t.value.title||!t.value.subtitle||!R.value||!t.value.language||!t.value.author||!t.value.topic){_.value="basic",f.value="Please fill in all required fields on the Basic Info tab.",k.value=!1,window.scrollTo({top:0,behavior:"smooth"});return}try{let e={type:m.value,text:null,file:null};m.value==="text"?e.text=G.value:m.value==="file"&&U.value&&(e.file=U.value);const g={title:t.value.title,subtitle:t.value.subtitle,style:R.value,author:t.value.author,language:t.value.language,acknowledgements:t.value.acknowledgements,dedication:t.value.dedication,recommendedBooks:t.value.recommendedBooks.filter(d=>d.trim()!==""),presetId:le.value?.id||"1",publisher:t.value.publisher,link:t.value.link,introduction:t.value.introduction,epilogue:t.value.epilogue,topic:t.value.topic,bibliography:t.value.bibliography,context:e,demo:a},o=await z("/api/v3/books/generate",{method:"POST",body:g});o.ok&&o.data?.id?$.isAuthenticated?a?await I("/my-books"):await I(`/services/generate/${o.data.id}`):(localStorage.setItem("bookId",o.data.id.toString()),await I("/registration")):o.status===403?o.data?.error==="not_enough_credit"?(Q.value=o.data?.cost||0,T.value=!0):o.data?.error==="generation_in_progress"?A.value=!0:f.value=o.data?.message||"Access denied":f.value=o.data?.message||"Failed to generate book"}catch(e){f.value=e?.message||"An error occurred while generating the book"}finally{k.value=!1,D.value=!1}}return he(()=>{ne(),re()}),(a,e)=>{const g=_e("font-awesome-icon");return n(),i("div",Ve,[l("div",Be,[l("div",Se,[e[37]||(e[37]=l("h1",{class:"text-2xl md:text-3xl font-black text-gray-900 mb-6 uppercase tracking-tight"},"Generate Book",-1)),l("div",Ie,[l("nav",Ue,[(n(),i(q,null,P(ee,o=>l("button",{key:o.id,onClick:d=>_.value=o.id,class:v(["py-2 px-1 border-b-2 font-medium text-sm transition-colors",_.value===o.id?"border-primary text-primary":"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"])},y(o.name),11,Te)),64))])]),l("form",{onSubmit:ke(ue,["prevent"]),novalidate:""},[u(l("div",Ae,[s(w,{modelValue:t.value.title,"onUpdate:modelValue":e[0]||(e[0]=o=>t.value.title=o),placeholder:"Enter book title",required:!0,"input-class":"transition-all",class:v({"!border-red-400":t.value.title.length>50}),maxlength:50},{label:c(()=>[s(x,{label:"Title","current-length":t.value.title.length,max:50,required:!0},null,8,["current-length"])]),_:1},8,["modelValue","class"]),s(w,{modelValue:t.value.subtitle,"onUpdate:modelValue":e[1]||(e[1]=o=>t.value.subtitle=o),placeholder:"Enter book subtitle",required:!0,"input-class":"transition-all",class:v({"!border-red-400":t.value.subtitle.length>100}),maxlength:100},{label:c(()=>[s(x,{label:"Subtitle","current-length":t.value.subtitle.length,max:100,required:!0},null,8,["current-length"])]),_:1},8,["modelValue","class"]),l("div",Ee,[s(x,{label:"Style","current-length":t.value.style==="__custom__"?C.value.length:t.value.style.length,max:30,required:!0},null,8,["current-length"]),l("div",qe,[u(l("select",{"onUpdate:modelValue":e[2]||(e[2]=o=>t.value.style=o),required:"",class:v(["select-standard",{"!border-red-400":(t.value.style==="__custom__"?C.value.length:t.value.style.length)>30}])},[(n(!0),i(q,null,P(H.value,o=>(n(),i("option",{key:o,value:o},y(o),9,Pe))),128)),e[24]||(e[24]=l("option",{value:"__custom__"},"+ Add custom style",-1))],2),[[W,t.value.style]])]),t.value.style==="__custom__"?(n(),we(w,{key:0,modelValue:C.value,"onUpdate:modelValue":e[3]||(e[3]=o=>C.value=o),placeholder:"Enter custom style",class:v(["mt-2",{"!border-red-400":C.value.length>30}]),maxlength:30},null,8,["modelValue","class"])):b("",!0)]),l("div",Fe,[e[25]||(e[25]=l("label",{class:"block text-sm font-medium text-gray-700 font-semibold"},[p(" Language "),l("span",{class:"text-red-500"},"*")],-1)),u(l("select",{"onUpdate:modelValue":e[4]||(e[4]=o=>t.value.language=o),required:"",class:"select-standard"},[(n(!0),i(q,null,P(K.value,(o,d)=>(n(),i("option",{key:d,value:d},y(o),9,Me))),128))],512),[[W,t.value.language]])]),s(w,{modelValue:t.value.author,"onUpdate:modelValue":e[5]||(e[5]=o=>t.value.author=o),label:"Author",placeholder:"Enter author name",required:!0,"label-class":"text-gray-700 font-semibold"},null,8,["modelValue"]),l("div",Ne,[l("div",$e,[s(x,{label:"Topic","current-length":t.value.topic.length,max:255,required:!0,class:"mb-0 flex-1"},{"after-label":c(()=>[l("div",ze,[s(g,{icon:"info-circle",class:"text-gray-400 hover:text-gray-600 cursor-help text-[10px]"}),e[26]||(e[26]=l("div",{class:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-48 p-2 bg-gray-900 text-white text-[10px] rounded shadow-lg op
1acity-0 group-hover:opacity-100 transition-opacity pointer-events-none z-10 font-normal"}," Topic is needed to help the best content generation. ",-1))])]),_:1},8,["current-length"])]),l("div",Ge,[s(w,{modelValue:t.value.topic,"onUpdate:modelValue":e[6]||(e[6]=o=>t.value.topic=o),placeholder:"Enter book topic",required:!0,class:"flex-1 space-y-0",maxlength:255},null,8,["modelValue"]),l("div",Le,[s(h,{variant:"secondary",size:"sm",class:"shrink-0 h-[38px]",onClick:ie,loading:L.value,disabled:!t.value.language||!t.value.title||!t.value.subtitle},{default:c(()=>[s(g,{icon:"wand-magic-sparkles",class:"mr-1.5"}),e[27]||(e[27]=p(" AI Suggest ",-1))]),_:1},8,["loading","disabled"]),!t.value.language||!t.value.title||!t.value.subtitle?(n(),i("div",De," Please fill in Language, Title, and Subtitle to enable AI Suggest. ")):b("",!0)])])])],512),[[j,_.value==="basic"]]),u(l("div",Re,[s(w,{modelValue:t.value.publisher,"onUpdate:modelValue":e[7]||(e[7]=o=>t.value.publisher=o),placeholder:"Enter publisher name",class:v({"!border-red-400":t.value.publisher.length>30}),maxlength:30},{label:c(()=>[s(x,{label:"Publisher","current-length":t.value.publisher.length,max:30},null,8,["current-length"])]),_:1},8,["modelValue","class"]),s(w,{modelValue:t.value.link,"onUpdate:modelValue":e[8]||(e[8]=o=>t.value.link=o),placeholder:"https://example.com",type:"url",class:v({"!border-red-400":t.value.link.length>50}),maxlength:50},{label:c(()=>[s(x,{label:"Insert Link","current-length":t.value.link.length,max:50},null,8,["current-length"])]),_:1},8,["modelValue","class"]),l("div",Oe,[s(x,{label:"Dedication","current-length":t.value.dedication.length,max:100},null,8,["current-length"]),u(l("textarea",{"onUpdate:modelValue":e[9]||(e[9]=o=>t.value.dedication=o),rows:"3",placeholder:"I write this book for...",class:v(["block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder-gray-400 shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary transition-all",{"!border-red-400":t.value.dedication.length>100}]),maxlength:"100"},null,2),[[S,t.value.dedication]])]),l("div",je,[s(x,{label:"Acknowledgements","current-length":t.value.acknowledgements.length,max:2500},null,8,["current-length"]),u(l("textarea",{"onUpdate:modelValue":e[10]||(e[10]=o=>t.value.acknowledgements=o),rows:"3",placeholder:"Enter acknowledgements",class:v(["block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder-gray-400 shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary transition-all",{"!border-red-400":t.value.acknowledgements.length>2500}]),maxlength:"2500"},null,2),[[S,t.value.acknowledgements]])]),l("div",Je,[s(x,{label:"Bibliography","current-length":t.value.bibliography.length,max:2e3},null,8,["current-length"]),u(l("textarea",{"onUpdate:modelValue":e[11]||(e[11]=o=>t.value.bibliography=o),rows:"3",placeholder:"Enter bibliography",class:v(["block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder-gray-400 shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary transition-all",{"!border-red-400":t.value.bibliography.length>2e3}]),maxlength:"2000"},null,2),[[S,t.value.bibliography]])]),l("div",Ye,[u(l("input",{type:"checkbox",id:"introduction","onUpdate:modelValue":e[12]||(e[12]=o=>t.value.introduction=o),class:"h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"},null,512),[[Z,t.value.introduction]]),e[28]||(e[28]=l("label",{for:"introduction",class:"text-sm font-medium text-gray-700"}," Introduction ",-1))]),l("div",Xe,[u(l("input",{type:"checkbox",id:"epilogue","onUpdate:modelValue":e[13]||(e[13]=o=>t.value.epilogue=o),class:"h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary"},null,512),[[Z,t.value.epilogue]]),e[29]||(e[29]=l("label",{for:"epilogue",class:"text-sm font-medium text-gray-700"}," Epilogue ",-1))]),l("div",He,[e[30]||(e[30]=l("label",{class:"block text-sm font-medium text-gray-700 font-semibold"}," Recommended Books ",-1)),l("div",Ke,[(n(!0),i(q,null,P(t.value.recommendedBooks,(o,d)=>(n(),i("div",{key:d,class:"flex gap-2"},[u(l("input",{"onUpdate:modelValue":E=>t.value.recommendedBooks[d]=E,type:"text",placeholder:"Enter book title",class:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder-gray-400 shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"},null,8,Qe),[[S,t.value.recommendedBooks[d]]]),l("button",{type:"button",onClick:E=>ae(d),class:"px-3 py-2 text-red-500 hover:text-red-700 transition-colors"}," â ",8,We)]))),128)),l("button",{type:"button",onClick:oe,class:"text-sm text-primary hover:text-primary/80 font-medium"}," + Add recommended book ")])])],512),[[j,_.value==="advanced"]]),u(l("div",Ze,[l("div",et,[e[35]||(e[35]=l("label",{class:"block text-sm font-medium text-gray-700 font-semibold"}," Source ",-1)),l("div",tt,[u(l("input",{type:"radio",id:"source-none",value:"none","onUpdate:modelValue":e[14]||(e[14]=o=>m.value=o),class:"h-4 w-4 border-gray-300 text-primary focus:ring-primary"},null,512),[[J,m.value]]),e[31]||(e[31]=l("label",{for:"source-none",class:"text-sm text-gray-700"},"None",-1))]),l("div",lt,[u(l("input",{type:"radio",id:"source-text",value:"text","onUpdate:modelValue":e[15]||(e[15]=o=>m.value=o),class:"h-4 w-4 border-gray-300 text-primary focus:ring-primary"},null,512),[[J,m.value]]),e[32]||(e[32]=l("label",{for:"source-text",class:"text-sm text-gray-700"},"Text Input",-1))]),m.value==="text"?(n(),i("div",ot,[u(l("textarea",{"onUpdate:modelValue":e[16]||(e[16]=o=>G.value=o),rows:"5",placeholder:"Enter your source text...",class:"block w-full rounded-md border border-gray-300 px-3 py-2 text-sm placeholder-gray-400 shadow-sm focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"},null,512),[[S,G.value]])])):b("",!0),l("div",at,[u(l("input",{type:"radio",id:"source-file",value:"file","onUpdate:modelValue":e[17]||(e[17]=o=>m.value=o),class:"h-4 w-4 border-gray-300 text-primary focus:ring-primary"},null,512),[[J,m.value]]),e[33]||(e[33]=l("label",{for:"source-file",class:"text-sm text-gray-700"},"File Input",-1))]),m.value==="file"?(n(),i("div",st,[l("input",{type:"file",ref_key:"fileInput",ref:te,accept:".pdf,.txt",onCh
1ange:se,class:"block w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded-md file:border-0 file:text-sm file:font-medium file:bg-primary file:text-white hover:file:bg-primary/90 file:cursor-pointer"},null,544),e[34]||(e[34]=l("p",{class:"mt-1 text-xs text-gray-500"},"Accepted formats: PDF, TXT",-1)),U.value?(n(),i("p",nt," Selected: "+y(U.value.name),1)):b("",!0)])):b("",!0)])],512),[[j,_.value==="source"]]),l("div",rt,[e[36]||(e[36]=l("label",{class:"block text-sm font-medium text-gray-700 font-semibold mb-4"}," Length ",-1)),V.value.length>0?(n(),i("div",it,[u(l("input",{type:"range",min:0,max:V.value.length-1,"onUpdate:modelValue":e[18]||(e[18]=o=>B.value=o),class:"custom-range w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer accent-primary relative z-10"},null,8,ut),[[S,B.value,void 0,{number:!0}]]),l("div",dt,[(n(!0),i(q,null,P(V.value,(o,d)=>(n(),i("div",{key:o.id,class:"flex flex-col items-center relative"},[l("div",ct,[l("span",{class:v([B.value===d?"text-primary font-bold":"text-gray-500 font-medium","cursor-pointer text-[11px] md:text-xs transition-all duration-200 text-center whitespace-nowrap"]),onClick:E=>B.value=d},y(o.name),11,mt)])]))),128))])])):(n(),i("div",vt," Loading presets... "))]),l("div",pt,[s(
1h,{type:"submit",variant:"primary",block:"",class:"py-3",loading:k.value},{default:c(()=>[p(y(Y.value?"Try out free":"Generate Book"),1)]),_:1},8,["loading"])]),f.value?(n(),i("p",gt,y(f.value),1)):b("",!0)],32)])]),F.value?(n(),i("div",ft,[l("div",{class:"fixed inset-0 bg-black/50",onClick:e[19]||(e[19]=o=>F.value=!1)}),l("div",bt,[e[41]||(e[41]=l("h2",{class:"text-xl font-bold text-gray-900 mb-4"},"Unfinished Book Found",-1)),l("p",yt,[e[38]||(e[38]=p(" You have an unfinished book: ",-1)),l("strong",null,y(M.value?.title),1)]),e[42]||(e[42]=l("p",{class:"text-gray-600 mb-6"}," Do you want to continue it, or would you like to generate a new one and delete the old one? ",-1)),e[43]||(e[43]=l("p",{class:"text-sm text-gray-500 mb-6"}," (Starting a new one will delete the old.) ",-1)),l("div",xt,[s(h,{variant:"secondary",block:"",onClick:de},{default:c(()=>[...e[39]||(e[39]=[p(" Continue ",-1)])]),_:1}),s(h,{variant:"primary",block:"",onClick:ce,loading:D.value},{default:c(()=>[...e[40]||(e[40]=[p(" Create New ",-1)])]),_:1},8,["loading"])])])])):b("",!0),T.value?(n(),i("div",ht,[l("div",{class:"fixed inset-0 bg-black/50",onClick:e[20]||(e[20]=o=>T.value=!1)}),l("div",kt,[e[47]||(e[47]=l("h2",{class:"text-xl font-bold text-gray-900 mb-4"},"Not Enough Credits",-1)),e[48]||(e[48]=l("p",{class:"text-gray-600 mb-4"}," You don't have enough credits to generate this book. ",-1)),l("p",wt,[e[44]||(e[44]=l("strong",null,"Cost:",-1)),p(" "+y(Q.value.toLocaleString())+" credits ",1)]),l("div",_t,[s(h,{variant:"secondary",block:"",onClick:e[21]||(e[21]=o=>T.value=!1)},{default:c(()=>[...e[45]||(e[45]=[p(" Cancel ",-1)])]),_:1}),s(h,{variant:"primary",block:"",onClick:me},{default:c(()=>[...e[46]||(e[46]=[p(" Get Credits ",-1)])]),_:1})])])])):b("",!0),A.value?(n(),i("div",Ct,[l("div",{class:"fixed inset-0 bg-black/50",onClick:e[22]||(e[22]=o=>A.value=!1)}),l("div",Vt,[e[51]||(e[51]=l("h2",{class:"text-xl font-bold text-gray-900 mb-4"},"Generation In Progress",-1)),e[52]||(e[52]=l("p",{class:"text-gray-600 mb-6"}," Please wait while your previous book is finished generating. ",-1)),l("div",Bt,[s(h,{variant:"secondary",block:"",onClick:e[23]||(e[23]=o=>A.value=!1)},{default:c(()=>[...e[49]||(e[49]=[p(" Cancel ",-1)])]),_:1}),s(h,{variant:"primary",block:"",onClick:ve},{default:c(()=>[...e[50]||(e[50]=[p(" Go to My Books ",-1)])]),_:1})])])])):b("",!0)])}}}),Mt=Ce(St,[["__scopeId","data-v-153e1a4d"]]);export{Mt 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.