import{u as F,r as m,b as E,j as e,cJ as _}from"./vendor-BKmmeuxg.js";import{I as u}from"./input-error-LaPr_4wd.js";import{L as I}from"./loading-button-BnTVAMJ7.js";import{T as P}from"./tag-input-BqUWHOBp.js";import{I as d}from"./input-DM0goJrn.js";import{L as t}from"./label-HmIcv5Yx.js";import{T as J}from"./textarea-CyndvowL.js";import{o as p}from"./inertia-SZXqLvQm.js";import{t as O}from"./index-D9-QKOod.js";import"./utils-DxSsnXxD.js";import"./button-BpNwv2aE.js";import"./index-WW_1X1qx.js";const K=({instructor:a})=>{const{auth:k,system:T,errors:c}=F().props,l=k.user,[j,v]=m.useState(l.photo),[h,f]=m.useState({website:"",github:"",twitter:"",linkedin:""}),y=m.useCallback(s=>{try{if(!s)return;const r=typeof s=="string"?JSON.parse(s):s,n={website:"",github:"",twitter:"",linkedin:""};r.forEach(o=>{o.host in n&&(n[o.host]=o.profile_link)}),f(n)}catch{O.error("Failed to parse social links")}},[]);m.useEffect(()=>{y(l.social_links)},[l.social_links]);const b=m.useCallback(s=>Object.entries(s).filter(([n,o])=>o).map(([n,o])=>({host:n,profile_link:o})),[]),x=m.useCallback((s,r)=>{f(n=>({...n,[s]:r}))},[]),w=a!=null&&a.skills?typeof a.skills=="string"?JSON.parse(a.skills):a.skills:[],{data:g,post:N,setData:i,processing:C}=E({name:l.name||"",photo:null,social_links:[],user_id:l.id,skills:w,designation:(a==null?void 0:a.designation)||"",biography:(a==null?void 0:a.biography)||"",resume:null});m.useEffect(()=>{i("social_links",b(h))},[h,b,i]);const S=s=>{s.preventDefault(),N(route("account.profile"))},L=(s,r)=>{i(s,r),v(URL.createObjectURL(r))};return e.jsxs("form",{onSubmit:S,className:"bg-card space-y-6 rounded-lg border p-6 shadow",children:[e.jsxs("div",{className:"flex flex-col items-center gap-6 sm:flex-row",children:[e.jsxs("div",{className:"flex w-full flex-col items-center space-y-3 text-center md:max-w-[160px]",children:[e.jsxs("div",{className:"relative mb-4 h-[100px] w-[100px]",children:[j?e.jsx("img",{alt:"item-1",src:j,className:"h-[100px] w-[100px] rounded-full object-cover"}):e.jsx("div",{className:"h-[100px] w-[100px] rounded-full bg-gray-300"}),e.jsx("label",{htmlFor:"formFileSm",className:"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",children:e.jsx("div",{className:"flex h-10 w-10 cursor-pointer items-center justify-center rounded-full bg-gray-100",children:e.jsx(_,{className:"h-6 w-6 text-gray-500"})})}),e.jsx("input",{hidden:!0,type:"file",id:"formFileSm",name:"photo",onChange:s=>p(s,L)})]}),e.jsx("small",{className:"text-xs text-gray-500",children:"Allowed: JPG, JPEG, PNG, SVG File, Maximum 2MB"}),c.photo&&e.jsx("p",{className:"mt-1 text-sm text-red-500",children:c.photo})]}),e.jsxs("div",{className:"grid w-full grid-cols-1 gap-6 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(t,{children:"Website"}),e.jsx(d,{type:"url",name:"website",value:h.website,onChange:s=>x("website",s.target.value),className:"mt-1",placeholder:"https://example.com"})]}),e.jsxs("div",{children:[e.jsx(t,{children:"GitHub"}),e.jsx(d,{type:"url",name:"github",value:h.github,onChange:s=>x("github",s.target.value),className:"mt-1",placeholder:"https://github.com/my-profile"})]}),e.jsxs("div",{children:[e.jsx(t,{children:"Twitter"}),e.jsx(d,{type:"url",name:"twitter",value:h.twitter,onChange:s=>x("twitter",s.target.value),className:"mt-1",placeholder:"https://twitter.com/my-profile"})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"linkedin",children:"LinkedIn"}),e.jsx(d,{id:"linkedin",name:"linkedin",value:h.linkedin,onChange:s=>x("linkedin",s.target.value),className:"mt-1",placeholder:"https://linkedin.com/my-profile"})]})]})]}),e.jsxs("div",{children:[e.jsx(t,{htmlFor:"name",children:"Full Name"}),e.jsx(d,{id:"name",name:"name",value:g.name,onChange:s=>p(s,i),className:"mt-1",placeholder:"John Doe"}),e.jsx(u,{message:c.name})]}),(l.role==="admin"&&l.instructor_id||l.role==="instructor")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(t,{children:"Designation"}),e.jsx(d,{name:"designation",value:g.designation,onChange:s=>p(s,i),placeholder:"Software Engineer"}),e.jsx(u,{message:c.designation})]}),l.role==="instructor"&&e.jsxs("div",{children:[e.jsx(t,{children:"Resume"}),e.jsx(d,{readOnly:!0,type:"file",name:"resume",onChange:s=>p(s,i)}),e.jsx(u,{message:c.resume})]}),e.jsxs("div",{children:[e.jsx(t,{children:"Skills"}),e.jsx(P,{defaultTags:g.skills,placeholder:"Enter the skills as a tag",onChange:s=>i("skills",s)})]}),e.jsxs("div",{className:"pb-3",children:[e.jsx(t,{children:"Biography"}),e.jsx(J,{rows:5,required:!0,name:"biography",value:g.biography,onChange:s=>p(s,i),placeholder:"Write about yourself"}),e.jsx(u,{message:c.biography})]})]}),e.jsx("div",{className:"col-span-full pt-2",children:e.jsx(I,{loading:C,children:"Save Changes"})})]})};export{K as default};