1import{g as at,r as g,j as s,B as L,k as gt,l as xt,m as bt,n as wt,o as Je,d as ue,e as T,s as v,L as de,U as rt,t as vt,q as yt,R as jt,C as ae,F as _t,G as St,i as Nt,v as Ct,D as Ft,O as kt}from"./index-NwEFhPA0.js";import{U as lt,u as Tt,g as ke,V as Oe,i as Et,a as Pt}from"./VisaDashboardLayout-DTrzxlTG.js";import{S as K}from"./SectionCard-gjIAJDBb.js";import{B as Ae}from"./badge-D_YHDHBA.js";import{P as At}from"./progress-BdaJRI0p.js";import{A as Dt,h as Rt,a as zt,b as Lt,c as It,d as Bt,e as Ut,f as $t,g as Ot}from"./alert-dialog-C5d9M25I.js";import{I as Ht}from"./input-CkVE8fp8.js";import{L as Ke}from"./label-D17oNgiY.js";import{D as Mt,f as Wt,a as Vt,b as qt,c as Gt,d as Yt,e as Jt}from"./dialog-CR40autX.js";import{M as ot}from"./mail-BSNUbYWs.js";import{P as Kt,a as Xt,b as Zt}from"./popover-B3zXKfBh.js";import{M as Qt,f as es}from"./formatDistanceToNow-xsXvXzd6.js";import{C as ts}from"./clock-DMkey-Ye.js";import{T as ss}from"./trash-2-DuhmMSCH.js";import{u as ns}from"./useLawyerSubscription-DvcKkrGQ.js";import{V as is}from"./VisaPromoBanner-CFcvYrOM.js";import{E as as}from"./jspdf.es.min-BwPd3Nws.js";import{P as E,T as N,f as rs,A as _,g as ls,e as os,F as cs,h as ms,i as us,B as ds,I as ps,d as Xe,a as Ze,W as He,S as Qe,b as hs}from"./FileSaver.min-TPampxK3.js";import{D as fs,a as gs,b as xs,c as et}from"./dropdown-menu-C4wafdtf.js";import{P as bs}from"./pen-line-C2mazCin.js";import{F as ws}from"./file-down-C7WaZh5M.js";import{C as Te}from"./crown-CayXwuvP.js";import{C as tt}from"./credit-card-CNY-kPb7.js";import{E as vs}from"./eye-yDhxOkfo.js";import{L as ys}from"./lock-Ad9P-h7W.js";import{B as js}from"./building-2-4SNP6Ag4.js";import"./zap-CyU0R1qD.js";import"./plus-BNPajLMA.js";import"./user-CcUIRpc_.js";import"./panel-left-DQjPX9y2.js";import"./log-out-CkU8Vx_b.js";import"./upload-DhyafyxF.js";import"./coins-CRu_Omx9.js";import"./index-KFRh6O9B.js";import"./en-US-wfBU2YNu.js";import"./endOfMonth-BsqzHdGd.js";import"./index-Ckyn2kv7.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const st=at("Bell",[["path",{d:"M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9",key:"1qo2s2"}],["path",{d:"M10.3 21a1.94 1.94 0 0 0 3.4 0",key:"qgo35s"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const nt=at("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);function _s({planId:e,planName:t,onInvited:n,mode:i="client"}){const[l,r]=g.useState(!1),[u,o]=g.useState(""),[p,a]=g.useState("editor"),c=i==="lawyer",d=c?"Invite Lawyer":"Invite Client",x=c?"Lawyer Email":"Client Email",b=c?"[email protected]":"[email protected]",[F,P]=g.useState(!1),R=async()=>{const k=u.trim().toLowerCase();if(!k||!k.includes("@")){T.error("Please enter a valid email address");return}P(!0);try{const{data:{user:I}}=await v.auth.getUser();if(!I)throw new Error("Not authenticated");const{data:he}=await v.from("plan_collaborators").select("id").eq("visa_business_plan_id",e).eq("email",k).maybeSingle();if(he){T.error("This email has already been invited to this plan"),P(!1);return}const{data:j}=await v.from("profiles").select("user_id").eq("email",k).maybeSingle(),{error:$}=await v.from("plan_collaborators").insert({visa_business_plan_id:e,email:k,user_id:(j==null?void 0:j.user_id)||null,role:p,invited_by:I.id,accepted_at:j!=null&&j.user_id?new Date().toISOString():null});if($)throw $;const{data:fe}=await v.from("law_firms").select("firm_name").eq("user_id",I.id).maybeSingle();let G=fe==null?void 0:fe.firm_name;if(!G){const{data:ge}=await v.from("visa_business_plans").select("business_name").eq("id",e).maybeSingle();G=(ge==null?void 0:ge.business_name)||void 0}const Se=typeof window<"u"?window.location.origin:"https://bizplanner.ai",{data:A,error:ze}=await v.functions.invoke("send-email",{body:{email_type:"client_invite",user_id:I.id,email:k,invite_plan_name:t,invite_firm_name:G||void 0,invite_role:p,invite_plan_id:e,invite_base_url:Se}});ze||!(A!=null&&A.success)?T.warning(`Client added, but email delivery failed for ${k}`):T.success(`Invitation sent to ${k}`),o(""),r(!1),n()}catch(I){console.error(I),T.error(I.message||"Failed to send invitation")}P(!1)};return s.jsxs(Mt,{open:l,onOpenChange:r,children:[s.jsx(Wt,{asChild:!0,children:s.jsxs(L,{variant:"outline",className:"gap-2",children:[s.jsx(nt,{className:"w-4 h-4"}),d]})}),s.jsxs(Vt,{className:"sm:max-w-md",children:[s.jsxs(qt,{children:[s.jsx(Gt,{children:d}),s.jsxs(Yt,{children:['Share "',t,'" with your ',c?"attorney":"client"," so they can view or edit the plan."]})]}),s.jsxs("div",{className:"space-y-4 py-4",children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ke,{htmlFor:"client-email",className:"flex items-center gap-2",children:[s.jsx(ot,{className:"w-3.5 h-3.5"})," ",x]}),s.jsx(Ht,{id:"client-email",type:"email",value:u,onChange:k=>o(k.target.value),placeholder:b,onKeyDown:k=>k.key==="Enter"&&R()})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx(Ke,{children:"Access Level"}),s.jsxs(gt,{value:p,onValueChange:k=>a(k),children:[s.jsx(xt,{children:s.jsx(bt,{})}),s.jsxs(wt,{children:[s.jsx(Je,{value:"editor",children:s.jsxs("div",{children:[s.jsx("span",{className:"font-medium",children:"Editor"}),s.jsx("span",{className:"text-muted-foreground ml-2 text-xs",children:"Can edit sections"})]})}),s.jsx(Je,{value:"viewer",children:s.jsxs("div",{children:[s.jsx("span",{className:"font-medium",children:"Viewer"}),s.jsx("span",{className:"text-muted-foreground ml-2 text-xs",children:"Read-only access"})]})})]})]})]})]}),s.jsxs(Jt,{children:[s.jsx(L,{variant:"ghost",onClick:()=>r(!1),children:"Cancel"}),s.jsxs(L,{onClick:R,disabled:F,className:"gap-2",children:[F?s.jsx(ue,{className:"w-4 h-4 animate-spin"}):s.jsx(nt,{className:"w-4 h-4"}),"Send Invitation"]})]})]})]})}const Ss={cover_page:"Cover Page",executive_summary:"Executive Summary",company_overview:"Company Overview",immigration_purpose:"Immigration Purpose",beneficiary_qualifications:"Beneficiary Profile",job_description:"Job Description & Duties",organizational_structure:"Organizational Structure",us_operations:"US Operations",parent_company:"Parent Company",market_analysis:"Market Analysis",competitive_analysis:"Competitive Analysis",marketing_strategy:"Marketing Strategy",financial_projections:"Financial Projections",financial_summary:"Financial Summary",parent_financials:"Parent Company Financials",staffing_plan:"Staffing & Job Creation",risk_analysis:"Risk Analysis",regulatory_compliance:"Regulatory Compliance",growth_strategy:"Growth Strategy",implementation_timeline:"Implementation Timeline",appendix:"Appendix & Supporting Documents"};function Ns({planId:e}){const[t,n]=g.useState([]),[i,l]=g.useState(0),[r,u]=g.useState(!1),[o,p]=g.useState(null);g.useEffect(()=>{v.auth.getUser().then(({data:{user:d}})=>{d&&p(d.id)})},[]);const a=g.useCallback(async()=>
11{if(!o||!e)return;const{data:d}=await v.from("comment_read_status").select("last_read_at").eq("user_id",o).eq("visa_business_plan_id",e).maybeSingle(),x=(d==null?void 0:d.last_read_at)||"1970-01-01T00:00:00Z",{data:b,error:F}=await v.from("plan_section_comments").select("id, section_type, content, created_at, user_id").eq("visa_business_plan_id",e).gt("created_at",x).neq("user_id",o).order("created_at",{ascending:!1});if(F||!b){n([]),l(0);return}const P=[...new Set(b.map(j=>j.user_id))],{data:R}=P.length>0?await v.from("profiles").select("user_id, full_name, email").in("user_id",P):{data:[]},k={};(R||[]).forEach(j=>{var $;k[j.user_id]=j.full_name||(($=j.email)==null?void 0:$.split("@")[0])||"Someone"});const I={};for(const j of b)I[j.section_type]||(I[j.section_type]={count:0,latest_at:j.created_at,latest_author:k[j.user_id]||"Someone",latest_content:j.content}),I[j.section_type].count++;const he=Object.entries(I).map(([j,$])=>({section_type:j,...$})).sort((j,$)=>new Date($.latest_at).getTime()-new Date(j.latest_at).getTime());n(he),l(b.length)},[o,e]);g.useEffect(()=>{a()},[a]),g.useEffect(()=>{if(!e)return;const d=v.channel(`bell-comments-${e}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"plan_section_comments",filter:`visa_business_plan_id=eq.${e}`},()=>a()).subscribe();return()=>{v.removeChannel(d)}},[e,a]);const c=async()=>{if(!o||!e)return;const d=new Date().toISOString(),{error:x}=await v.from("comment_read_status").upsert({user_id:o,visa_business_plan_id:e,last_read_at:d},{onConflict:"user_id,visa_business_plan_id"});x||(n([]),l(0),u(!1))};return s.jsxs(Kt,{open:r,onOpenChange:u,children:[s.jsx(Xt,{asChild:!0,children:s.jsxs(L,{variant:"outline",size:"icon",className:"relative",children:[s.jsx(st,{className:"w-4 h-4"}),i>0&&s.jsx("span",{className:"absolute -top-1 -right-1 bg-destructive text-destructive-foreground text-[10px] font-bold rounded-full w-5 h-5 flex items-center justify-center",children:i>99?"99+":i})]})}),s.jsxs(Zt,{align:"end",className:"w-80 p-0",children:[s.jsxs("div",{className:"px-4 py-3 border-b flex items-center justify-between",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Qt,{className:"w-4 h-4 text-primary"}),s.jsx("h4",{className:"font-semibold text-sm",children:"Comments"})]}),i>0&&s.jsx("button",{onClick:c,className:"text-xs text-primary hover:underline",children:"Mark all read"})]}),s.jsx("div",{className:"max-h-80 overflow-y-auto",children:t.length===0?s.jsxs("div",{className:"py-8 text-center",children:[s.jsx(st,{className:"w-8 h-8 text-muted-foreground/30 mx-auto mb-2"}),s.jsx("p",{className:"text-sm text-muted-foreground",children:"No new comments"})]}):t.map(d=>s.jsx(de,{to:`/visa/plan/${e}/edit/${d.section_type}?comments=open`,onClick:()=>u(!1),className:"block px-4 py-3 hover:bg-muted/50 border-b last:border-0 transition-colors",children:s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-medium text-sm text-foreground truncate",children:Ss[d.section_type]||d.section_type}),s.jsx("span",{className:"bg-primary/10 text-primary text-[10px] font-semibold px-1.5 py-0.5 rounded-full shrink-0",children:d.count})]}),s.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:[s.jsx("span",{className:"font-medium",children:d.latest_author}),": ",d.latest_content.slice(0,60),d.latest_content.length>60?"â¦":""]})]}),s.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 mt-0.5",children:es(new Date(d.latest_at),{addSuffix:!0})})]})},d.section_type))})]})]})}function Cs({planId:e,isOwner:t,refreshKey:n}){const[i,l]=g.useState([]),[r,u]=g.useState(!0);g.useEffect(()=>{o()},[e,n]);const o=async()=>{const{data:a,error:c}=await v.from("plan_collaborators").select("*").eq("visa_business_plan_id",e).order("created_at",{ascending:!1});!c&&a&&l(a),u(!1)},p=async(a,c)=>{if(!confirm(`Remove ${c} from this plan?`))return;const{error:d}=await v.from("plan_collaborators").delete().eq("id",a);d?T.error("Failed to remove collaborator"):(T.success(`${c} removed`),l(x=>x.filter(b=>b.id!==a)))};return r||i.length===0?null:s.jsxs("div",{className:"rounded-xl border border-border bg-card p-4",children:[s.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[s.jsx(rt,{className:"w-4 h-4 text-primary"}),s.jsx("h3",{className:"text-sm font-semibold",children:"Shared With"}),s.jsx(Ae,{variant:"secondary",className:"text-[10px] ml-auto",children:i.length})]}),s.jsx("div",{className:"space-y-2",children:i.map(a=>s.jsxs("div",{className:"flex items-center gap-3 py-2 px-3 rounded-lg bg-muted/50",children:[s.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center",children:a.accepted_at?s.jsx(lt,{className:"w-4 h-4 text-primary"}):s.jsx(ts,{className:"w-4 h-4 text-muted-foreground"})}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("p",{className:"text-sm font-medium truncate flex items-center gap-1.5",children:[s.jsx(ot,{className:"w-3 h-3 text-muted-foreground"}),a.email]}),s.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[s.jsx(Ae,{variant:a.role==="editor"?"default":"secondary",className:"text-[10px] px-1.5 py-0",children:a.role}),!a.accepted_at&&s.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Pending"})]})]}),t&&s.jsx(L,{variant:"ghost",size:"icon",className:"w-7 h-7 text-muted-foreground hover:text-destructive",onClick:()=>p(a.id,a.email),children:s.jsx(ss,{className:"w-3.5 h-3.5"})})]},a.id))})]})}const V=210,Pe=297,m=18,w=V-m*2,Fs=Pe-20,X=[15,76,129],ct=[232,240,249],ye=[201,168,76],B=[31,41,55],Re=[107,114,128],_e=[225,229,235],ks=[247,249,252],le=e=>{const t=Number(e);
11return Number.isFinite(t)?"$"+Math.round(t).toLocaleString("en-US"):"â"},Ts=e=>e.replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()),Es=e=>Ts(e.split(/\s+or\s+/i)[0].trim()),H=(e,t)=>e.setFillColor(t[0],t[1],t[2]),y=(e,t)=>e.setTextColor(t[0],t[1],t[2]),te=(e,t)=>e.setDrawColor(t[0],t[1],t[2]);function U(e,t,n,i=m+4){return t+n>Fs?(e.addPage(),i):t}function Ps(e,t,n,i){return t=U(e,t,18),H(e,X),e.rect(m,t,10,10,"F"),e.setFont("helvetica","bold"),e.setFontSize(11),y(e,[255,255,255]),e.text(String(i).padStart(2,"0"),m+5,t+6.8,{align:"center"}),y(e,X),e.setFontSize(14),e.text(n,m+14,t+7),te(e,ye),e.setLineWidth(.6),e.line(m+14,t+10.5,m+60,t+10.5),e.setLineWidth(.2),t+15}function As(e,t,n){y(e,B),e.setFont("helvetica","normal"),e.setFontSize(10);const i=4.6,l=t.split(/\n\s*\n/).map(r=>r.trim()).filter(Boolean);return l.forEach((r,u)=>{const o=e.splitTextToSize(r,w);o.forEach((p,a)=>{n=U(e,n,i);const c=a===o.length-1,d=p.trim(),x=d.split(/\s+/);if(c||x.length<2)e.text(d,m,n);else{const b=x.reduce((P,R)=>P+e.getTextWidth(R),0),F=(w-b)/(x.length-1);if(F>3)e.text(d,m,n);else{let P=m;x.forEach((R,k)=>{e.text(R,P,n),P+=e.getTextWidth(R)+F})}}n+=i}),u<l.length-1&&(n+=2.5)}),n+3}function je(e,t,n){H(e,X),e.rect(m,t,w,7,"F"),e.setFont("helvetica","bold"),e.setFontSize(8.5),y(e,[255,255,255]);let i=m;return n.forEach(l=>{const r=l.align==="right"?i+l.w-2:i+2;e.text(l.label,r,t+4.8,{align:l.align==="right"?"right":"left"}),i+=l.w}),t+7}function ee(e,t,n,i,l,r=!1){t=U(e,t,6.5),r?(H(e,ct),e.rect(m,t,w,6.5,"F")):l%2===0&&(H(e,ks),e.rect(m,t,w,6.5,"F")),e.setFont("helvetica",r?"bold":"normal"),e.setFontSize(8.5),y(e,B);let o=m;return n.forEach((p,a)=>{const c=i[a],d=c.align==="right"?o+c.w-2:o+2,x=e.splitTextToSize(p,c.w-4)[0]??p;e.text(x,d,t+4.5,{align:c.align==="right"?"right":"left"}),o+=c.w}),t+6.5}function Ds(e,t,n){const i=Object.entries(n).map(([c,d])=>({label:c.replace(/year/i,"Y").replace(/\s+/g,""),value:Number(d)||0})).filter(c=>c.value>0);if(i.length===0)return t;const l=34;t=U(e,t,l+10),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Revenue Projection",m,t),t+=4;const r=w,u=l-8,o=Math.max(...i.map(c=>c.value)),p=4,a=(r-p*(i.length+1))/i.length;return te(e,_e),e.line(m,t+u,m+r,t+u),i.forEach((c,d)=>{const x=o>0?c.value/o*u:0,b=m+p+d*(a+p),F=t+u-x;H(e,X),e.rect(b,F,a,x,"F"),y(e,B),e.setFont("helvetica","bold"),e.setFontSize(7.5),e.text(le(c.value),b+a/2,F-1.2,{align:"center"}),y(e,Re),e.setFont("helvetica","normal"),e.text(c.label,b+a/2,t+u+4,{align:"center"})}),t+l+4}function mt(e,t,n){if(n.length===0)return t;const i=14;t=U(e,t,i+2);const l=w/n.length;return H(e,ct),e.rect(m,t,w,i,"F"),n.forEach(([r,u],o)=>{const p=m+l*o+l/2;y(e,X),e.setFont("helvetica","bold"),e.setFontSize(11),e.text(u,p,t+6,{align:"center"}),y(e,Re),e.setFont("helvetica","normal"),e.setFontSize(7.5),e.text(r.toUpperCase(),p,t+11,{align:"center"})}),t+i+3}function Rs(e,t,n){if(!n)return t;const i=n.keyMetrics??{},l=[];if(i.grossMargin!=null&&l.push(["Gross Margin",String(i.grossMargin)]),i.netMargin!=null&&l.push(["Net Margin",String(i.netMargin)]),i.breakevenMonth!=null&&l.push(["Break-even",`Month ${i.breakevenMonth}`]),l.length&&(t=mt(e,t,l)),n.revenueProjections&&typeof n.revenueProjections=="object"&&(t=Ds(e,t,n.revenueProjections)),Array.isArray(n.startupCosts)&&n.startupCosts.length){t=U(e,t,20),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Startup Costs",m,t),t+=3.5;const r=[{label:"Item",w:w*.7,align:"left"},{label:"Amount",w:w*.3,align:"right"}];t=je(e,t,r);let u=0;n.startupCosts.forEach((o,p)=>{const a=Number(o.amount)||0;u+=a,t=ee(e,t,[String(o.item||o.name||""),le(a)],r,p)}),t=ee(e,t,["Total",le(u)],r,0,!0),t+=3}if(Array.isArray(n.fundingSources)&&n.fundingSources.length){t=U(e,t,20),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Funding Sources",m,t),t+=3.5;const r=[{label:"Source",w:w*.5,align:"left"},{label:"Type",w:w*.25,align:"left"},{label:"Amount",w:w*.25,align:"right"}];t=je(e,t,r);let u=0;n.fundingSources.forEach((o,p)=>{const a=Number(o.amount)||0;u+=a,t=ee(e,t,[String(o.source||""),String(o.type||""),le(a)],r,p)}),t=ee(e,t,["Total","",le(u)],r,0,!0),t+=3}return t}function zs(e,t,n){if(!n)return t;const i=[];if(n.totalJobsYear1!=null&&i.push(["Jobs Year 1",String(n.totalJobsYear1)]),n.totalJobsYear3!=null&&i.push(["Jobs Year 3",String(n.totalJobsYear3)]),n.totalJobsYear5!=null&&i.push(["Jobs Year 5",String(n.totalJobsYear5)]),i.length&&(t=mt(e,t,i)),Array.isArray(n.hiringPlan)&&n.hiringPlan.length){t=U(e,t,20),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Hiring Plan",m,t),t+=3.5;const u=[{label:"Position",w:w*.4,align:"left"},{label:"Timeline",w:w*.2,align:"left"},{label:"Salary",w:w*.25,align:"right"},{label:"Count",w:w*.15,align:"right"}];return t=je(e,t,u),n.hiringPlan.forEach((o,p)=>{t=ee(e,t,[String(o.role||o.position||""),String(o.timeline||""),String(o.salary??""),String(o.count??"")],u,p)}),t+=3,t}const l=n.staffingPlan||n.roles,r=n.years||[1,2,3,4,5];if(Array.isArray(l)&&l.length){t=U(e,t,20),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Staffing by Year",m,t),t+=3.5;const u=w*.4,o=(w-u)/r.length,p=[{label:"Position",w:u,align:"left"},...r.map(a=>({label:`Year ${a}`,w:o,align:"right"}))];t=je(e,t,p),l.forEach((a,c)=>{const d=a.counts||a.values||r.map((x,b)=>a[`year${b+1}`]??"");t=ee(e,t,[String(a.position||a.role||a.title||""),...d.map(x=>String(x??""))],p,c,!!a.isTotal)}),t+=3}return t}function Ls(e,t,n){if(!n||n.length===0)return t;t=U(e,t,20),e.setFont("helvetica","bold"),e.setFontSize(9.5),y(e,B),e.text("Source of Funds",m,t),t+=3.5;const i=[{label:"Source",w:w*.4,align:"left"},{label:"Type",w:w*.25,align:"left"},{label:"Amount",w:w*.2,align:"right"},{label:"Notes",w:w*.15,align:"left"}];t=je(e,t,i);let l=0;
11return n.forEach((r,u)=>{const o=Number(r.amount)||0;l+=o,t=ee(e,t,[String(r.source||""),String(r.type||""),le(o),String(r.note||"")],i,u)}),t=ee(e,t,["Total","",le(l),""],i,0,!0),t+3}function Is(e,t){if(H(e,X),e.rect(0,0,V,130,"F"),H(e,ye),e.rect(0,130,V,3,"F"),t.logoDataUrl)try{const o=e.getImageProperties(t.logoDataUrl),p=o.width/o.height;let a=40,c=a/p;c>26&&(c=26,a=c*p);const d=4,x=a+d*2,b=c+d*2,F=V-m-x,P=20;H(e,[255,255,255]),e.roundedRect(F,P,x,b,2,2,"F");const R=t.logoDataUrl.startsWith("data:image/png")?"PNG":"JPEG";e.addImage(t.logoDataUrl,R,F+d,P+d,a,c,void 0,"FAST")}catch{}y(e,[255,255,255]),e.setFont("helvetica","bold"),e.setFontSize(9),e.text("BUSINESS PLAN",m,32,{charSpace:1.6}),e.setFont("helvetica","bold"),e.setFontSize(30);const n=e.splitTextToSize(t.business_name||"Business",w);if(e.text(n.slice(0,3),m,58),t.tagline){e.setFont("helvetica","italic"),e.setFontSize(12),y(e,[220,232,245]);const r=e.splitTextToSize(t.tagline,w);e.text(r.slice(0,3),m,90)}H(e,[255,255,255]),e.rect(m,148,w,46,"F"),te(e,_e),e.rect(m,148,w,46);const i=w/2;if([["Visa Category",t.visa_label||t.visa_type],["Industry",t.industry?Es(t.industry):"â"],["Prepared For","Consulate Review"]].forEach(([r,u],o)=>{const p=Math.floor(o/2),a=o%2,c=m+6+a*i,d=158+p*20;y(e,Re),e.setFont("helvetica","bold"),e.setFontSize(7.5),e.text(r.toUpperCase(),c,d,{charSpace:1}),y(e,B),e.setFont("helvetica","bold"),e.setFontSize(11);const x=e.splitTextToSize(u,i-10);e.text(x[0]??u,c,d+6)}),t.highlights&&t.highlights.length){y(e,X),e.setFont("helvetica","bold"),e.setFontSize(11),e.text("Key Highlights",m,210),te(e,ye),e.setLineWidth(.6),e.line(m,212.5,m+40,212.5),e.setLineWidth(.2),y(e,B),e.setFont("helvetica","normal"),e.setFontSize(10);let r=220;t.highlights.slice(0,6).forEach(u=>{const o=e.splitTextToSize(u,w-8);H(e,ye),e.circle(m+1.5,r-1.3,1.1,"F"),y(e,B),e.text(o[0]??u,m+6,r),r+=o.length>1?5.5*o.length:6})}}function Bs(e,t){e.addPage(),y(e,X),e.setFont("helvetica","bold"),e.setFontSize(20),e.text("Table of Contents",m,m+8),te(e,ye),e.setLineWidth(.8),e.line(m,m+12,m+40,m+12),e.setLineWidth(.2);let n=m+24;y(e,B),e.setFont("helvetica","normal"),e.setFontSize(11),t.forEach((i,l)=>{n=U(e,n,8);const r=String(l+1).padStart(2,"0");y(e,X),e.setFont("helvetica","bold"),e.text(r,m,n),y(e,B),e.setFont("helvetica","normal"),e.text(i.title,m+10,n),te(e,_e),e.setLineDashPattern([.5,1.2],0),e.line(m+10+e.getTextWidth(i.title)+2,n-1,V-m-8,n-1),e.setLineDashPattern([],0),n+=8})}function Us(e,t){const n=e.getNumberOfPages();for(let i=2;i<=n;i++)e.setPage(i),te(e,_e),e.setLineWidth(.3),e.line(m,m-4,V-m,m-4),y(e,Re),e.setFont("helvetica","normal"),e.setFontSize(8),e.text(t,m,m-6.5),e.text("Business Plan",V-m,m-6.5,{align:"right"}),e.line(m,Pe-14,V-m,Pe-14),e.text(`Page ${i-1} of ${n-1}`,V-m,Pe-8,{align:"right"});e.setLineWidth(.2)}function $s(e){const t=new as({unit:"mm",format:"a4"}),n=e.business_name||"Business";Is(t,e),Bs(t,e.sections),t.addPage();let i=m+4;e.sections.forEach((r,u)=>{var o,p,a;u>0&&(i+=2),i=Ps(t,i,r.title,u+1),i=As(t,r.text,i),r.key==="financial_projections"?i=Rs(t,i,((o=e.structured)==null?void 0:o.financials)??null):r.key==="staffing_plan"?i=zs(t,i,((p=e.structured)==null?void 0:p.staffing)??null):r.key==="investment_analysis"&&(i=Ls(t,i,((a=e.structured)==null?void 0:a.sourceOfFunds)??null)),u<e.sections.length-1&&(i=U(t,i,6),te(t,_e),t.line(m,i,V-m,i),i+=5)}),Us(t,n);const l=n.replace(/[^a-z0-9]+/gi,"_").slice(0,60)||"condensed_plan";t.save(`${l}_condensed_business_plan.pdf`)}const pe="0F4C81",De="C9A84C",q="1F2937",ve="6B7280",Os="F7F9FC",re=e=>{const t=Number(e);return Number.isFinite(t)?"$"+Math.round(t).toLocaleString("en-US"):"â"},Hs=e=>e.replace(/\w\S*/g,t=>t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()),Ms=e=>Hs(e.split(/\s+or\s+/i)[0].trim());function Ws(e){return e.split(/\n\s*\n/).map(n=>n.trim()).filter(Boolean).map(n=>new E({alignment:_.JUSTIFIED,spacing:{after:100,line:260},children:[new N({text:n,size:20,color:q,font:"Calibri"})]}))}function Vs(e,t){return new E({spacing:{before:320,after:160},border:{bottom:{style:ds.SINGLE,size:8,color:De,space:4}},children:[new N({text:`${String(t).padStart(2,"0")} `,bold:!0,color:De,size:28,font:"Calibri"}),new N({text:e,bold:!0,color:pe,size:30,font:"Calibri"})]})}function it(e,t={}){return new E({alignment:t.align||_.LEFT,children:[new N({text:e,bold:t.bold,color:t.color||q,size:20,font:"Calibri"})]})}function oe(e,t,n,i){const r=n.map(p=>Math.round(9360*p)),u=new Xe({tableHeader:!0,children:e.map((p,a)=>new Ze({width:{size:r[a],type:He.DXA},shading:{fill:pe,type:Qe.CLEAR,color:"auto"},margins:{top:80,bottom:80,left:120,right:120},children:[it(p,{bold:!0,color:"FFFFFF",align:i[a]})]}))}),o=t.map((p,a)=>new Xe({children:p.map((c,d)=>new Ze({width:{size:r[d],type:He.DXA},shading:a%2===0?{fill:Os,type:Qe.CLEAR,color:"auto"}:void 0,margins:{top:60,bottom:60,left:120,right:120},children:[it(c,{align:i[d]})]}))}));return new hs({width:{size:9360,type:He.DXA},columnWidths:r,rows:[u,...o]})}function qs(e){const t=[];if(!e)return t;if(e.revenueProjections&&typeof e.revenueProjections=="object"){const n=Object.entries(e.revenueProjections).filter(([,i])=>Number(i)>0);n.length&&(t.push(new E({spacing:{before:160,after:80},children:[new N({text:"Revenue Projection",bold:!0,size:22,color:q,font:"Calibri"})]})),t.push(oe(["Period","Revenue"],n.map(([i,l])=>[i,re(l)]),[.6,.4],[_.LEFT,_.RIGHT])))}if(Array.isArray(e.startupCosts)&&e.startupCosts.length){let n=0;
11const i=e.startupCosts.map(l=>{const r=Number(l.amount)||0;return n+=r,[String(l.item||l.name||""),re(r)]});i.push(["Total",re(n)]),t.push(new E({spacing:{before:160,after:80},children:[new N({text:"Startup Costs",bold:!0,size:22,color:q,font:"Calibri"})]})),t.push(oe(["Item","Amount"],i,[.7,.3],[_.LEFT,_.RIGHT]))}if(Array.isArray(e.fundingSources)&&e.fundingSources.length){let n=0;const i=e.fundingSources.map(l=>{const r=Number(l.amount)||0;return n+=r,[String(l.source||""),String(l.type||""),re(r)]});i.push(["Total","",re(n)]),t.push(new E({spacing:{before:160,after:80},children:[new N({text:"Funding Sources",bold:!0,size:22,color:q,font:"Calibri"})]})),t.push(oe(["Source","Type","Amount"],i,[.5,.25,.25],[_.LEFT,_.LEFT,_.RIGHT]))}return t}function Gs(e){const t=[];if(!e)return t;if(Array.isArray(e.hiringPlan)&&e.hiringPlan.length){const l=e.hiringPlan.map(r=>[String(r.role||r.position||""),String(r.timeline||""),String(r.salary??""),String(r.count??"")]);return t.push(new E({spacing:{before:160,after:80},children:[new N({text:"Hiring Plan",bold:!0,size:22,color:q,font:"Calibri"})]})),t.push(oe(["Position","Timeline","Salary","Count"],l,[.4,.2,.25,.15],[_.LEFT,_.LEFT,_.RIGHT,_.RIGHT])),t}const n=e.staffingPlan||e.roles,i=e.years||[1,2,3,4,5];if(Array.isArray(n)&&n.length){const l=n.map(o=>{const p=o.counts||o.values||i.map((a,c)=>o[`year${c+1}`]??"");return[String(o.position||o.role||o.title||""),...p.map(a=>String(a??""))]}),r=.4,u=(1-r)/i.length;t.push(new E({spacing:{before:160,after:80},children:[new N({text:"Staffing by Year",bold:!0,size:22,color:q,font:"Calibri"})]})),t.push(oe(["Position",...i.map(o=>`Year ${o}`)],l,[r,...i.map(()=>u)],[_.LEFT,...i.map(()=>_.RIGHT)]))}return t}function Ys(e){if(!e||!e.length)return[];let t=0;const n=e.map(i=>{const l=Number(i.amount)||0;return t+=l,[String(i.source||""),String(i.type||""),re(l),String(i.note||"")]});return n.push(["Total","",re(t),""]),[new E({spacing:{before:160,after:80},children:[new N({text:"Source of Funds",bold:!0,size:22,color:q,font:"Calibri"})]}),oe(["Source","Type","Amount","Notes"],n,[.4,.25,.2,.15],[_.LEFT,_.LEFT,_.RIGHT,_.LEFT])]}function Js(e){const t=e.split(",")[1]||"",n=atob(t),i=new Uint8Array(n.length);for(let l=0;l<n.length;l++)i[l]=n.charCodeAt(l);return i}function Ks(e,t){try{if(t==="png"&&e.length>24){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);return{width:n.getUint32(16),height:n.getUint32(20)}}if(t==="jpg"||t==="jpeg"){let n=2;for(;n<e.length;){if(e[n]!==255)return null;const i=e[n+1];if(n+=2,i>=192&&i<=207&&i!==196&&i!==200&&i!==204){const r=e[n+3]<<8|e[n+4];return{width:e[n+5]<<8|e[n+6],height:r}}const l=e[n]<<8|e[n+1];n+=l}}}catch{}return null}function Xs(e){const t=[];if(e.logoDataUrl)try{const i=e.logoDataUrl.startsWith("data:image/png")?"png":"jpg",l=Js(e.logoDataUrl),r=Ks(l,i),u=160,o=100;let p=u,a=r?p*(r.height/r.width):u;a>o&&(a=o,p=r?a*(r.width/r.height):o),t.push(new E({alignment:_.CENTER,spacing:{before:400,after:200},children:[new ps({type:i,data:l,transformation:{width:Math.round(p),height:Math.round(a)}
11,altText:{title:"Logo",description:"Company logo",name:"logo"}})]}))}catch{}t.push(new E({alignment:_.CENTER,spacing:{before:200,after:100},children:[new N({text:"BUSINESS PLAN",bold:!0,size:24,color:De,font:"Calibri",characterSpacing:40})]})),t.push(new E({alignment:_.CENTER,spacing:{after:120},children:[new N({text:e.business_name||"Business",bold:!0,size:60,color:pe,font:"Calibri"})]})),e.tagline&&t.push(new E({alignment:_.CENTER,spacing:{after:400},children:[new N({text:e.tagline,italics:!0,size:26,color:ve,font:"Calibri"})]}));const n=[["Visa Category",e.visa_label||e.visa_type],["Industry",e.industry?Ms(e.industry):"â"],["Prepared For","Consulate Review"]];return t.push(oe(["Field","Value"],n,[.35,.65],[_.LEFT,_.LEFT])),e.highlights&&e.highlights.length&&(t.push(new E({spacing:{before:400,after:120},children:[new N({text:"Key Highlights",bold:!0,size:28,color:pe,font:"Calibri"})]})),e.highlights.slice(0,6).forEach(i=>{t.push(new E({spacing:{after:100},indent:{left:360,hanging:200},children:[new N({text:"⢠",bold:!0,color:De,size:22,font:"Calibri"}),new N({text:i,size:22,color:q,font:"Calibri"})]}))})),t}async function Zs(e){const t=e.business_name||"Business",n=Xs(e),i=[new E({spacing:{before:200,after:200},children:[new N({text:"Table of Contents",bold:!0,size:36,color:pe,font:"Calibri"})]}),...e.sections.map((c,d)=>new E({spacing:{after:100},children:[new N({text:`${String(d+1).padStart(2,"0")} `,bold:!0,color:pe,size:22,font:"Calibri"}),new N({text:c.title,size:22,color:q,font:"Calibri"})]}))],l=[];e.sections.forEach((c,d)=>{var x,b,F;l.push(Vs(c.title,d+1)),l.push(...Ws(c.text)),c.key==="financial_projections"?l.push(...qs(((x=e.structured)==null?void 0:x.financials)??null)):c.key==="staffing_plan"?l.push(...Gs(((b=e.structured)==null?void 0:b.staffing)??null)):c.key==="investment_analysis"&&l.push(...Ys(((F=e.structured)==null?void 0:F.sourceOfFunds)??null))});const r=new rs({children:[new E({alignment:_.RIGHT,children:[new N({text:`${t} | Page `,size:16,color:ve,font:"Calibri"}),new N({children:[ls.CURRENT],size:16,color:ve,font:"Calibri"})]})]}),u=new os({children:[new E({children:[new N({text:t,size:16,color:ve,font:"Calibri"}),new N({text:" Business Plan",size:16,color:ve,font:"Calibri"})]})]}),o=new cs({creator:"Bizplanner",title:`${t} Business Plan`,styles:{default:{document:{run:{font:"Calibri",size:22}}}},sections:[{properties:{page:{margin:{top:1080,right:1080,bottom:1080,left:1080}}},children:n},{properties:{page:{margin:{top:1440,right:1080,bottom:1080,left:1080}}},headers:{default:u},footers:{default:r},children:[...i,...l]}]}),p=await ms.toBlob(o),a=t.replace(/[^a-z0-9]+/gi,"_").slice(0,60)||"condensed_plan";us.saveAs(p,`${a}_condensed_business_plan.docx`)}const Ee={L1A:"L-1A Intracompany Transferee (Manager/Executive)",L1B:"L-1B Intracompany Transferee (Specialized Knowledge)",E2:"E-2 Treaty Investor",EB1C:"EB-1C Multinational Manager/Executive",EB2_NIW:"EB-2 National Interest Waiver",O1:"O-1 Extraordinary Ability",EB1A:"EB-1A Extraordinary Ability"},D=e=>e.replace(/<[^>]*>/g,"").trim(),Qs=e=>{if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.visa_generation_started_at;if(typeof t!="string")return null;const n=new Date(t).getTime();return Number.isFinite(n)?n:null},en=e=>{if(!e)return"";try{const t=JSON.parse(e);if(typeof t=="string")return D(t).slice(0,200);if(t.summary)return D(t.summary).slice(0,200);if(t.overview)return D(t.overview).slice(0,200);if(t.description)return D(t.description).slice(0,200);if(t.purpose)return D(t.purpose).slice(0,200);if(t.professionalBackground)return D(t.professionalBackground).slice(0,200);if(t.positionSummary)return D(t.positionSummary).slice(0,200);if(t.industryOverview)return D(t.industryOverview).slice(0,200);if(t.operationsOverview)return D(t.operationsOverview).slice(0,200);if(t.investmentOverview)return D(t.investmentOverview).slice(0,200);if(t.competitiveLandscape)return D(t.competitiveLandscape).slice(0,200);if(t.currentStaffing)return D(t.currentStaffing).slice(0,200);if(Array.isArray(t)&&t.length>0){const n=t[0];if(typeof n=="string")return D(n).slice(0,200);if(n.title)return D(n.title);if(n.description)return D(n.description).slice(0,200)}return""}catch{return D(e).slice(0,200)}},$n=()=>{const{planId:e}=vt(),[t,n]=g.useState(null),[i,l]=g.useState(!0),[r,u]=g.useState(!1),[o,p]=g.useState({}),[a,c]=g.useState(!1),[d,x]=g.useState(!1),[b,F]=g.useState(null),[P,R]=g.useState(0),[k,I]=g.useState({}),[he,j]=g.useState(!1),[$,fe]=g.useState(0),[G,Se]=g.useState(!1),[A,ze]=g.useState(null),[ge,ut]=g.useState(null),[Le,Me]=g.useState(!1),se=g.useRef(null),{isOwner:We,isCollaborator:Ie,isViewer:tn,canEdit:Ve}=Tt(e),xe=ns(A==="lawyer"),ne=g.useCallback(async h=>{if(e)try{const[f,C]=await Promise.all([v.from("visa_business_plans").select("*").eq("id",e).maybeSingle(),v.from("visa_plan_sections").select("section_type, content, updated_at").eq("visa_business_plan_id",e)]);if(!f.data){u(!0);return}n(f.data);const J=f.data.status==="generating",Q=J?Qs(f.data.metadata):null,we=h??b??Q,Fe=ke(f.data.visa_type),Ue=Fe.length,$e=new Set(Fe.map(W=>W.type));if(Q&&(!b||Q>b)&&(F(Q),R(0)),C.data){const W={},Ye={};C.data.forEach(ie=>{W[ie.section_type]=ie.content,ie.updated_at&&(Ye[ie.section_type]=new Date(ie.updated_at).getTime())}),p(W),I(Ye);
11const ft=Object.keys(W).filter(ie=>$e.has(ie)).length;J&&f.data.is_unlocked&&we||J&&f.data.is_unlocked&&ft<Ue?c(!0):we||c(!1)}else J&&f.data.is_unlocked&&c(!0)}catch(f){console.error("Error:",f)}finally{l(!1)}},[e,b]);g.useEffect(()=>{ne(),v.auth.getUser().then(({data:{user:h}})=>{h&&(ut(h.id),v.from("profiles").select("account_type").eq("user_id",h.id).maybeSingle().then(({data:f})=>{f&&ze(f.account_type)}))})},[ne]),g.useEffect(()=>{if(!t||t.is_unlocked||!e||A!=="lawyer"||xe.loading||!xe.subscribed)return;(async()=>{try{const{error:f}=await v.from("visa_business_plans").update({is_unlocked:!0,status:"completed"}).eq("id",e);if(!f){T.success("Plan unlocked with your subscription!"),ne();const{data:C}=await v.from("visa_plan_sections").select("id").eq("visa_business_plan_id",e).limit(1);(!C||C.length===0)&&(await v.functions.invoke("generate-visa-plan",{body:{planId:e}}),c(!0))}}catch(f){console.error("Auto-unlock failed:",f)}})()},[t,A,xe.loading,xe.subscribed,e]),g.useEffect(()=>(a&&e&&(se.current=setInterval(()=>{ne()},8e3)),()=>{se.current&&clearInterval(se.current)}),[a,e,ne]);const z=t?ke(t.visa_type).length:21;g.useEffect(()=>{if(b&&z>0){const h=new Set(ke(t==null?void 0:t.visa_type).map(C=>C.type)),f=Object.entries(k).filter(([C,J])=>h.has(C)&&J>=b).length;R(f),f>=z&&(c(!1),x(!1),F(null),se.current&&clearInterval(se.current),T.success("Your visa plan is ready! All sections have been regenerated."));return}a&&Object.keys(o).length>=z&&z>0&&(c(!1),x(!1),se.current&&clearInterval(se.current),T.success("Your visa plan is ready! All sections have been generated."))},[o,k,a,z,b,t==null?void 0:t.visa_type]);const dt=async()=>{if(e){x(!0),c(!0);try{const{error:h}=await v.functions.invoke("generate-visa-plan",{body:{planId:e}});if(h)throw h;T.success("AI generation started! Your plan sections will appear shortly."),ne()}catch(h){console.error("Generation error:",h),T.error(h.message||"Failed to start generation"),c(!1),x(!1)}}},pt=async()=>{if(!e||d||a)return;const h=Date.now();j(!1),x(!0),c(!0),F(h),R(0);try{const{error:f}=await v.functions.invoke("generate-visa-plan",{body:{planId:e,regenerate:!0}});if(f)throw f;T.success("Plan regeneration started! Existing sections will be rewritten with the latest visa-specific framing."),ne(h)}catch(f){console.error("Regeneration error:",f),T.error(f.message||"Failed to start regeneration"),c(!1),x(!1),F(null)}},S=h=>h in o,Z=h=>en(o[h]),ht=new Set(ke(t==null?void 0:t.visa_type).map(h=>h.type)),O=Object.keys(o).filter(h=>ht.has(h)).length,Y=(t==null?void 0:t.is_unlocked)===!0,M=We||!!(t!=null&&t.user_id)&&ge===t.user_id,Ne=t==null?void 0:t.visa_type,ce=Ne==="EB2_NIW",be=Ne==="EB1A",qe=h=>!Et(Ne,h),me=(h,f)=>Pt(Ne,h,f),Be=async()=>{if(e){Se(!0);try{if(A==="lawyer"){const{data:h,error:f}=await v.functions.invoke("create-lawyer-checkout",{body:{plan:"monthly",planId:e}});if(f||!(h!=null&&h.url))throw new Error((f==null?void 0:f.message)||"Failed to create checkout");window.location.href=h.url}else{const{data:h,error:f}=await v.functions.invoke("create-visa-checkout",{body:{planId:e}});if(f||!(h!=null&&h.url))throw new Error((f==null?void 0:f.message)||"Failed to create checkout");window.location.href=h.url}}catch(h){T.error(h.message||"Something went wrong"),Se(!1)}}},Ce=A==="lawyer"&&xe.trial,Ge=async(h="pdf")=>{if(!e||Le)return;if(Ce){T.error("Exports are disabled during the free trial. Subscribe to unlock.");return}Me(!0);const f=T.loading(`Generating your 10-page condensed brief (${h==="word"?"Word":"PDF"})...`);try{const{data:C,error:J}=await v.functions.invoke("condense-visa-plan",{body:{planId:e}});if(J)throw J;if(!C||!Array.isArray(C.sections)||C.sections.length===0)throw new Error("Condensed plan came back empty. Try again in a moment.");let Q=null;if(C.logoUrl)try{const Fe=await(await fetch(C.logoUrl,{mode:"cors"})).blob();Q=await new Promise((Ue,$e)=>{const W=new FileReader;W.onloadend=()=>Ue(W.result),W.onerror=$e,W.readAsDataURL(Fe)})}catch(we){console.warn("Logo fetch failed, exporting without logo",we)}h==="word"?await Zs({...C,logoDataUrl:Q}):$s({...C,logoDataUrl:Q}),T.success("Condensed brief downloaded",{id:f})}catch(C){console.error("Condensed export failed:",C),T.error((C==null?void 0:C.message)||"Failed to generate condensed brief",{id:f})}finally{Me(!1)}};return i?s.jsx(Oe,{planId:e||"",children:s.jsxs("div",{className:"animate-pulse space-y-4",children:[s.jsx("div",{className:"h-8 bg-muted rounded w-1/3"}),s.jsx("div",{className:"h-4 bg-muted rounded w-1/4"})]})}):r||!t?s.jsx(Oe,{planId:e||"",children:s.jsxs("div",{className:"max-w-xl",children:[s.jsx("h1",{className:"text-2xl font-semibold",children:"Visa plan not found"}),s.jsx("p",{className:"mt-2 text-muted-foreground",children:"This visa business plan doesn't exist, or you don't have access to it."}),s.jsxs("div",{className:"mt-6 flex flex-wrap gap-3",children:[s.jsx(L,{asChild:!0,children:s.jsx(de,{to:"/dashboard",children:"Go to dashboard"})}),s.jsx(L,{variant:"outline",asChild:!0,children:s.jsx(de,{to:"/visa/get-started",children:"Create a new visa plan"})})]})]})}):s.jsxs(Oe,{planId:e||"",children:[!Y&&M&&A!=="lawyer"&&s.jsx("div",{className:"-mx-4 sm:-mx-6 lg:-mx-8 -mt-6 mb-6 rounded-none",children:s.jsx(is,{onClaim:Be,disabled:G})}),s.jsx("div",{className:"mb-8",children:s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-3xl font-bold font-display",children:t.business_name||t.title}),s.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[s.jsx(Ae,{variant:"secondary",className:"text-xs",children:Ee[t.visa_type]||t.visa_type}),t.industry&&s.jsx("span",{className:"text-sm text-muted-foreground",children:t.industry}),Ie&&s.jsx(Ae,{variant:Ve?"default":"outline",className:"text-xs",children:Ve?"Editor Access":"View Only"})]}),(t.petitioner_name||t.beneficiary_name)&&s.jsxs("div",{className:"flex gap-4 mt-3 text-sm text-muted-foreground",children:[t.petitioner_name&&s.jsxs("span",{children:["Petitioner: ",s.jsx("strong",{className:"text-foreground",children:t.petitioner_name})]}),t.beneficiary_name&&s.jsxs("span",{children:["Beneficiary: ",s.jsx("strong",{className:"text-foreground",children:t.beneficiary_name})]})]})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(Ns,{planId:e}),M&&!Ce&&s.jsx(_s,{planId:e,planName:t.business_name||t.title,onInvited:()=>fe(h=>h+1),mode:A==="lawyer"?"client":"lawyer"}),M&&Y&&O===0&&!a&&s.jsx(L,{variant:"outline",onClick:dt,disabled:d,children:d?s.jsxs(s.Fragment,{children:[s.jsx(ue,{className:"w-4 h-4 mr-2 animate-spin"}),"Generating..."]}):s.jsxs(s.Fragment,{children:[s.jsx(yt,{className:"w-4 h-4 mr-2"}),"Generate Plan"]})}),M&&Y&&O>0&&!a&&s.jsxs(Dt,{open:he,onOpenChange:j,children:[s.jsx(Rt,{asChild:!0,children:s.jsxs(L,{variant:"outline",className:"gap-2",children:[s.jsx(jt,{className:"w-4 h-4"}),"Regenerate Plan"]})}),s.jsxs(zt,{children:[s.jsxs(Lt,{children:[s.jsx(It,{children:"Regenerate this plan?"}),s.jsx(Bt,{children:"This will rewrite all sections using the latest AI prompts and visa-specific framing. Your current content will be replaced. This action cannot be undone."})]}),s.jsxs(Ut,{children:[s.jsx($t,{children:"Cancel"}),s.jsx(Ot,{onClick:pt,children:"Regenerate"})]})]})]}),M&&Y&&s.jsx(de,{to:`/visa/plan/${e}/edit/cover_page`,children:s.jsxs(L,{variant:"hero",children:[s.jsx(bs,{className:"w-4 h-4 mr-2"}),"Open Editor"]})}),Y&&O>0&&!Ce&&(We||Ie||M)&&s.jsxs(fs,{children:[s.jsx(gs,{asChild:!0,children:s.jsx(L,{variant:"outline",disabled:Le,className:"gap-2",title:"AI-summarized 10-page brief for consulate interviews",children:Le?s.jsxs(s.Fragment,{children:[s.jsx(ue,{className:"w-4 h-4 animate-spin"}),"Condensing..."]}):s.jsxs(s.Fragment,{children:[s.jsx(ws,{className:"w-4 h-4"}),"10-Page Brief"]})})}),s.jsxs(xs,{align:"end",children:[s.jsx(et,{onClick:()=>Ge("pdf"),children:"Download as PDF"}),s.jsx(et,{onClick:()=>Ge("word"),children:"Download as Word"})]})]}),M&&!Y&&s.jsx(L,{onClick:Be,disabled:G,children:G?s.jsxs(s.Fragment,{children:[s.jsx(ue,{className:"w-4 h-4 mr-2 animate-spin"}),"Processing..."]}):A==="lawyer"?s.jsxs(s.Fragment,{children:[s.jsx(Te,{className:"w-4 h-4 mr-2"}),"Start Free Trial"]}):s.jsxs(s.Fragment,{children:[s.jsx(tt,{className:"w-4 h-4 mr-2"}),"Unlock â ",s.jsx("span",{className:"line-through opacity-60 ml-1 mr-1",children:"$399"})," $199.50"]})}),Ie&&s.jsx(de,{to:`/visa/plan/${e}/preview`,children:s.jsxs(L,{variant:"hero",children:[s.jsx(vs,{className:"w-4 h-4 mr-2"}),"View Full Plan"]})})]})]})}),M&&s.jsx("div",{className:"mb-6",children:s.jsx(Cs,{planId:e,isOwner:M,refreshKey:$})}),a&&(b?P<z:O<z)&&s.jsxs("div",{className:"mb-6 rounded-xl border border-primary/20 bg-primary/5 p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(ue,{className:"w-5 h-5 text-primary animate-spin shrink-0"}),s.jsxs("div",{children:[s.jsx("p",{className:"font-semibold text-foreground text-sm",children:b?"Regenerating your visa business plan...":"AI is generating your visa business plan..."}),s.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:[b?P:O," of ",z," sections ready â this usually takes 5-10 minutes"]})]})]}),s.jsx(At,{value:(b?P:O)/z*100,className:"h-2"})]}),!Y&&M&&s.jsx("div",{className:"mb-6 rounded-xl border-2 border-primary/30 bg-primary/5 p-6",children:s.jsxs("div",{className:"flex items-start justify-between gap-4",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center shrink-0 mt-0.5",children:A==="lawyer"?s.jsx(Te,{className:"w-5 h-5 text-primary"}):s.jsx(ys,{className:"w-5 h-5 text-primary"})}),s.jsxs("div",{children:[s.jsx("h3",{className:"font-semibold text-foreground text-lg",children:A==="lawyer"?"Start Your Free Trial":"Unlock Your Visa Business Plan"}),s.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:A==="lawyer"?"Try free for 3 days. Get full access to all plan features with your subscription.":`Get a complete, USCIS-ready ${ce?"self-petition narrative":"business plan"} with ${z} AI-generated sections tailored to your ${Ee[t==null?void 0:t.visa_type]||(t==null?void 0:t.visa_type)}
11 petition.`}),s.jsxs("ul",{className:"mt-3 space-y-1.5 text-sm text-muted-foreground",children:[s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," ",z," specialized sections for USCIS compliance"]}),s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," Financial projections & market analysis"]}),A==="lawyer"?s.jsxs(s.Fragment,{children:[s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," 2 client plans per month included"]}),s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," PDF & Word export (after trial)"]})]}):s.jsxs(s.Fragment,{children:[s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," Lifetime access with PDF & Word export"]}),s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx(ae,{className:"w-4 h-4 text-primary shrink-0"})," In-browser editing & AI-assisted revisions"]})]})]})]})]}),s.jsxs("div",{className:"text-right shrink-0",children:[A==="lawyer"?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"text-3xl font-bold text-foreground",children:"$499"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"per month after trial"})]}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-baseline justify-end gap-2",children:[s.jsx("p",{className:"text-lg font-medium text-muted-foreground line-through",children:"$399"}),s.jsx("p",{className:"text-3xl font-bold text-foreground",children:"$199.50"})]}),s.jsx("p",{className:"text-xs text-primary font-semibold mt-0.5",children:"50% OFF auto-applied (VISA50)"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"one-time payment · lifetime access"})]}),s.jsx(L,{onClick:Be,disabled:G,className:"mt-3 w-full",size:"lg",children:G?s.jsxs(s.Fragment,{children:[s.jsx(ue,{className:"w-4 h-4 mr-2 animate-spin"}),"Processing..."]}):A==="lawyer"?s.jsxs(s.Fragment,{children:[s.jsx(Te,{className:"w-4 h-4 mr-2"}),"Start Free Trial"]}):s.jsxs(s.Fragment,{children:[s.jsx(tt,{className:"w-4 h-4 mr-2"}),"Unlock Now â $199.50"]})})]})]})}),Ce&&Y&&s.jsxs("div",{className:"mb-6 rounded-xl border border-amber-200 bg-amber-50 p-4 flex items-center gap-3",children:[s.jsx(Te,{className:"w-5 h-5 text-amber-600 shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"font-semibold text-foreground text-sm",children:"Free Trial Active"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"PDF/Word export and sharing are disabled during the trial. Subscribe to unlock all features."})]})]}),!a&&O>0&&Y&&s.jsxs("div",{className:"mb-6 rounded-xl border border-green-300 bg-green-50 p-4 flex items-center gap-3",children:[s.jsx(ae,{className:"w-5 h-5 text-green-600 shrink-0"}),s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"font-semibold text-foreground text-sm",children:O===z?"Your visa plan is ready":`${O} of ${z} sections ready`}),s.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:O===z?'All sections generated. Click "Open Editor" to review or download your plan.':'Click "Open Editor" or use the sidebar to edit any section'})]}),O===z&&s.jsx(L,{asChild:!0,size:"sm",className:"shrink-0",children:s.jsx(de,{to:`/visa/plan/${e}/preview`,children:"Preview Plan"})})]}),s.jsxs("div",{className:"grid md:grid-cols-2 lg:grid-cols-3 gap-6",children:[s.jsx(K,{title:"Your Plan",icon:s.jsx(_t,{className:"w-5 h-5"}),iconColor:"text-muted-foreground",linkHref:`/visa/plan/${e}/edit/cover_page`,linkText:"Open full document",children:s.jsx("div",{className:"space-y-3",children:s.jsxs("div",{children:[s.jsx("p",{className:"font-medium text-foreground",children:t.business_name||t.title}),s.jsxs("p",{className:"text-xs text-muted-foreground",children:[Ee[t.visa_type]||t.visa_type," Business Plan"]})]})})}),s.jsx(K,{title:me("company_overview","Company Overview"),icon:s.jsx(js,{className:"w-5 h-5"}),iconColor:"text-blue-500",linkHref:`/visa/plan/${e}/edit/company_overview`,linkText:S("company_overview")?"View & edit":"Start writing",className:a&&!S("company_overview")?"animate-pulse opacity-60":"",children:S("company_overview")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("company_overview")||(be?"Beneficiary profile ready":ce?"Proposed endeavor overview ready":"Company overview content ready")}):s.jsx("p",{className:"text-sm text-muted-foreground",children:be?"Introduce the beneficiary, area of extraordinary ability, and self-petition context":ce?"Describe the proposed endeavor, its origin, and current state":"Describe your company's background, mission, and operations"})}),s.jsx(K,{title:me("immigration_purpose","Immigration Purpose"),icon:s.jsx(St,{className:"w-5 h-5"}),iconColor:"text-purple-500",linkHref:`/visa/plan/${e}/edit/immigration_purpose`,linkText:S("immigration_purpose")?"Vie
11w & edit":"Start writing",className:a&&!S("immigration_purpose")?"animate-pulse opacity-60":"",children:S("immigration_purpose")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("immigration_purpose")||"Immigration context ready"}):s.jsxs("p",{className:"text-sm text-muted-foreground",children:["How this business plan supports the ",Ee[t.visa_type]||t.visa_type," petition"]})}),s.jsx(K,{title:me("beneficiary_qualifications","Beneficiary Profile"),icon:s.jsx(lt,{className:"w-5 h-5"}),iconColor:"text-green-600",linkHref:`/visa/plan/${e}/edit/beneficiary_qualifications`,linkText:S("beneficiary_qualifications")?"View & edit":"Start writing",className:a&&!S("beneficiary_qualifications")?"animate-pulse opacity-60":"",children:S("beneficiary_qualifications")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("beneficiary_qualifications")||"Qualifications documented"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:t.beneficiary_name?`Document ${t.beneficiary_name}'s qualifications and experience`:"Document the beneficiary's qualifications, education, and achievements"})}),qe("job_description")&&s.jsx(K,{title:"Job Description & Duties",icon:s.jsx(Nt,{className:"w-5 h-5"}),iconColor:"text-orange-500",linkHref:`/visa/plan/${e}/edit/job_description`,linkText:S("job_description")?"View & edit":"Start writing",className:a&&!S("job_description")?"animate-pulse opacity-60":"",children:S("job_description")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("job_description")||"Job duties documented"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Detail the proposed position, duties, and qualifications"})}),s.jsx(K,{title:me("market_analysis","Market Analysis"),icon:s.jsx(Ct,{className:"w-5 h-5"}),iconColor:"text-primary",linkHref:`/visa/plan/${e}/edit/market_analysis`,linkText:S("market_analysis")?"View & edit":"Start writing",className:a&&!S("market_analysis")?"animate-pulse opacity-60":"",children:S("market_analysis")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("market_analysis")||"Market analysis ready"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:be?"Describe the field and the beneficiary's standing at the top":ce?"Analyze the field landscape and national relevance of the endeavor":"Analyze market size, growth trends, and industry dynamics"})}),s.jsx(K,{title:me("financial_projections","Financial Projections"),icon:s.jsx(Ft,{className:"w-5 h-5"}),iconColor:"text-green-600",linkHref:`/visa/plan/${e}/edit/financial_projections`,linkText:S("financial_projections")?"View financials":"Start writing",className:a&&!S("financial_projections")?"animate-pulse opacity-60":"",children:S("financial_projections")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("financial_projections")||"Financial projections ready"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:be?"Sustaining support, compensation, and resources for continued U.S. work":ce?"Resources required to advance the endeavor and projected impact":"Revenue forecasts, startup costs, and 5-year financial projections"})}),qe("staffing_plan")&&s.jsx(K,{title:"Staffing & Job Creation",icon:s.jsx(rt,{className:"w-5 h-5"}),iconColor:"text-blue-500",linkHref:`/visa/plan/${e}/edit/staffing_plan`,linkText:S("staffing_plan")?"View plan":"Start writing",className:a&&!S("staffing_plan")?"animate-pulse opacity-60":"",children:S("staffing_plan")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("staffing_plan")||"Staffing plan documented"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:"Hiring plans and job creation projections to demonstrate economic impact"})}),s.jsx(K,{title:me("risk_analysis","Risk Analysis"),icon:s.jsx(kt,{className:"w-5 h-5"}),iconColor:"text-red-500",linkHref:`/visa/plan/${e}/edit/risk_analysis`,linkText:S("risk_analysis")?"View risks":"Start writing",className:a&&!S("risk_analysis")?"animate-pulse opacity-60":"",children:S("risk_analysis")?s.jsx("p",{className:"line-clamp-3 text-sm",children:Z("risk_analysis")||"Risk analysis complete"}):s.jsx("p",{className:"text-sm text-muted-foreground",children:be?"Final Merits Determination and evidence of sustained acclaim":ce?"Balancing test and justification for waiving the job-offer requirement":"Identify business risks and mitigation strategies"})})]})]})};export{$n 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.