import{e as z,r as x,j as e,C as g,f as U}from"./index-sga-FecS.js";import{u as v}from"./DefaultLayout-R679muSx.js";import{b as c,a as A}from"./index.esm-7CdJvro0.js";import{C as n,a as i}from"./CRow-BaMSc2yS.js";import{C as d}from"./CAlert-UiIGbbv-.js";import{C as D,a as E}from"./CCardBody-e8lVonr1.js";import{C as R}from"./CCardHeader-B7SoQ3bq.js";import{C as B}from"./CForm-C4v7yst3.js";import{C as I}from"./CFormInput-DmJ_XO-V.js";import"./university-logo-full-HPG0vyLU.js";import"./cil-user-Dlmw-Gem.js";function O(){const{t:r,i18n:C}=z(),{user:m,loading:_,error:y}=v(),[h,f]=x.useState(null),[t,a]=x.useState({type:"",text:"",errors:[]}),[p,j]=x.useState(!1),b=["admin","registrar"],N=m&&m.role&&b.includes(m.role),w=C.language==="ar"?"/ar":"/en",F=l=>{f(l.target.files[0]),a({type:"",text:"",errors:[]})},S=async l=>{if(l.preventDefault(),!h){a({type:"error",text:r("select_file")});return}j(!0),a({type:"",text:"",errors:[]});const o=new FormData;o.append("file",h);try{const s=await U.post(`${w}/api/import-accepted-students/`,o,{headers:{"Content-Type":"multipart/form-data"}});s.status===206?a({type:"warning",text:s.data.message,errors:s.data.errors||[]}):a({type:"success",text:s.data.message,errors:[]}),f(null)}catch(s){console.error("File upload error:",s);let u=r("file_upload_error",{message:s.message});s.response&&s.response.data&&s.response.data.detail?u=s.response.data.detail:s.response&&s.response.data?.file?.[0]&&(u=s.response.data.file[0]),a({type:"error",text:u,errors:[]})}finally{j(!1)}};return _?e.jsx(c,{fluid:!0,className:"py-4",children:e.jsx(n,{children:e.jsxs(i,{children:[e.jsx(g,{size:"sm"})," ",r("loading_user")]})})}):y?e.jsx(c,{fluid:!0,className:"py-4",children:e.jsx(n,{children:e.jsx(i,{children:e.jsx(d,{color:"danger",children:r("error_loading_user")})})})}):N?e.jsxs(c,{fluid:!0,className:"py-4",children:[e.jsx(n,{className:"mb-3",children:e.jsxs(i,{children:[e.jsx("h2",{className:"mb-1",children:r("import_accepted_students_title")}),e.jsx("p",{className:"text-medium-emphasis mb-0",children:r("import_accepted_students_subtitle")})]})}),e.jsx(n,{children:e.jsx(i,{md:8,lg:6,children:e.jsxs(D,{children:[e.jsx(R,{children:r("import_accepted_students_header")}),e.jsxs(E,{children:[t.text&&e.jsx(d,{color:t.type==="success"?"success":t.type==="error"?"danger":"warning",className:"mb-3",children:t.text}),t.errors&&t.errors.length>0&&e.jsx(d,{color:"warning",className:"mb-3",children:e.jsx("ul",{className:"mb-0",children:t.errors.map((l,o)=>e.jsx("li",{children:l},o))})}),e.jsxs(B,{onSubmit:S,children:[e.jsx(I,{type:"file",accept:".xlsx,.xls,.csv",onChange:F,label:r("select_file_label"),disabled:p,className:"mb-3"}),e.jsx("div",{className:"d-flex gap-2 align-items-center",children:e.jsx(A,{type:"submit",color:"primary",disabled:p,children:p?e.jsxs(e.Fragment,{children:[e.jsx(g,{size:"sm"})," ",r("uploading")]}):r("upload_file")})}),e.jsx("p",{className:"text-medium-emphasis small mt-3 mb-0",children:r("import_accepted_students_help")})]})]})]})})})]}):e.jsx(c,{fluid:!0,className:"py-4",children:e.jsx(n,{children:e.jsx(i,{children:e.jsx(d,{color:"warning",children:r("not_authorized")})})})})}export{O as default};
