import{u as b,c as j,j as e,d as f,M as o,e as u}from"./index-D9pJRAs5.js";import{r as _}from"./vendor-D6aTFYy9.js";import{b3 as w,aa as k,ab as D,N as S,B as E,ad as N,D as M,L as P,n as R}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const L=({isOpen:t,onClose:i,employee:l})=>{const{t:a}=b(),{addEmployee:x,updateEmployee:y}=j(),[n,h]=_.useState(!1),[d,m]=_.useState({name:"",email:"",role:"Worker",department:"Production",hourlyRate:15,salary:3e3,startDate:new Date,allowedProcesses:[]});if(_.useEffect(()=>{t&&m(l?{name:l.name,email:l.email,role:l.role,department:l.department,hourlyRate:l.hourlyRate,salary:l.salary,startDate:new Date(l.startDate),allowedProcesses:l.allowedProcesses||[]}:{name:"",email:"",role:"Worker",department:"Production",hourlyRate:15,salary:3e3,startDate:new Date,allowedProcesses:[]})},[t,l]),!t)return null;const r=c=>{const{name:s,value:p}=c.target;m(v=>({...v,[s]:s==="hourlyRate"||s==="salary"?parseFloat(p)||0:p}))},g=async c=>{c.preventDefault(),h(!0);try{l?y(l.id,d):x({...d,hoursWorked:0,totalEarnings:0}),i()}catch(s){console.error("Error saving employee:",s),alert(a("hr_modals.add_edit_employee.error_save"))}finally{h(!1)}};return e.jsx(f,{isOpen:t,onClose:i,title:a(l?"hr_modals.add_edit_employee.title_edit":"hr_modals.add_edit_employee.title_add"),subtitle:a("hr_modals.add_edit_employee.subtitle"),icon:w,variant:"info",maxWidth:"max-w-2xl",children:e.jsxs("form",{onSubmit:g,className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-6",children:[e.jsx("div",{className:"sm:col-span-2",children:e.jsx(o,{label:a("hr_modals.add_edit_employee.full_name"),icon:k,name:"name",value:d.name,onChange:r,required:!0,placeholder:a("hr_modals.add_edit_employee.name_placeholder")})}),e.jsx("div",{className:"sm:col-span-2",children:e.jsx(o,{label:a("hr_modals.add_edit_employee.email"),icon:D,type:"email",name:"email",value:d.email,onChange:r,required:!0,placeholder:a("hr_modals.add_edit_employee.email_placeholder")})}),e.jsx("div",{children:e.jsxs(u,{label:a("hr_modals.add_edit_employee.role"),icon:S,name:"role",value:d.role,onChange:r,children:[e.jsx("option",{value:"Worker",children:a("hr_modals.add_edit_employee.roles.worker")}),e.jsx("option",{value:"Manager",children:a("hr_modals.add_edit_employee.roles.manager")}),e.jsx("option",{value:"Admin",children:a("hr_modals.add_edit_employee.roles.admin")}),e.jsx("option",{value:"Sales",children:a("hr_modals.add_edit_employee.roles.sales")}),e.jsx("option",{value:"Designer",children:a("hr_modals.add_edit_employee.roles.designer")})]})}),e.jsx("div",{children:e.jsxs(u,{label:a("hr_modals.add_edit_employee.department"),icon:E,name:"department",value:d.department,onChange:r,children:[e.jsx("option",{value:"Production",children:a("hr_modals.add_edit_employee.departments.production")}),e.jsx("option",{value:"Sales",children:a("hr_modals.add_edit_employee.departments.sales")}),e.jsx("option",{value:"Design",children:a("hr_modals.add_edit_employee.departments.design")}),e.jsx("option",{value:"Admin",children:a("hr_modals.add_edit_employee.departments.admin")}),e.jsx("option",{value:"Logistics",children:a("hr_modals.add_edit_employee.departments.logistics")})]})}),e.jsx("div",{children:e.jsx(o,{label:a("hr_modals.add_edit_employee.hourly_rate"),icon:N,type:"number",name:"hourlyRate",value:d.hourlyRate,onChange:r,min:"0",step:"0.5"})}),e.jsx("div",{children:e.jsx(o,{label:a("hr_modals.add_edit_employee.base_salary"),icon:M,type:"number",name:"salary",value:d.salary,onChange:r,min:"0",step:"100"})})]}),e.jsxs("div",{className:"pt-6 border-t dark:border-gray-800 flex flex-col sm:flex-row justify-end gap-3",children:[e.jsx("button",{type:"button",onClick:i,disabled:n,className:"w-full sm:w-auto px-8 py-3.5 bg-gray-200 dark:bg-gray-700 text-gray-700 dark:text-gray-200 rounded-2xl font-black uppercase tracking-widest text-[10px] hover:bg-gray-300 dark:hover:bg-gray-600 transition-all active:scale-95 order-2 sm:order-1 disabled:opacity-50",children:a("hr_modals.add_edit_employee.discard")}),e.jsxs("button",{type:"submit",disabled:n,className:"w-full sm:w-auto px-10 py-3.5 bg-blue-600 hover:bg-blue-700 text-white rounded-2xl font-black uppercase tracking-widest text-[10px] shadow-xl shadow-blue-500/20 transition-all active:scale-95 flex items-center justify-center space-x-2 order-1 sm:order-2 disabled:opacity-50",children:[n?e.jsx(P,{size:16,className:"animate-spin"}):e.jsx(R,{size:16}),e.jsx("span",{children:a(l?"hr_modals.add_edit_employee.save_changes":"hr_modals.add_edit_employee.onboard")})]})]})]})})};export{L as default};
