import{q as h,r as b,S as k,j as e,J as F}from"./app-DB4YCWeF.js";import{I as o}from"./Input-BfNm_9oA.js";import{S as j,d as L,u as E}from"./Select-DXXQNVxU.js";import{m as U}from"./BaseForm-CkSb_d40.js";import{u as A}from"./useFormChange-B0pYJsvh.js";function J({userData:l=null}){const{location:m,status:r=null,roles:u=null,owners:_=null}=h().props,x=h().props.auth.user,t=x?x.role:"guest",[c,g]=b.useState((l==null?void 0:l.picture)??null),{data:a,setData:f,post:d,processing:p,errors:w,reset:v}=k({location:m,name:(l==null?void 0:l.name)??"",username:(l==null?void 0:l.username)??"",phone:(l==null?void 0:l.phone)??"",email:(l==null?void 0:l.email)??"",role:(l==null?void 0:l.role)??"user",status:(l==null?void 0:l.status)??"active",picture:c??"",password:"",password_confirmation:""});b.useEffect(()=>{if(m){const s=new URLSearchParams(new URL(m).search);s.get("role")&&f(i=>({...i,role:s.get("role")}))}return()=>{v("password","password_confirmation")}},[]);function N(s){let{name:i,value:P,files:S}=A(s,a);["picture"].includes(i)&&g(URL.createObjectURL(S[0])),f(R=>({...R,[i]:P}))}const y=s=>{if(s.preventDefault(),l)return a._method="put",d(`/admin/users/${l.id}`);["admin"].includes(t)?d("/admin/users"):d("/register")},n={handleChange:N,data:a,errors:w};return e.jsxs("form",{onSubmit:y,className:"flex flex-col items-center justify-center w-full gap-4 p-4 border rounded-lg shadow-lg",children:[["admin"].includes(t)?e.jsx("p",{className:"text-lg font-semibold",children:l?"Edit Pengguna":"Tambah Pengguna"}):null,e.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-4",children:[e.jsx(o,{type:"text",name:"name",label:"nama",...n}),l?e.jsx(o,{type:"text",name:"username",label:"username",...n}):null,e.jsx(o,{type:"email",name:"email",label:"email",...n})]}),e.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-4",children:[e.jsx(o,{type:"tel",name:"phone",label:"nomor whatsapp",alt:"Opsional",...n}),e.jsx(o,{type:"password",name:"password",label:"password",...n}),e.jsx(o,{type:"password",name:"password_confirmation",label:"Konfirmasi Password",...n})]}),e.jsxs("div",{className:"flex flex-col md:flex-row w-full gap-4",children:[e.jsxs("div",{className:"flex gap-2 items-end w-full",children:[e.jsx(o,{type:"file",name:"picture",label:"Upload Foto",alt:"Opsional",...n,accept:U("image")}),c?e.jsx("img",{src:c,alt:"Foto Profil",className:"w-16 h-16 object-cover rounded-full"}):null]}),["admin"].includes(t)&&r?e.jsxs(e.Fragment,{children:[e.jsxs(j,{name:"status",label:"status",...n,defaultValue:a.status,children:[e.jsx("option",{value:"",children:"Pilih salah satu"}),r.length==0?null:r.map((s,i)=>e.jsx("option",{value:s,className:"capitalize",children:L(s)},i))]}),e.jsxs(j,{name:"role",label:"role",...n,defaultValue:a.role,children:[e.jsx("option",{value:"",children:"Pilih salah satu"}),u.length==0?null:u.map((s,i)=>e.jsx("option",{value:s,className:"capitalize",children:E(s)},i))]})]}):null]}),e.jsx("div",{className:"flex flex-col gap-4 my-4",children:e.jsx("div",{className:"flex flex-col",children:["admin"].includes(t)?e.jsx("button",{className:"btn btn-sm btn-primary",disabled:p,children:l?"Edit Akun":"Tambah Akun"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"btn btn-sm btn-primary",disabled:p,children:"Buat Akun"}),e.jsx("div",{className:"divider",children:"Atau"}),e.jsx(F,{href:"/login",className:"mx-auto btn btn-sm btn-primary btn-outline w-max",disabled:p,children:"Masuk ke akunmu"})]})})})]})}export{J as R};
