1import{j as e,n as F,q as zt,K as nt,a1 as Gt,s as Bt,a2 as Wt,D as gt,af as Yt,N as xt,O as ot,a3 as ft,a4 as qt,a5 as yt,ag as Kt,ah as Vt,S as Ae,I as Xt,y as it,z as lt,a8 as Qt,a9 as Zt,aa as ea,ab as ta,_ as aa,ac as ra,X as ct}from"./vendor-ui-CIS6Qz9y.js";import{i as sa,h as na,c as oa,r as s,a as bt}from"./vendor-react-CIGxEcP1.js";import{A as Ce,S as X}from"./app-layout-BfMDeSVd.js";import{C as ia}from"./template-picker-dialog-rPJW1Ig_.js";import{A as S,p as la,i as dt,C as mt,q as ca,s as da,o as Q,F as f,T as ma,j as O,u as de,W as ht,a as ha,P as ua}from"./preview-frame-utils-BRPnbMch.js";import{u as pa,a as P,b as ke,A as Ie}from"./index-BaHIFxRN.js";import{u as ga}from"./use-credits-status-CW4dKF4L.js";import{d as Se,c as ut,S as xa}from"./cover-letter-types-Be_4O--B.js";import"./vendor-supabase-C--0TtcN.js";import"./external-links-AIV8z4qi.js";import"./template-category-DGWH4ww2.js";import"./vendor-charts-DqS88uak.js";const Pe=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,fa={resume_export:"Export",cover_letter_export:"Cover Letter Export",ats_check:"ATS Check",enhance:"Enhance",generate:"Generate",skills_gap:"Skills Gap"},ya={personalInfo:{fullName:"Priya Nair",email:"[email protected]",phone:"+91 99887 11223",location:"Chennai, India",linkedin:"linkedin.com/in/priyanair",website:"priyanair.dev"},recipient:{name:"M.S. in Computer Science",title:"Admissions Committee",organization:"Stanford University",address:"Stanford, CA, USA"},date:"June 14, 2026",subject:"Application for M.S. in Computer Science",salutation:"Dear Admissions Committee,",paragraphs:["My fascination with machine learning began during my undergraduate capstone project, where I developed a Bengali handwritten text recogniser achieving 94.3% accuracy on a dataset I curated. That experience crystallised my ambition to advance AI systems that serve linguistically diverse communities â the driving force behind my application to the M.S. in Computer Science programme at Stanford University.","I completed my B.Tech in Information Technology from IIT Madras with a CGPA of 9.1/10, consistently ranking in the top 3% of my cohort. My research on self-supervised learning under Professor S. Ramakrishnan led to a paper accepted at CVPR 2025. Two years at Infosys building production-grade NLP pipelines has since given me hands-on experience deploying large-scale models responsibly.","I am particularly drawn to Stanford's AI Lab and Professor Fei-Fei Li's work on human-centred AI. The programme's emphasis on theoretical rigour combined with applied systems research aligns precisely with my goal of developing accessible language-AI infrastructure for Indic languages â a domain with over one billion speakers that remains severely under-resourced.","I am confident that Stanford's collaborative environment and research mentorship will enable me to make meaningful contributions to multilingual AI. I would be honoured to join your programme and carry forward the spirit of impactful, open research that defines Stanford."],closing:"Respectfully,"},ba={personalInfo:{fullName:"Priya Nair",email:"[email protected]",phone:"+91 99887 11223",location:"Chennai, India",linkedin:"linkedin.com/in/priyanair",website:"priyanair.dev"},recipient:{name:"Ph.D. in Computer Science",title:"Graduate Admissions Committee",organization:"Carnegie Mellon University",address:"Pittsburgh, PA, USA"},date:"June 14, 2026",subject:"Application for Ph.D. in Computer Science",salutation:"Dear Admissions Committee,",paragraphs:["My research journey began with a question that has since defined my academic focus: why do state-of-the-art NLP models fail catastrophically on Indic scripts despite decades of progress in English? This curiosity evolved into a systematic investigation that has led to two peer-reviewed publications, a patent filing, and an unwavering commitment to pursue doctoral research in multilingual AI at Carnegie Mellon University.","I completed my B.Tech in Information Technology from IIT Madras (CGPA 9.1/10, top 3% of cohort), followed by two years as an Applied Scientist at Amazon Alexa, where I built dialogue-state tracking systems for low-resource languages. Under Professor S. Ramakrishnan's mentorship I published a paper on self-supervised representation learning for Indic scripts at CVPR 2025, and I am co-first author on a follow-up submission to NeurIPS 2026.","My long-term goal is to build the foundational infrastru
1cture â datasets, pre-training methodologies, and evaluation frameworks â for Indic language AI that is both technically rigorous and culturally appropriate. I intend to establish an academic lab focused on South Asian NLP after completing my doctorate, bridging the gap between academic research and real-world deployment for over one billion Indic language speakers.","CMU's Language Technologies Institute is the ideal environment for this research. I am eager to work with Professor Graham Neubig on massively multilingual pre-training, and Professor Yulia Tsvetkov's work on cross-lingual transfer is closely aligned with challenges I have encountered in production systems. CMU's collaborative culture and access to large-scale compute infrastructure will accelerate the dataset and model-building work central to my thesis.","I am deeply motivated to contribute to CMU's tradition of impactful, open research. My technical foundation, two peer-reviewed publications, and firsthand experience with the real-world limitations of multilingual AI make me confident I will thrive in and contribute meaningfully to your doctoral programme. I look forward to the opportunity to discuss how my research agenda aligns with the work underway at the Language Technologies Institute."],closing:"Respectfully,"},va=`You are helping me fill in a cover letter builder. I will give you the JSON format the app uses, and my personal details below. 2 3Please fill in ALL the fields in the JSON with MY information â use real-sounding but accurate content based on what I tell you. Return ONLY the completed JSON, no explanation, no markdown, no extra text. 4 5--- 6MY DETAILS (replace everything in brackets with my actual info): 7Name: [your full name] 8Email: [your email] 9Phone: [your phone number] 10Location: [city, country] 11Target role: [e.g. Software Engineer] 12Company applying to: [company name] 13Recipient name/title: [e.g. Jane Smith, Head of Engineering â or leave blank for "Hiring Manager"] 14Key experience: [2-3 sentences about relevant experience] 15Why this company: [what draws you to this company] 16Notable achievement: [1-2 key accomplishments with metrics if possible] 17 18--- 19Write 3-4 body paragraphs (opening, experience/achievements, why this company, closing call-to-action). 20Fill this exact JSON format with my details above: 21 22`,wa=`You are helping me write a Statement of Purpose (SOP) for a university application. I will give you the JSON format the app uses, and my personal details below. 23 24Please fill in ALL the fields in the JSON with MY information â write compelling, specific, academic-style content. Return ONLY the completed JSON, no explanation, no markdown, no extra text. 25 26Note: in this JSON, the "recipient" fields map to the university application target: 27 recipient.name â Program / Department (e.g. "M.S. in Computer Science") 28 recipient.title â Admissions Committee / Reviewer name 29 recipient.organization â University name 30 salutation â "Dear Admissions Committee," 31 closing â "Respectfully," 32 33--- 34MY DETAILS (replace everything in brackets with my actual info): 35Name: [your full name] 36Email: [your email] 37Phone: [your phone number] 38Location: [city, country] 39Target program: [e.g. M.S. in Computer Science, MBA] 40University: [university name] 41Academic background: [degrees, institutions, GPA/CGPA, graduation year] 42Research or work experience: [2-3 sentences on relevant projects, publications, or jobs] 43Research interests / Why this program: [specific aspects of the program or faculty that attract you] 44Career goals: [short-term and long-term goals after graduating] 45Notable achievement: [1-2 key accomplishments â publications, awards, competition wins] 46 47--- 48Write 4 paragraphs (Motivation, Academic Background & Experience, Why This Program, Conclusion & Goals). 49Each paragraph: 5-7 sentences, formal academic tone, specific and evidence-based. Avoid generic phrases. 50Fill this exact JSON format with my details above: 51 52`,ja=`You are helping me write a structured Statement of Purpose (SOP) for a graduate or doctoral program application. I will give you the JSON format the app uses (5 named section paragraphs), and my personal details below. 53 54Please fill in ALL the fields in the JSON â write compelling, rigorous, doctoral-level content. Return ONLY the completed JSON, no explanation, no markdown, no extra text. 55 56Note: in this JSON, the "recipient" fields map to the university application target: 57 recipient.name â Program (e.g. "Ph.D. in Computer Science") 58 recipient.title â Graduate Admissions Committee 59 recipient.organization â University name 60 salutation â "Dear Admissions Committee," 61 closing â "Respectfully," 62 63The "paragraphs" array must have exactly 5 entries in this order: 64 [0] Introduction â hook + central research question + motivation for this program
65 [1] Academic Background â degrees, CGPA, key courses, academic milestones 66 [2] Career Goals â doctoral research agenda + long-term vision 67 [3] Why This Program â specific faculty, labs, courses, research culture fit 68 [4] Conclusion â confidence statement, contribution you'll make, call to action 69 70--- 71MY DETAILS (replace everything in brackets with my actual info): 72Name: [your full name] 73Email: [your email] 74Phone: [your phone number] 75Location: [city, country] 76Target program: [e.g. Ph.D. in Computer Science] 77University: [university name] 78Research area: [e.g. Natural Language Processing, Computer Vision] 79Faculty of interest: [professor(s) you want to work with] 80Academic background: [degrees, institutions, GPA/CGPA, graduation year] 81Research experience: [papers, projects, lab work â with concrete outcomes] 82Industry experience: [jobs, roles, companies â if any] 83Career goals: [doctoral research focus â long-term academic/industry vision] 84Why this program specifically: [faculty fit, lab resources, research culture] 85Notable achievement: [strongest 1-2 credentials â publication, award, ranking] 86 87--- 88Each paragraph: 5-8 sentences, rigorous academic tone, concrete evidence, zero generic filler. 89Fill this exact JSON format with my details above: 90 91`;function Na({visible:u}){return u?bt.createPortal(e.jsxs("div",{className:"animate-slide-in-toast fixed top-4 right-4 z-[500] flex items-center gap-3 rounded-2xl bg-gray-900 px-4 py-3 shadow-2xl",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-xl bg-white/10",children:e.jsx(gt,{className:"h-4 w-4 animate-bounce text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-white",children:"Preparing your PDFâ¦"}),e.jsx("p",{className:"text-[10px] text-gray-400 mt-0.5",children:"Rendering document â this takes a few seconds"})]}),e.jsx(F,{className:"h-4 w-4 animate-spin text-gray-500 ml-1 shrink-0"})]}),document.body):null}function Ca({content:u,onImport:B,onPreview:v,isAcademic:w=!1,isGraduateSop:d=!1}){var Z;const y=!!((Z=u.personalInfo.fullName)!=null&&Z.trim())||u.paragraphs.some(j=>j.trim()),R=d?ba:w?ya:xa,J=d?ja:w?wa:va,[p,b]=s.useState(()=>JSON.stringify(y?u:R,null,2)),[m,A]=s.useState(""),[o,k]=s.useState(!1),l=w?"SOP":"cover letter",I=d?"5 structured sections (Introduction, Backgroun
91d, Goals, Why This Program, Conclusion)":w?"4 essay paragraphs (Motivation, Background, Why This Program, Conclusion)":"3-4 paragraphs (opening, experience, why this company, closing)",h=()=>{try{const j=JSON.parse(p);B(j),A("")}catch{A("Invalid JSON â check your formatting.")}},me=()=>{const j=JSON.stringify(y?u:R,null,2);navigator.clipboard.writeText(J+j).then(()=>{k(!0),setTimeout(()=>k(!1),2500)})};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg border border-indigo-100 bg-indigo-50 px-3 py-3",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-indigo-800",children:"Use AI to fill this in"}),e.jsxs("p",{className:"text-xs text-indigo-700 mt-0.5 leading-relaxed",children:["Click ",e.jsx("strong",{children:"Copy AI Prompt"})," â paste into ChatGPT or Claude â add your details â paste the result back here â Apply."]}),e.jsxs("p",{className:"text-[11px] text-indigo-500 mt-1",children:["Prompt is tailored for a ",e.jsx("strong",{children:l})," â asks AI to write ",I,"."]})]}),e.jsxs("button",{onClick:me,className:"shrink-0 flex items-center gap-1.5 rounded-md bg-indigo-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-indigo-700 transition-colors",children:[e.jsx(xt,{className:"w-3 h-3"}),o?"Copied!":"Copy AI Prompt"]})]})}),e.jsxs("div",{className:"rounded-lg bg-amber-50 border border-amber-100 px-3 py-2.5",children:[e.jsx("p",{className:"text-xs text-amber-800 font-medium",children:y?`Your current ${l} data`:`Sample ${l} pre-loaded`}),e.jsx("p",{className:"text-xs text-amber-700 mt-0.5",children:y?"Edit directly, or paste updated JSON from an AI chat â Apply":"Copy the AI prompt above â fill your details â paste the returned JSON â Apply"})]}),e.jsx("textarea",{value:p,onChange:j=>{b(j.target.value);try{v(JSON.parse(j.target.value))}catch{}},rows:14,className:"w-full rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs font-mono text-gray-800 placeholder:text-gray-300 focus:border-gray-400 focus:outline-none resize-none"}),m&&e.jsx("p",{className:"text-xs text-red-600",children:m}),e.jsx("button",{onClick:h,className:"rounded-lg bg-gray-900 px-4 py-2 text-xs font-semibold text-white hover:bg-gray-700 transition-colors",children:"Apply JSON"})]})}const pt={manual:{label:"Build",Icon:yt},json:{label:"JSON",Icon:qt},generate:{label:"Generate",Icon:ft}},ka=[{label:"More professional tone",instruction:"Rewrite all body paragraphs with a more professional, polished tone. Use clear, concise business language and remove any informal phrasing. Keep dates, names, and structure intact."},{label:"More concise",instruction:"Make the cover letter more concise and impactful. Cut unnecessary filler words and redundant phrases, keeping only the strongest points in each paragraph. Do not remove any factual content."},{label:"Stronger opening",instruction:"Rewrite the first paragraph to be more compelling and engaging. Start with a strong hook that immediately demonstrates enthusiasm and value for the role. Keep the same core facts."},{label:"Add specific achievements",instruction:"Strengthen the body paragraphs by making achievements more specific and quantified where possible. Replace vague statements with concrete examples and measurable results."},{label:"Academic / formal style",instruction:"Rewrite the letter in a formal academic style â precise language, structured arguments, and a tone appropriate for university or research program applications."}];function Sa({content:u,onApply:B,onCreditLimit:v}){var A;const w=!!((A=u.personalInfo.fullName)!=null&&A.trim())||u.paragraphs.some(o=>o.trim()),[d,y]=s.useState(""),[R,J]=s.useState(!1),[p,b]=s.useState(""),m=async o=>{const k=o.trim();if(!(!k||!w)){J(!0),b("");try{const l=await P.post("/ai/refine-resume",{content:u,instruction:k});l.content?(B(l.content),y("")):b(l.error||"Could not apply changes. Try again.")}catch(l){if(l instanceof Ie&&l.status===429){const h=l.body??{};h.code==="CREDIT_LIMIT_REACHED"?v(h):b("Too many requests. Please wait a moment and try again.");return}const I=l instanceof Error?l.message:"";I.includes("503")||I.toLowerCase().includes("provider")?b("AI provider not configured. Add OPENAI_API_KEY or ANTHROPIC_API_KEY."):b("Could not apply changes. Try again.")}finally{J(!1)}}};return e.jsx("div",{className:"space-y-4 px-4 py-3",children:w?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold text-gray-700",children:"Refine existing cover letter"}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:"Pick a quick action or describe a custom change."})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ka.map(o=>e.jsx("button",{onClick:()=>y(o.instruction),className:`rounded-full border px-2.5 py-1 text-xs font-medium transition-colors ${d===o.instruction?"border-violet-400 bg-vi
91olet-50 text-violet-700":"border-gray-200 text-gray-500 hover:border-gray-400 hover:text-gray-700"}`,children:o.label},o.label))}),e.jsx("textarea",{value:d,onChange:o=>y(o.target.value),rows:3,placeholder:"Or describe a custom change⦠e.g. Make the opening paragraph more compelling and specific",className:"w-full rounded-lg border border-gray-200 bg-white px-3 py-2 text-xs text-gray-900 placeholder:text-gray-300 focus:border-gray-400 focus:outline-none resize-none"}),p&&e.jsx("p",{className:"text-xs text-red-500",children:p}),e.jsxs("button",{onClick:()=>void m(d),disabled:R||!d.trim(),className:"flex items-center gap-2 rounded-lg border border-violet-200 bg-violet-50 px-4 py-2 text-xs font-semibold text-violet-700 hover:bg-violet-100 transition-colors disabled:opacity-40",children:[R?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(Ae,{className:"h-3 w-3"}),"Apply changes"]})]}):e.jsxs("div",{className:"rounded-lg border border-dashed border-gray-200 bg-gray-50 px-4 py-5 text-center",children:[e.jsx(ft,{className:"mx-auto mb-2 h-5 w-5 text-gray-300"}),e.jsx("p",{className:"text-xs font-medium text-gray-500",children:"Add your details in the Build tab first"}),e.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:"Then come back here to refine with AI."})]})})}function $a(){var tt,at,rt;const{id:u}=sa(),[B]=na(),v=oa(),{profile:w}=pa(),{status:d,loading:y,refetch:R}=ga(),J=(d==null?void 0:d.watermark_enabled)===!0,p=(tt=d==null?void 0:d.allowed_template_ids)==null?void 0:tt.cover_letter,b=!((at=d==null?void 0:d.features)!=null&&at.all_templates)&&((p==null?void 0:p.length)??0)>0,[m,A]=s.useState("Untitled Cover Letter"),[o,k]=s.useState(Se()),[l,I]=s.useState(B.get("template")??""),[h,me]=s.useState([]),[Z,j]=s.useState(!1),[W,he]=s.useState(null),[vt,Le]=s.useState(""),[wt,ue]=s.useState(!1),[Ee,Re]=s.useState(null),[jt,Te]=s.useState(!1),[ee,pe]=s.useState("manual"),[ge,Me]=s.useState(!1),[Oe,_e]=s.useState(!1),[Nt,De]=s.useState(!!u),[_,Ue]=s.useState(u||null),[$e,Ct]=s.useState({}),[L,kt]=s.useState(1),[St,te]=s.useState(!1),[Fe,Pt]=s.useState(!0),[At,It]=s.useState(S),[xe,Lt]=s.useState([]),[Y,Je]=s.useState(!1),[He,ae]=s.useState(""),[T,q]=s.useState(null),[fe,re]=s.useState(!1),[se,Et]=s.useState(null),[Rt,ze]=s.useState(!1),Ge=s.useRef(null),ye=s.useRef([]),be=s.useRef(null),Be=s.useRef(null),[ne,We]=s.useState(!0),[H,Tt]=s.useState(!1),[D,ve]=s.useState(""),[E,oe]=s.useState("");s.useEffect(()=>{const t=a=>{var n;const r=a.target;(n=Be.current)!=null&&n.contains(r)||te(!1)};return document.addEventListener("click",t,{capture:!0}),()=>document.removeEventListener("click",t,{capture:!0})},[]),s.useEffect(()=>{const t=Ge.current;if(!t)return;const a=()=>{const n=t.offsetWidth-48;kt(Math.min(1,n/O))};a();const r=new ResizeObserver(a);return r.observe(t),()=>r.disconnect()},[]);const i=h.find(t=>t.id===l)??h[0]??null,x=(i==null?void 0:i.template_type)==="html",g=(i==null?void 0:i.category)==="academic";s.useEffect(()=>{P.get("/templates?document_kind=cover-letter").then(t=>me(t.templates??[])).catch(()=>{})},[]),s.useEffect(()=>{y||h.length===0||I(t=>{var n;const a=c=>!b||((p==null?void 0:p.includes(c))??!1);if(t&&h.some(c=>(c.id===t||c.slug===t)&&a(c.id))){const c=h.find(U=>U.slug===t);return(c==null?void 0:c.id)??t}return((n=(b?h.filter(c=>a(c.id)):h)[0])==null?void 0:n.id)??t})},[y,b,p,h]),s.useEffect(()=>{if(!(i!=null&&i.id)||!Pe.test(i.id)){he(null);return}let t=!1;return P.get(`/templates/${i.id}`).then(a=>{var r;t||he(((r=a.template)==null?void 0:r.html_source)??null)}).catch(()=>{t||he(null)}),()=>{t=!0}},[i==null?void 0:i.id]);const ie=s.useMemo(()=>ut(o),[o]),we=s.useMemo(()=>!x||!W?"":la(W,ie),[x,W,ie]),z=we||vt,N=s.useMemo(()=>{if(!z)return"";if(!D&&!E)return z;const t=[];D&&t.push(`p, li { text-align: ${D} !important; }`),E&&t.push(`body, p, li { font-size: ${E}px !important; }`);const a=`<style id="__cl-style__">${t.join(` 92`)}</style>`;return z.includes("</head>")?z.replace("</head>",`${a}</head>`):z+a},[z,D,E]);s.useEffect(()=>{if(!i||!x||W){Le("");return}ue(!0);const t=setTimeout(()=>{P.post("/templates/preview",{templateId:i.id,content:ie,title:m}).then(a=>{a.html&&Le(a.html)}).catch(()=>{}).finally(()=>ue(!1))},80);return()=>clearTimeout(t)},[i,x,ie,m,W]),s.useEffect(()=>{we&&ue(!1)},[we]),s.useEffect(()=>{if(!i||x){Re(r=>(r&&URL.revokeObjectURL(r),null));return}Te(!0);const t=ut(o),a=setTimeout(()=>{ke("/templates/preview-pdf",{templateId:i.id,content:t,title:m}).then(r=>{const n=URL.createObjectURL(r);Re(c=>(c&&URL.revokeObjectURL(c),n))}).catch(()=>{}).finally(()=>Te(!1))},800);return()=>clearTimeout(a)},[i,x,o,m]),s.useEffect(()=>{var r;if(!x||!N)return;const t=ye.current[0];if(!t)return;const a=t.contentDocument||((r=t.contentWindow)==null?void 0:r.document);a&&(a.open(),a.write(N),a.close(),requestAnimationFrame(()=>{var $,st;dt(t.contentDocument,de);const n=((st=($=t.contentDocument)==null?void 0:$.documentElement)==null?void 0:st.scrollHeight)??mt,c=Math.max(mt,n);It(c);const U=t.contentDocument;Lt(U?ca(da(U),c):[])}))},[N,x]),s.useEffect(()=>{!x||!N||ye.current.forEach((t,a)=>{var n;if(!t||a===0)return;const r=t.contentDocument||((n=t.contentWindow)==null?void 0:n.document);r&&(r.open(),r.write(N),r.close(),dt(r,de))})},[N,xe.length,x]);const Ye=s.useMemo(()=>[0,...xe],[xe]),qe=Ye.length;s.useEffect(()=>{var r;if(!Fe)return;const t=(r=o.personalInfo.fullName)==null?void 0:r.trim();if(!t)return;const a=(i==null?void 0:i.name)??"Cover Letter";A(`${t} â ${a}`)},[o.personalInfo.fullName,i==null?void 0:i.name,Fe]),s.useEffect(()=>{if(!u){De(!1);return}P.get(`/resumes/${u}`).then(t=>{var a;if(t.resume){A(t.resume.title||"Untitled Cover Letter"),k({...Se(),...t.resume.content}),Ue(t.resume.id);const r=t.resume.template_id,n=(a=t.resume.metadata)==null?void 0:a.template_key;r&&Pe.test(r)?I(r):n&&I(n)}}).catch(()=>v("/dashboard")).finally(()=>De(!1))},[u,v]);const je=s.useCallback(async(t,a,r)=>{Me(!0);try{const n=h.find($=>
92$.id===r),c=n!=null&&n.id&&Pe.test(n.id)?n.id:null,U={document_type:"cover-letter",template_key:(n==null?void 0:n.slug)??r,letter_category:(n==null?void 0:n.category)??"professional"};if(_)await P.put(`/resumes/${_}`,{title:a,content:t,metadata:U,...c?{template_id:c}:{}});else{const $=await P.post("/resumes",{title:a,content:t,category:"cover-letter",metadata:U,...c?{template_id:c}:{}});Ue($.resume.id),v(`/create-cover-letter/${$.resume.id}`,{replace:!0})}_e(!0),setTimeout(()=>_e(!1),2e3)}finally{Me(!1)}},[_,v,h]),K=s.useCallback((t,a,r)=>{be.current&&clearTimeout(be.current),be.current=setTimeout(()=>je(t,a,r),2e3)},[je]),C=s.useCallback(t=>{k(a=>{const r={...a,...t};return K(r,m,l),r})},[m,l,K]),Ne=t=>{I(t),K(o,m,t)},M=o.personalInfo,G=(t,a)=>C({personalInfo:{...M,[t]:a}}),V=o.recipient,le=(t,a)=>C({recipient:{...V,[t]:a}}),Mt=()=>C({paragraphs:[...o.paragraphs,""]}),Ot=t=>C({paragraphs:o.paragraphs.filter((a,r)=>r!==t)}),Ke=(t,a)=>C({paragraphs:o.paragraphs.map((r,n)=>n===t?a:r)}),Ve=(t,a)=>{const r=t+a;if(r<0||r>=o.paragraphs.length)return;const n=[...o.paragraphs];[n[t],n[r]]=[n[r],n[t]],C({paragraphs:n})},Xe=(t,a)=>Ct(r=>({...r,[t]:a})),_t=async t=>{const a=o.paragraphs[t];if(a.trim()){Xe(t,!0);try{const r=g?"formal":"business",n=await P.post("/ai/enhance-content",{content:a,mode:r,industry:w==null?void 0:w.industry});n.enhanced&&Ke(t,n.enhanced.trim())}catch(r){if(r instanceof Ie&&r.status===429){const n=r.body??{};n.code==="CREDIT_LIMIT_REACHED"&&q(n)}}finally{Xe(t,!1)}}},Dt=(t,a)=>{const r=URL.createObjectURL(t),n=document.createElement("a");n.href=r,n.download=a,document.body.appendChild(n),n.click(),setTimeout(()=>{document.body.removeChild(n),URL.revokeObjectURL(r)},100)},Ut=async()=>{if(!Y){Je(!0),ae("");try{const t=x&&N?{html:N,document_type:"cover-letter"}:{templateId:i==null?void 0:i.id,content:o,title:m},a=await ke("/templates/export-pdf",t),r=m.replace(/[^a-z0-9\s\-ââ]/gi,"").trim()||"cover-letter";Dt(a,`${r}.pdf`),R()}catch(t){if(t instanceof Ie&&t.status===429){const r=t.body??{};r.code==="CREDIT_LIMIT_REACHED"?q(r):ae("Too many export requests. Please wait a moment and try again."),R();return}const a=t instanceof Error?t.message:String(t);ae(`PDF export failed: ${a}`)}finally{Je(!1)}}},$t=async()=>{if(_){te(!1);try{const t=await P.post(`/resumes/${_}/duplicate`);v(`/create-cover-letter/${t.resume.id}`)}catch{}}},Ft=async()=>{if(!_){v("/dashboard");return}if(te(!1),!!window.confirm("Delete this document? It can be restored from trash."))try{await P.delete(`/resumes/${_}`),v("/dashboard")}catch{}};if(s.useEffect(()=>{if(!fe)return;const t=a=>{a.key==="Escape"&&re(!1)};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[fe]),Nt)return e.jsx(Ce,{children:e.jsx("div",{className:"flex items-center justify-center py-24",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-gray-400"})})});if(d&&!((rt=d.features)!=null&&rt.has_cover_letters))return e.jsx(Ce,{children:e.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 py-24 text-center px-4",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-full bg-amber-50",children:e.jsx(zt,{className:"h-6 w-6 text-amber-500"})}),e.jsx("h1",{className:"text-lg font-semibold text-gray-900",children:"Cover letters aren't on your plan"}),e.jsx("p",{className:"max-w-sm text-sm text-gray-500",children:"Upgrade to Starter or above to build and export cover letters."}),e.jsx("a",{href:"/pricing",className:"mt-2 rounded-xl bg-gray-900 px-5 py-2.5 text-sm font-semibold text-white hover:bg-gray-700 transition-colors",children:"View plans"})]})});const Qe=b?h.filter(t=>p==null?void 0:p.includes(t.id)):h,Ze=Qe.filter(t=>t.category==="professional"),et=Qe.filter(t=>t.category==="academic"),ce=(i==null?void 0:i.slug)==="sop-graduate",Jt=t=>{const a={...Se(),...t};k(a),pe("manual"),K(a,m,l)},Ht=t=>{k(a=>({...a,...t}))};return e.jsxs(Ce,{lockViewport:!0,children:[e.jsx(Na,{visible:Y}),e.jsxs("div",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-12 shrink-0 items-center gap-3 border-b border-gray-200 bg-white px-4",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(nt,{className:"h-3.5 w-3.5 shrink-0 text-gray-300"}),e.jsx("input",{value:m,onChange:t=>{A(t.target.value),Pt(!1),K(o,t.target.value,l)},className:"flex-1 min-w-0 bg-transparent text-sm font-semibold text-gray-800 border-0 outline-none focus:outline-none focus:ring-0 placeholder:text-gray-300",placeholder:"Cover letter titleâ¦"})]}),e.jsx("button",{onClick:()=>je(o,m,l),disabled:ge,title:ge?"Savingâ¦":Oe?"All changes saved":"Save",className:"flex items-center gap-1.5 rounded-lg px-2 py-1.5 text-xs font-medium transition-colors disabled:pointer-events-none shrink-0",children:ge?e.jsxs(e.Fragment,{children:[e.jsx(Gt,{className:"h-4 w-4 text-blue-400 animate-cloud-save"}),e.jsx("span",{className:"text-gray-400 text-[11px]",children:"Saving"})]}):Oe?e.jsxs(e.Fragment,{children:[e.jsx(Bt,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-green-600 text-[11px]",children:"Saved"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Wt,{className:"h-4 w-4 text-gray-300"}),e.jsx("span",{className:"text-gray-300 text-[11px]",children:"Save"})]})}),e.jsxs("button",{onClick:()=>{re(!0),ze(!0);const t=x&&N?{html:N}:{templateId:i==null?void 0:i.id,content:o,title:m};ke("/templates/preview-pdf",t).then(a=>{se&&URL.revokeObjectURL(se),Et(URL.createObjectURL(a))}).catch(()=>{}).finally(()=>ze(!1))},className:"flex items-center gap-1.5 rounded-lg border border-gray-200 bg-white px-3.5 py-2 text-xs font-semibold text-gray-700 hover:border-gray-400 transition-colors",children:[e.jsxs("svg",{className:"h-3.5 w-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]}),"Preview"]}),e.jsxs("button",{onClick:()=>void Ut(),disabled:Y,className:"flex items-center gap-1.5 rounded-lg border border-gray-200 bg-white px-3.5 py-2 text-xs font-semibold text-gray-700 hover:border-gray-400 transition-colors disabled:opacity-50",children:[Y?e.jsx(F,{className:"h-3.5 w-3.5 text-red-500 animate-spin"}):e.jsx(gt,{className:"h-3.5 w-3.5"}),Y?"Generatingâ¦":"Export PDF"]}),e.jsxs("div",{ref:Be,className:"relative hidden",children:[e.jsx("button",{onClick:()=>te(t=>!t),className:"flex items-center justify-center rounded-lg border border-gray-200 bg-white p-2 text-gray-500 hover:border-gray-400 hover:text-gray-700 transition-colors",title:"More options",children:e.jsx(Yt,{className:"h-4 w-4"})}),St&&e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-40 rounded-xl border border-gray-200 bg-white shadow-lg z-50 overflow-hidden",children:[e.jsxs("button",{onClick:$t,className:"flex w-full items-center gap-2.5 px-4 py-2.5 text-xs font-medium text-gray-700 hover:bg-gray-50 transition-colors",children:[e.jsx(xt,{className:"h-3.5 w-3.5 text-gray-400"}),"Clone document"]}),e.jsxs("button",{onClick:Ft,className:"flex w-full items-center gap-2.5 px-4 py-2.5 text-xs font-medium text-red-600 hover:bg-red-50 transition-colors",children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),"Delete document"]})]})]})]}),He&&e.jsxs("div",{className:"mx-4 mb-2 flex items-center justify-between gap-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700",children:[e.jsx("span",{children:He}),e.jsx("button",{onClick:()=>ae(""),className:"shrink-0 font-semibold hover:text-red-900",children:"â"})]}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsxs("div",{className:`flex h-full min-h-0 shrink-0 flex-col border-r border-gray-200 bg-white overflow-hidden transition-[width] duration-200 ease-out ${ne?"w-[420px]":"w-0 border-r-0"}`,children:[e.jsx("div",{className:"flex gap-0 border-b border-gray-100 bg-gray-50/70 px-4 py-2 shrink-0",children:Object.keys(pt).map(t=>{const{label:a,Icon:r}=pt[t];return e.jsxs("button",{onClick:()=>pe(t),className:`flex items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-[background-color,color,box-shadow,border-color] ${ee===t?"bg-white text-gray-900 shadow-sm border border-gray-200":"text-gray-500 hover:text-gray-700"}`,children:[e.jsx(r,{className:"h-3.5 w-3.5"}),a]},t)})}),ee==="manual"&&e.jsxs(X,{className:"flex-1",children:[e.jsx(Q,{title:"Your Info",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"Full Name",value:M.fullName,onChange:t=>G("fullName",t),placeholder:"Taylor Reed"})}),e.jsx(f,{label:"Email",value:M.email,onChange:t=>G("email",t),placeholder:"[email protected]",type:"email"}),e.jsx(f,{label:"Phone",value:M.phone,onChange:t=>G("phone",t),placeholder:"+91 800 000 0000"}),e.jsx(f,{label:"Location",value:M.location,onChange:t=>G("location",t),placeholder:"Hyderabad, India"}),e.jsx(f,{label:"LinkedIn",value:M.linkedin||"",onChange:t=>G("linkedin",t),placeholder:"linkedin.com/in/taylorreed"}),e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"Website / Portfolio",value:M.website||"",onChange:t=>G("website",t),placeholder:"taylorreed.dev"})})]})}),e.jsx(Q,{title:g?"University / Program":"Recipient",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:g?"Program / Department":"Recipient Name",value:V.name||"",onChange:t=>le("name",t),placeholder:g?"M.S. in Computer Science":"Hiring Manager"})}),e.jsx(f,{label:g?"Reviewer / Committee":"Recipient Title",value:V.title||"",onChange:t=>le("title",t),placeholder:g?"Admissions Committee":"Engineering Recruiting"}),e.jsx(f,{label:g?"University":"Company",value:V.organization||"",onChange:t=>le("organization",t),placeholder:g?"Stanford University":"TechCorp India"}),e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"Address",value:V.address||"",onChange:t=>le("address",t),placeholder:"Hyderabad, India"})})]})}),e.jsx(Q,{title:"Letter Details",children:e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(f,{label:"Date",value:o.date,onChange:t=>C({date:t}),placeholder:"June 14, 2026"}),e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:g?"Title / Subject":"Subject",value:o.subject||"",onChange:t=>C({subject:t}),placeholder:g?"Application for M.S. in Computer Science":"Application for Software Engineer Position"})}),!g&&e.jsx("div",{className:"col-span-2",children:e.jsx(f,{label:"Salutation",value:o.salutation,onChange:t=>
92C({salutation:t}),placeholder:"Dear Hiring Manager,"})})]})}),e.jsxs(Q,{title:g&&ce?"Body (Introduction, Background, Goals, Why This Program, Conclusion)":"Body",children:[o.paragraphs.map((t,a)=>e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50/50 p-2.5 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] font-semibold text-gray-400",children:g&&ce?["Introduction","Academic Background","Career Goals","Why This Program","Conclusion"][a]||`Paragraph ${a+1}`:`Paragraph ${a+1}`}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:()=>Ve(a,-1),disabled:a===0,className:"rounded p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 transition-colors",children:e.jsx(Kt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>Ve(a,1),disabled:a===o.paragraphs.length-1,className:"rounded p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 transition-colors",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>Ot(a),disabled:o.paragraphs.length<=1,className:"rounded p-1 text-gray-400 hover:text-red-600 disabled:opacity-30 transition-colors",children:e.jsx(ot,{className:"h-3.5 w-3.5"})})]})]}),e.jsx(ma,{value:t,onChange:r=>Ke(a,r),placeholder:"Write this paragraphâ¦",rows:4}),e.jsxs("button",{onClick:()=>void _t(a),disabled:$e[a]||!t.trim(),className:"flex items-center gap-1.5 rounded-lg border border-gray-200 bg-white px-2.5 py-1.5 text-[11px] font-semibold text-gray-500 hover:text-gray-900 hover:bg-gray-50 transition-colors disabled:opacity-40",children:[$e[a]?e.jsx(F,{className:"h-3 w-3 animate-spin"}):e.jsx(Ae,{className:"h-3 w-3"}),"Enhance with AI"]})]},a)),e.jsxs("button",{onClick:Mt,className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-gray-300 px-3 py-2 text-xs font-medium text-gray-500 hover:border-gray-400 hover:text-gray-700 transition-colors",children:[e.jsx(Xt,{className:"h-3.5 w-3.5"}),"Add paragraph"]})]}),e.jsxs(Q,{title:"Closing",children:[e.jsx(f,{label:"Closing phrase",value:o.closing,onChange:t=>C({closing:t}),placeholder:"Sincerely,"}),e.jsxs("p",{className:"text-[11px] text-gray-400",children:["Signed as: ",M.fullName||"Your Name"]})]})]}),ee==="json"&&e.jsx(X,{className:"flex-1",children:e.jsx("div",{className:"p-4",children:e.jsx(Ca,{content:o,onImport:Jt,onPreview:Ht,isAcademic:g,isGraduateSop:ce},`${g}-${ce}`)})}),ee==="generate"&&e.jsx(X,{className:"flex-1",children:e.jsx(Sa,{content:o,onApply:t=>{C(t),pe("manual")},onCreditLimit:q})})]}),e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden bg-[#f0f2f5]",children:[e.jsx(X,{direction:"x",className:"flex items-center gap-2 border-b border-gray-200 bg-white px-4 py-2 shrink-0",children:h.length===0||y?e.jsx("span",{className:"text-xs text-gray-400",children:"Loading templatesâ¦"}):e.jsxs(e.Fragment,{children:[Ze.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-xs font-medium text-gray-500 shrink-0 mr-1",children:"Cover Letters:"}),Ze.map(t=>e.jsx("button",{onClick:()=>Ne(t.id),className:`shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-[background-color,color] ${l===t.id?"bg-gray-900 text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"}`,title:t.description??void 0,children:t.name},t.id))]}),et.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mx-2 h-4 w-px shrink-0 bg-gray-200"}),e.jsx("span",{className:"text-xs font-medium text-gray-500 shrink-0 mr-1",children:"SOP:"}),et.map(t=>e.jsx("button",{onClick:()=>Ne(t.id),className:`shrink-0 rounded-lg px-3 py-1.5 text-xs font-medium transition-[background-color,color] ${l===t.id?"bg-gray-900 text-white":"bg-gray-50 text-gray-600 hover:bg-gray-100"}`,title:t.description??void 0,children:t.name},t.id))]}),e.jsx("span",{className:"mx-1 h-4 w-px shrink-0 bg-gray-200"}),e.jsxs("button",{onClick:()=>j(!0),className:"flex shrink-0 items-center gap-1.5 rounded-lg border border-gray-200 px-3 py-1.5 text-xs font-medium text-gray-500 hover:border-gray-400 hover:text-gray-700 transition-[border-color,color]",children:[e.jsx(yt,{className:"h-3.5 w-3.5"}),"Browse templates"]}),(i==null?void 0:i.description)&&e.jsx("span",{className:"ml-2 shrink-0 text-xs text-gray-400 max-w-[180px] truncate hidden",children:i.description})]})}),e.jsxs("div",{className:"relative h-0 min-h-0 flex-1 min-w-0 overflow-hidden",children:[e.jsxs(X,{ref:Ge,direction:"both",className:`h-full w-full p-6 pl-10 transition-[padding] duration-200 ease-out ${H?"pr-[300px]":"pr-10"}`,children:[(wt||jt)&&e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-gray-400"})}),!x&&Ee&&e.jsx("div",{className:"mx-auto",style:{width:O*L},children:e.jsx("iframe",{title:"Cover Letter PDF Preview",src:Ee,className:"bg-white",style:{width:O*L,height:S*L,border:"none",boxShadow:"0 4px 32px rgba(0,0,0,0.18)"}})}),x&&N&&e.jsx("div",{className:"mx-auto flex flex-col items-center gap-6",style:{width:O*L},children:Ye.map((t,a)=>e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsxs("div",{className:"relative bg-white box-border",style:{width:O*L,height:S*L,padding:`${ha*L}px ${ua*L}px`,boxShadow:"0 4px 32px rgba(0,0,0,0.18)"},children:[e.jsx("div",{className:"relative h-full w-full overflow-hidden",children:e.jsx("div",{className:"relative",style:{width:de,transformOrigin:"top left",transform:`scale(${L})`},children:e.jsx("iframe",{ref:r=>{ye.current[a]=r},title:`Cover Letter Preview â Page ${a+1}`,style:{position:"absolute",top:-t,left:0,width:de,height:At,border:"none"}})})}),J&&e.jsx(ht,{})]}),e.jsxs("span",{className:"mt-1.5 text-[11px] text-gray-400",children:["Page ",a+1,qe>1?` of ${qe}`:""]})]},a))})]}),e.jsx("div",{className:"absolute inset-y-0 left-0 z-30 flex flex-row items-stretch pointer-events-none",children:e.jsxs("button",{type:"button","aria-label":ne?"Close editor":"Open editor","aria-expanded":ne,onClick:()=>We(t=>!t),className:"pointer-events-auto ml-1 flex h-[4.5rem] w-7 shrink-0 flex-col items-center justify-center gap-0.5 self-center rounded-r-lg border border-l-0 border-gray-200 bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-50 hover:text-gray-800",children:[ne?e.jsx(it,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(lt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(nt,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"text-[9px] font-semibold leading-none tracking-wide",children:"Edit"})]})}),e.jsxs("div",{className:"absolute inset-y-0 right-0 z-30 flex flex-row-reverse items-stretch pointer-events-none",children:[e.jsx("div",{className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-hidden border-l border-gray-200 bg-white shadow-lg transition-[width] duration-200 ease-out ${H?"w-[268px]":"w-0 border-l-0 shadow-none"}`,children:H&&e.jsxs("div",{className:"w-[268px] flex flex-col overflow-hidden",children:[e.jsx("div",{className:"shrink-0 border-b border-gray-100 px-4 py-3",children:e.jsx("p",{className:"text-xs font-semibold text-gray-700",children:"Style"})}),e.jsx("div",{className:"bg-white px-4 py-4",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-gray-700",children:"Text Alignment"}),e.jsx("div",{className:"flex gap-1.5",children:[{value:"left",Icon:Qt,label:"Left"},{value:"center",Icon:Zt,label:"Center"},{value:"right",Icon:ea,label:"Right"},{value:"justify",Icon:ta,label:"Justify"}].map(({value:t,Icon:a,label:r})=>e.jsx("button",{type:"button",title:r,onClick:()=>ve(D===t?"":t),className:`flex flex-1 items-center justify-center rounded-lg border py-2 transition-colors ${D===t?"border-gray-900 bg-gray-900 text-white":"border-gray-200 text-gray-500 hover:border-gray-400 hover:text-gray-700"}`,children:e.jsx(a,{className:"h-4 w-4"})},t))}),D&&e.jsx("button",{type:"button",onClick:()=>ve(""),className:"mt-1.5 text-[10px] text-gray-400 hover:text-gray-600",children:"Reset to default"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-2 text-xs font-semibold text-gray-700",children:"Text Size"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>oe(String(Math.max(8,parseFloat(E||"10.5")-.5))),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-gray-200 text-base text-gray-600 hover:border-gray-400 transition-colors",children:"â"}),e.jsx("span",{className:"flex-1 text-center text-xs font-medium text-gray-700",children:E?`${E}px`:"Default"}),e.jsx("button",{type:"button",onClick:()=>oe(String(Math.min(22,parseFloat(E||"10.5")+.5))),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-gray-200 text-base text-gray-600 hover:border-gray-400 transition-colors",children:"+"})]}),E&&e.jsx("button",{type:"button",onClick:()=>oe(""),className:"mt-1.5 text-[10px] text-gray-400 hover:text-gray-600",children:"Reset to default"})]})]})}),e.jsx("div",{className:"shrink-0 border-t border-gray-100 px-4 py-3",children:e.jsxs("button",{onClick:()=>{ve(""),oe("")},className:"flex w-full items-center justify-center gap-2 rounded-lg border border-gray-200 py-2 text-xs font-medium text-gray-500 hover:border-gray-400 hover:text-gray-700 transition-colors",children:[e.jsx(aa,{className:"h-3.5 w-3.5"}),"Reset to Default"]})})]})}),e.jsxs("button",{type:"button","aria-label":H?"Close style panel":"Open style panel","aria-expanded":H,onClick:()=>Tt(t=>(t||We(!1),!t)),className:"pointer-events-auto ml-1 flex h-[4.5rem] w-7 shrink-0 flex-col items-center justify-center gap-0.5 self-center rounded-l-lg border border-r-0 border-gray-200 bg-white text-gray-500 shadow-sm transition-colors hover:bg-gray-50 hover:text-gray-800",children:[H?e.jsx(lt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(it,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(ra,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"text-[9px] font-semibold leading-none tracking-wide",children:"Style"})]})]})]})]})]})]}),e.jsx(ia,{open:Z,onClose:()=>j(!1),onSelect:t=>Ne(t)}),T&&e.jsx("div",{className:"fixed inset-0 z-[400] flex items-center justify-center bg-black/40 backdrop-blur-sm px-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-2xl max-w-sm w-full p-6 relative",children:[e.jsx("button",{onClick:()=>q(null),className:"absolute top-4 right-4 text-gray-400 hover:text-gray-600 transition-colors",children:e.jsx(ct,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex items-center justify-center w-12 h-12 bg-amber-50 rounded-full mb-4 mx-auto",children:e.jsx(Ae,{className:"h-6 w-6 text-amber-500"})}),(()=>{const t=fa[String(T.operation??"")]??"Credit";return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-base font-semibold text-gray-900 text-center mb-2",children:T.tier==="free"?`Free ${t} Credits Completed`:`${t} Credits Completed`}),T.tier==="free"?e.jsxs("p",{className:"text-sm text-gray-500 text-center",children:["You've used your free lifetime ",t.toLowerCase()," allowance â it doesn't refill. Upgrade to a paid plan to keep going."]}):e.jsxs("p",{className:"text-sm text-gray-500 text-center",children:["You've used all your ",t.toLowerCase()," credits on your"," ",e.jsx("span",{className:"font-medium text-gray-700 capitalize",children:String(T.plan_name??T.tier)})," ","plan",T.expiresAt?e.jsxs(e.Fragment,{children:[", active until"," ",e.jsx("span",{className:"font-medium text-gray-700",children:new Date(T.expiresAt).toLocaleDateString("en-US",{month:"long",day:"numeric"})})]}):null,". Upgrade or buy a top-up for more credits."]})]})})(),e.jsxs("div",{className:"mt-5 flex flex-col gap-2",children:[e.jsx("a",{href:"/pricing",className:"flex items-center justify-center gap-2 rounded-lg bg-violet-600 px-4 py-2.5 text-sm font-semibold text-white hover:bg-violet-700 transition-colors",children:"View Plans"}),e.jsx("button",{onClick:()=>q(null),className:"rounded-lg border border-gray-200 px-4 py-2.5 text-sm font-medium text-gray-600 hover:bg-gray-50 transition-colors",children:"Close"})]})]})}),fe&&bt.createPortal(e.jsxs("div",{className:"fixed inset-0 z-[300] flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/75 backdrop-blur-sm",onClick:()=>re(!1)}),e.jsxs("div",{className:"relative z-10 flex flex-col overflow-hidden rounded-2xl bg-[#18181b] shadow-2xl",style:{width:Math.round(O*Math.min(.82,(window.innerHeight-140)/S))+48},children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-white/10 px-5 py-3.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-white",children:m||"Cover Letter"}),e.jsx("p",{className:"text-[11px] text-white/40 mt-0.5",children:"Preview · watermark removed on export"})]}),e.jsx("button",{onClick:()=>re(!1),className:"ml-8 flex h-8 w-8 items-center justify-center rounded-lg text-white/50 hover:bg-white/10 hover:text-white transition-colors",children:e.jsx(ct,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"flex items-center justify-center p-6",children:Rt?e.jsx("div",{style:{width:Math.round(O*Math.min(.82,(window.innerHeight-140)/S)),height:Math.round(S*Math.min(.82,(window.innerHeight-140)/S))},className:"flex items-center justify-center",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-white/40"})}):se?e.jsxs("div",{className:"relative",style:{width:Math.round(O*Math.min(.82,(window.innerHeight-140)/S)),height:Math.round(S*Math.min(.82,(window.innerHeight-140)/S))},children:[e.jsx("iframe",{src:se+"#toolbar=0",style:{width:"100%",height:"100%",border:"none"},title:"Cover Letter Preview"}),e.jsx(ht,{})]}):e.jsx("p",{className:"py-10 text-sm text-white/40",children:"Failed to generate preview."})})]})]}),document.body)]})}
92export{$a 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.