1import{u as k,j as e,R as C,a as O,b as R,c as U,d as A,r as p,A as j,L as q,g as E,e as D}from"./index-DI8w2tsm.js";const L=encodeURIComponent("/institution/sign-up");function Q(){const{data:n,isPending:d}=k();return d?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"})}):n?.user?e.jsx(M,{email:n.user.email,name:n.user.name}):e.jsx(C,{to:`/sign-up?redirect=${L}`})}function M({email:n,name:d}){const m=O(),{data:i,isLoading:x}=R(),{data:u}=U(),c=A(),[s,r]=p.useState({institutionName:"",country:"",city:"",websiteUrl:"",description:"",contactName:d??"",numberOfStudents:""}),[f,N]=p.useState([]),[y,v]=p.useState(!1),[h,g]=p.useState(null),w=t=>{N(o=>o.includes(t)?o.filter(b=>b!==t):[...o,t])};if(x)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background",children:e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"})});if(i&&i.status!=="rejected"&&!y)return e.jsx(j,{application:i});if(y&&i)return e.jsx(j,{application:i});const S=t=>{t.preventDefault(),g(null);const o=s.numberOfStudents.trim();let b=null;if(o!==""){const a=Number(o);if(!Number.isInteger(a)||a<0){g("Number of students must be a non-negative whole number");return}b=a}c.mutate({data:{institutionName:s.institutionName.trim(),country:s.country.trim(),city:s.city.trim(),websiteUrl:s.websiteUrl.trim()||null,description:s.description.trim(),contactName:s.contactName.trim(),numberOfStudents:b,directoryIds:f}},{onSuccess:()=>{m.invalidateQueries({queryKey:E()}),m.invalidateQueries({queryKey:D()}),v(!0)},onError:a=>{const I=a instanceof Error?a.message:"Failed to submit application";g(I)}})};return e.jsx("div",{className:"min-h-screen bg-background py-10 px-4",children:e.jsxs("div",{className:"max-w-2xl mx-auto bg-card border border-border rounded-xl shadow-sm p-8",children:[e.jsx(q,{href:"/",className:"text-sm text-muted-foreground hover:text-foreground",children:"â Back to home"}),e.jsx("h1",{className:"text-3xl font-serif font-bold text-foreground mt-4 mb-2",children:"Apply to list your institution"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Fill in your institution's basic details. Our team will review and approve eligible applicants â typically within a few business days."}),i?.status==="rejected"&&e.jsxs("div",{className:"mb-6 rounded-md border border-destructive/40 bg-destructive/5 p-4 text-sm",children:[e.jsx("p",{className:"font-medium text-destructive",children:"Your previous application was declined."}),i.rejectionReason&&e.jsxs("p",{className:"mt-1 text-muted-foreground",children:["Reason: ",i.rejectionReason]}),e.jsx("p",{className:"mt-1 text-muted-foreground",children:"You may submit an updated application below."})]}),e.jsxs("form",{onSubmit:S,className:"space-y-4","data-testid":"institution-application-form",children:[e.jsx(l,{label:"Institution name *",value:s.institutionName,onChange:t=>r({...s,institutionName:t}),required:!0,testId:"field-institutionName"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsx(l,{label:"Country *",value:s.country,onChange:t=>r({...s,country:t}),required:!0,testId:"field-country"}),e.jsx(l,{label:"City *",value:s.city,onChange:t=>r({...s,city:t}),required:!0,testId:"field-city"})]}),e.jsx(l,{label:"Website",value:s.websiteUrl,onChange:t=>r({...s,websiteUrl:t}),placeholder:"https://your-institution.edu",testId:"field-websiteUrl"}),e.jsx(l,{label:"Your name *",value:s.contactName,onChange:t=>r({...s,contactName:t}),required:!0,testId:"field-contactName"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1",children:"Number of students"}),e.jsx("input",{type:"number",inputMode:"numeric",min:0,step:1,value:s.numberOfStudents,onChange:t=>r({...s,numberOfStudents:t.target.value}),placeholder:"e.g. 12000","data-testid":"field-numberOfStudents",className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1",children:"About your institution"}),e.jsx("textarea",{value:s.description,onChange:t=>r({...s,description:t.target.value}),rows:4,className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring","data-testid":"field-description"})]}),u&&u.length>0&&e.jsxs("fieldset",{"data-testid":"directory-checkboxes",children:[e.jsx("legend",{className:"block text-sm font-medium text-foreground mb-1",children:"Which directories would you like to list your courses on?"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Optional â select any that apply. Our team will see your preferences when reviewing your application."}),e.jsx("div",{className:"space-y-2 rounded-md border border-border bg-background p-3",children:u.map(t=>e.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f.includes(t.id),onChange:()=>w(t.id),"data-testid":`directory-checkbox-${t.id}
1`,className:"h-4 w-4 rounded border-border accent-primary"}),t.name]},t.id))})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Submitting as ",e.jsx("strong",{children:n})]}),h&&e.jsx("p",{className:"text-sm text-destructive","data-testid":"application-error",children:h}),e.jsx("button",{type:"submit",disabled:c.isPending,"data-testid":"submit-application",className:"w-full rounded-md bg-primary text-primary-foreground font-medium py-2.5 hover:bg-primary/90 disabled:opacity-60",children:c.isPending?"Submittingâ¦":"Submit application"})]})]})})}function l({label:n,value:d,onChange:m,required:i,placeholder:x,testId:u}){return e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-foreground mb-1",children:n}),e.jsx("input",{type:"text",value:d,onChange:c=>m(c.target.value),required:i,placeholder:x,"data-testid":u,className:"w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring"})]})}export{Q 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.