import{u as L,r as o,b as E,j as e,dE as I}from"./vendor-rThclpOQ.js";import{I as F}from"./input-error-Br4ngfdE.js";import{L as O}from"./loading-button-DKhpmf6V.js";import{I as i}from"./input-BeqyurrI.js";import{L as c}from"./label-CtY1vfZY.js";import{o as j}from"./inertia-SZXqLvQm.js";import"./utils-8KAaAB9H.js";import"./button-ZcsoqUQn.js";import"./index-DquVdLUg.js";const A=()=>{const{auth:m,errors:h,translate:g}=L().props,{button:f,input:t,common:P}=g,d=m.user,[v,k]=o.useState(d.photo),[n,x]=o.useState({website:"",facebook:"",twitter:"",linkedin:""}),y=o.useCallback(s=>{try{if(!s)return;const r=typeof s=="string"?JSON.parse(s):s,a={website:"",facebook:"",twitter:"",linkedin:""};r.forEach(l=>{l.host in a&&(a[l.host]=l.profile_link)}),x(a)}catch{}},[]);o.useEffect(()=>{y(d.social_links)},[d.social_links]);const b=o.useCallback(s=>{const r=Object.entries(s).filter(([a,l])=>l).map(([a,l])=>({host:a,profile_link:l}));return JSON.stringify(r)},[]),p=o.useCallback((s,r)=>{x(a=>({...a,[s]:r}))},[]),{data:w,post:N,setData:u,processing:C}=E({name:d.name||"",photo:null,social_links:null});o.useEffect(()=>{u("social_links",b(n))},[n,b,u]);const _=s=>{s.preventDefault(),N(route("student.profile.update"))},S=(s,r)=>{u(s,r),k(URL.createObjectURL(r))};return e.jsxs("form",{onSubmit:_,className:"bg-card grid grid-cols-1 gap-6 rounded-lg p-6 md:grid-cols-2",children:[e.jsxs("div",{className:"col-span-full space-y-1",children:[e.jsx("div",{className:"border-border h-[150px] w-[150px] rounded-full border border-dashed p-1.5",children:e.jsxs("div",{className:"border-border relative h-full w-full overflow-hidden rounded-full border",children:[e.jsx("img",{alt:`${m.user.name}'s profile`,src:v||"/assets/icons/avatar.png",className:"h-full w-full content-center object-cover"}),e.jsxs("label",{htmlFor:"formFile",className:"text-primary-foreground absolute right-0 bottom-0 flex h-full w-full cursor-pointer flex-col items-center justify-center gap-2 bg-black/50 opacity-0 transition-opacity duration-300 hover:opacity-100",children:[e.jsx(I,{className:"h-7 w-7"}),e.jsx("span",{className:"text-xs",children:f.upload})]}),e.jsx("input",{hidden:!0,type:"file",id:"formFile",name:"photo",onChange:s=>j(s,S)})]})}),h.photo&&e.jsx("p",{className:"mt-1 text-sm text-red-500",children:h.photo})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(c,{children:t.name}),e.jsx(i,{type:"text",name:"name",value:w.name,onChange:s=>j(s,u),placeholder:t.full_name_placeholder}),e.jsx(F,{message:h.name})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(c,{children:t.website}),e.jsx(i,{type:"url",name:"website",value:n.website,onChange:s=>p("website",s.target.value),placeholder:t.https_placeholder})]}),e.jsxs("div",{children:[e.jsx(c,{children:t.facebook}),e.jsx(i,{type:"url",value:n.facebook,onChange:s=>p("facebook",s.target.value),placeholder:t.https_placeholder})]}),e.jsxs("div",{children:[e.jsx(c,{children:t.twitter}),e.jsx(i,{type:"url",value:n.twitter,onChange:s=>p("twitter",s.target.value),placeholder:t.https_placeholder})]}),e.jsxs("div",{children:[e.jsx(c,{children:t.linkedin}),e.jsx(i,{type:"url",value:n.linkedin,onChange:s=>p("linkedin",s.target.value),placeholder:t.https_placeholder})]}),e.jsx("div",{className:"col-span-full flex items-center justify-end pt-2",children:e.jsx(O,{loading:C,className:"col-span-full",children:f.update})})]})};export{A as default};
