1import{c as pe,V as se,U as Ve,r as f,u as q,s as m,W as z,t as h,j as e,B as x,aY as Be,m as ge,L as $e,d as Ne,D as G,g as we,h as W,i as H,k as X,a5 as Z}from"./index-CC7LeppY.js";import{g as ke}from"./student-info.functions-C8Alni7P.js";import{r as Qe}from"./instructor-admin.functions-3Mdil7Ar.js";import{B as J}from"./badge-CSoMkE9d.js";import{C as P,b as M,c as V,d as Re,a as A}from"./card-CZnJ2TeO.js";import{I as _}from"./input-CP1rm5Jz.js";import{L as j}from"./label-BDrGmM36.js";import{C as ee}from"./checkbox-BeyvdgSY.js";import{i as xe}from"./image-url-Bb3SltRr.js";import{L as C}from"./loader-circle-DNIotRoX.js";import{T as he}from"./trash-2-CT18mOkT.js";import{A as Ie}from"./arrow-left-1FZJGIF0.js";import{C as Te}from"./car-BfkvNnzw.js";import{U as Ue}from"./user-Coico82R.js";import{C as Oe}from"./chevron-left-CGgS5eD1.js";import{C as Ye}from"./chevron-right-C3jhp7DR.js";import{P as Je}from"./plus-R0wRMqAv.js";import{B as Ge}from"./ban-C-Q3_QU5.js";import{T as _e}from"./triangle-alert-CkkF4Ncm.js";import{P as We}from"./pencil-Ckeankd1.js";import"./check-sFveOP9a.js";const He=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Xe=pe("image",He);const Ze=[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]],es=pe("power",Ze);const ss=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],Ce=pe("upload",ss);function ts({instructorId:a}){const u=se(),p=Ve(),v=f.useRef(null),{data:c,isLoading:y}=q({queryKey:["car-photos",a],queryFn:async()=>{if(!a)return[];const{data:n,error:l}=await m.from("car_photos").select("*").eq("instructor_id",a).order("created_at",{ascending:!1});if(l)throw l;return n??[]},enabled:!!a}),d=z({mutationFn:async n=>{if(!a)throw new Error(p("Vispirms saglabÄ profilu","СнаÑала ÑоÑ
Ñани пÑоÑилÑ","Save the profile first"));const l=n.name.split(".").pop()||"jpg",i=`${a}/${Date.now()}.${l}`,{error:k}=await m.storage.from("car-photos").upload(i,n,{cacheControl:"3600"});if(k)throw k;const{data:F}=m.storage.from("car-photos").getPublicUrl(i),{error:L}=await m.from("car_photos").insert({instructor_id:a,url:F.publicUrl});if(L)throw L},onSuccess:()=>{h.success(p("Foto augÅ¡upielÄdÄts","ФоÑо загÑÑжено","Photo uploaded")),u.invalidateQueries({queryKey:["car-photos",a]}),v.current&&(v.current.value="")},onError:n=>h.error(n.message)}),r=z({mutationFn:async n=>{const l=n.url.split("/car-photos/").pop();l&&await m.storage.from("car-photos").remove([l]);const{error:i}=await m.from("car_photos").delete().eq("id",n.id);if(i)throw i},onSuccess:()=>{h.success(p("Foto dzÄsts","ФоÑо Ñдалено","Photo removed")),u.invalidateQueries({queryKey:["car-photos",a]})},onError:n=>h.error(n.message)}),o=n=>{const l=n.target.files?.[0];l&&d.mutate(l)};return e.jsxs(P,{children:[e.jsxs(M,{className:"flex flex-row items-start justify-between gap-4 space-y-0",children:[e.jsxs("div",{children:[e.jsx(V,{children:p("Auto bildes","ФоÑо авÑомобилÑ","Car photos")}),e.jsx(Re,{children:p("Bildes, ko redzÄs studenti tavÄ profilÄ.","ФоÑо, коÑоÑÑе ÑÑÑденÑÑ ÑвидÑÑ Ð² ÑвоÑм пÑоÑиле.","Photos students will see on your profile.")})]}),e.jsxs(x,{onClick:()=>v.current?.click(),disabled:d.isPending||!a,variant:"outline",size:"sm",children:[d.isPending?e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Ce,{className:"w-4 h-4 mr-2"}),p("AugÅ¡upielÄdÄt","ÐагÑÑзиÑÑ","Upload")]}),e.jsx("input",{ref:v,type:"file",accept:"image/*",className:"hidden",onChange:o})]}),e.jsx(A,{children:a?y?e.jsx("div",{className:"grid place-items-center py-8",children:e.jsx(C,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):!c||c.length===0?e.jsxs("div",{className:"py-8 text-center text-muted-foreground border border-dashed rounded-lg",children:[e.jsx(Xe,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:p("Nav augÅ¡upielÄdÄtu bilžu.","ÐагÑÑженнÑÑ
ÑоÑо неÑ.","No uploaded photos.")})]}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:c.map(n=>e.jsxs("div",{className:"group relative rounded-lg border border-border bg-card overflow-hidden",children:[e.jsx("img",{src:xe(n.url,320),alt:p("Auto","ÐвÑо","Car"),className:"w-full h-32 object-cover",loading:"lazy"}),e.jsx("div",{className:"absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition flex items-end justify-end p-2",children:e.jsx(x,{variant:"destructive",size:"icon",onClick:()=>r.mutate(n),children:e.jsx(he,{className:"w-4 h-4"})})})]},n.id))}):e.jsx("p",{className:"text-sm text-muted-foreground",children:p("Vispirms saglabÄ profilu, lai pievienotu auto bildes.","СнаÑала ÑоÑ
Ñани пÑоÑилÑ, ÑÑÐ¾Ð±Ñ Ð´Ð¾Ð±Ð°Ð²Ð¸ÑÑ ÑоÑо авÑо.","Save the profile first to add car photos.")})})]})}const as=["P","O","T","C","Pk","S","Sv"],rs={weekday:"Darba diena",weekday_evening:"Vakars",weekend:"NedÄļas nogale"};function E(a){const u=a.getFullYear(),p=String(a.getMonth()+1).padStart(2,"0"),v=String(a.getDate()).padStart(2,"0");return`${u}-${p}-${v}`}function is(a,u){const[p,v]=a.split(":").map(Number),c=p*60+v+u,y=String(Math.floor(c/60)%24).padStart(2,"0"),d=String(c%60).padStart(2,"0");return`${y}:${d}`}function Ps(){const{id:a}=Be.useParams(),u=se(),p=ge(ke),v=f.useRef(null),[c,y]=f.useState(()=>{const s=new Date;return new Date(s.getFullYear(),s.getMonth(),1)}),[d,r]=f.useState(()=>E(new Date)),[o,n]=f.useState("all"),[l,i]=f.useState(null),[k,F]=f.useState(null),[L,B]=f.useState(null),[re,R]=f.useState(""),[Se,ie]=f.useState(!1),[N,$]=f.useState({date:E(new Date),start_time:"10:00",duration:90,price_category:"weekday",price:"25"}),{data:b}=q({queryKey:["admin-instructor",a],queryFn:async()=>{const{data:s,error:t}=await m.rpc("get_instructor_full",{_id:a});if(t)throw t;if(!s||s.length===0)throw new Error("Not found");return s[0]}}),{data:I}=q({queryKey:["admin-instructor-pricing",a],queryFn:async()=>{const{data:s}=await m.from("instructor_pricing").select("*").eq("instructor_id",a).maybeSingle();return s}}),T=f.useMemo(()=>{const s=new Date(c),t=(s.getDay()+6)%7;return s.setDate(s.getDate()-t),s},[c]),je=f.useMemo(()=>{const s=new Date(T);return s.setDate(s.getDate()+41),s},[T]),{data:ve}=q({queryKey:["admin-instr-month",a,E(T),E(je)],queryFn:async()=>{const{data:s,error:t}=await m.from("time_slots").select("id,date,status").eq("instructor_id",a).gte("date",E(T)).lte("date",E(je));if(t)throw t;return s}}),{data:fe,isLoading:qe}=q({queryKey:["admin-instr-day",a,d],queryFn:async()=>{const{data:s,error:t}=await m.from("time_slots").select("*").eq("instructor_id",a).eq("date",d).order("start_time");if(t)throw t;return s}}),{data:U}=q({queryKey:["admin-instr-stats",a],queryFn:async()=>{const{data:s,error:t}=await m.from("time_slots").select("status, price").eq("instructor_id",a);if(t)throw t;const g=s??[],w=g.filter(D=>D.status==="completed").length,S=g.filter(D=>D.status==="booked").length,K=g.filter(D=>D.status==="canceled").length,ae=g.filter(D=>D.status==="available").length,Le=g.filter(D=>D.status==="booked"||D.status==="completed").reduce((D,Me)=>D+(Number(Me.price)||0),0);return{total:g.length,completed:w,booked:S,canceled:K,available:ae,revenue:Le}}}),ne=b?.user_id??null,{data:ze}=q({queryKey:["admin-instr-wallet",ne],queryFn:async()=>{const{data:s,error:t}=await m.from("wallets").select("balance").eq("user_id",ne).maybeSingle();if(t)throw t;return Number(s?.balance??0)},enabled:!!ne}),{data:O}=q({queryKey:["admin-instr-lessons",a],queryFn:async()=>{const{data:s,error:t}=await m.from("time_slots").select("id,date,start_time,end_time,status,price,student_id,admin_deleted_at,late_cancel_paid,no_show").eq("instructor_id",a).in("status",["booked","completed","canceled"]).order("date",{ascending:!1}).order("start_time",{ascending:!1}).limit(200);if(t)throw t;return s}}),te=f.useMemo(()=>(O??[]).filter(s=>s.status==="canceled").map(s=>s.id),[O]),{data:De}=q({queryKey:["admin-instr-cancel-acts",a,te],queryFn:async()=>
1{if(te.length===0)return{};const{data:s,error:t}=await m.from("instructor_activities").select("time_slot_id, action, created_at").in("time_slot_id",te).in("action",["canceled_by_student","canceled_by_instructor"]).order("created_at",{ascending:!1});if(t)throw t;const g={};for(const w of s??[])w.time_slot_id&&!g[w.time_slot_id]&&(g[w.time_slot_id]={created_at:w.created_at,action:w.action});return g},enabled:te.length>=0}),le=f.useMemo(()=>Array.from(new Set((O??[]).filter(s=>s.student_id).map(s=>s.student_id))),[O]),{data:Fe}=q({queryKey:["admin-instr-lesson-names",le],queryFn:()=>p({data:{studentIds:le}}),enabled:le.length>0}),Pe=f.useMemo(()=>{const s={};for(const t of ve??[]){const g=t.date;s[g]||={available:0,booked:0},t.status==="available"?s[g].available++:t.status==="booked"&&s[g].booked++}return s},[ve]),Y=()=>{u.invalidateQueries({queryKey:["admin-instr-month",a]}),u.invalidateQueries({queryKey:["admin-instr-day",a]}),u.invalidateQueries({queryKey:["admin-instr-stats",a]}),u.invalidateQueries({queryKey:["admin-instr-lessons",a]}),u.invalidateQueries({queryKey:["admin-instr-cancel-acts",a]})},oe=z({mutationFn:async s=>{const{error:t}=await m.from("time_slots").update({status:"canceled"}).eq("id",s);if(t)throw t},onSuccess:()=>{h.success("NodarbÄ«ba atcelta"),i(null),Y()},onError:s=>h.error(s.message)}),Ae=z({mutationFn:async s=>{const{error:t}=await m.from("time_slots").delete().eq("id",s);if(t)throw t},onSuccess:()=>{h.success("Slots dzÄsts"),Y()},onError:s=>h.error(s.message)}),ce=z({mutationFn:async({slotId:s,reason:t})=>{const{error:g}=await m.rpc("admin_waive_late_cancel",{_slot:s,_reason:t});if(g)throw g},onSuccess:()=>{h.success("Sods atcelts, nauda atgriezta"),B(null),R(""),Y()},onError:s=>h.error(s.message)}),de=z({mutationFn:async s=>{const{error:t}=await m.rpc("admin_delete_slot",{_slot:s});if(t)throw t},onSuccess:()=>{h.success("NodarbÄ«ba dzÄsta un summas atgrieztas"),F(null),Y()},onError:s=>h.error(s.message)}),me=z({mutationFn:async()=>{const s=is(N.start_time,Number(N.duration)),{error:t}=await m.from("time_slots").insert({instructor_id:a,date:N.date,start_time:N.start_time,end_time:s,duration_minutes:Number(N.duration),price_category:N.price_category,price:Number(N.price),status:"available"});if(t)throw t},onSuccess:()=>{h.success("Slots izveidots"),ie(!1),r(N.date),Y()},onError:s=>h.error(s.message)}),be=z({mutationFn:async()=>{const{error:s}=await m.from("instructors").update({active:!b.active}).eq("id",a);if(s)throw s},onSuccess:()=>{h.success(b.active?"Instruktors deaktivizÄts":"Instruktors aktivizÄts"),u.invalidateQueries({queryKey:["admin-instructor",a]}),u.invalidateQueries({queryKey:["admin-instructors-list"]})},onError:s=>h.error(s.message)}),ue=z({mutationFn:async s=>{const t=s.name.split(".").pop()||"jpg",g=`${a}/profile.${t}`,{error:w}=await m.storage.from("profile-photos").upload(g,s,{upsert:!0,cacheControl:"3600"});if(w)throw w;const{data:S}=m.storage.from("profile-photos").getPublicUrl(g),{error:K}=await m.from("instructors").update({photo_url:S.publicUrl}).eq("id",a);if(K)throw K;return S.publicUrl},onSuccess:()=>{h.success("Profila foto atjauninÄts"),u.invalidateQueries({queryKey:["admin-instructor",a]}),u.invalidateQueries({queryKey:["admin-instructors-list"]}),v.current&&(v.current.value="")},onError:s=>h.error(s.message)}),Ke=s=>{const t=s.target.files?.[0];t&&ue.mutate(t)};if(!b)return e.jsx("div",{className:"grid place-items-center py-20",children:e.jsx(C,{className:"w-6 h-6 animate-spin text-muted-foreground"})});const ye=[];for(let s=0;s<42;s++){const t=new Date(T);t.setDate(t.getDate()+s),ye.push(t)}const Ee=E(new Date);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{children:e.jsxs($e,{to:"/admin/instructors",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground",children:[e.jsx(Ie,{className:"w-4 h-4"})," Atpakaļ uz sarakstu"]})}),e.jsx(P,{children:e.jsxs(A,{className:"p-5 flex flex-wrap items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-muted overflow-hidden grid place-items-center shrink-0",children:b.photo_url?e.jsx("img",{src:xe(b.photo_url,128),alt:b.name,className:"w-full h-full object-cover",loading:"lazy"}):e.jsx(Te,{className:"w-7 h-7 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xl font-bold flex items-center gap-2",children:[b.name,!b.active&&e.jsx(J,{variant:"outline",children:"deaktivizÄts"})]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[b.city??"â"," · ",b.car_make??""," ",b.car_model??""," ",b.car_year??"",b.car_transmission?` · ${b.car_transmission}`:""]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Valodas: ",(b.languages??[]).join(", ")
1]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(cs,{instructor:b}),e.jsxs(x,{variant:b.active?"outline":"default",onClick:()=>be.mutate(),disabled:be.isPending,children:[e.jsx(es,{className:"w-4 h-4 mr-1"}),b.active?"DeaktivizÄt":"AktivizÄt"]})]})]})}),e.jsxs(P,{children:[e.jsx(M,{className:"pb-2",children:e.jsx(V,{className:"text-base",children:"Profila foto"})}),e.jsx(A,{children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx("div",{className:"w-20 h-20 rounded-2xl bg-muted overflow-hidden border border-border grid place-items-center",children:b.photo_url?e.jsx("img",{src:xe(b.photo_url,160),alt:"Profils",className:"w-full h-full object-cover",loading:"lazy"}):e.jsx(Ue,{className:"w-8 h-8 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsxs(x,{onClick:()=>v.current?.click(),disabled:ue.isPending,variant:"outline",size:"sm",children:[ue.isPending?e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(Ce,{className:"w-4 h-4 mr-2"}),"AugÅ¡upielÄdÄt foto"]}),e.jsx("input",{ref:v,type:"file",accept:"image/*",className:"hidden",onChange:Ke}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"JPG, PNG. Ieteicams 400Ã400."})]})]})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-3",children:[e.jsx(Q,{label:"KopÄ slotu",value:U?.total??0}),e.jsx(Q,{label:"RezervÄti",value:U?.booked??0}),e.jsx(Q,{label:"NotikuÅ¡i",value:U?.completed??0}),e.jsx(Q,{label:"Atcelti",value:U?.canceled??0}),e.jsx(Q,{label:"IeÅÄmumi",value:`â¬${(U?.revenue??0).toFixed(0)}`}),e.jsx(Q,{label:"Makas atlikums",value:`â¬${(ze??0).toFixed(2)}`})]}),I&&e.jsxs(P,{children:[e.jsx(M,{className:"pb-2",children:e.jsx(V,{className:"text-base",children:"Cenas un komisija"})}),e.jsxs(A,{className:"space-y-3",children:[e.jsxs("div",{className:"text-sm text-muted-foreground flex flex-wrap gap-4",children:[e.jsxs("span",{children:["Darba diena: ",e.jsxs("b",{className:"text-foreground",children:["â¬",Number(I.weekday_price).toFixed(2)]})]}),e.jsxs("span",{children:["Vakars: ",e.jsxs("b",{className:"text-foreground",children:["â¬",Number(I.weekday_evening_price).toFixed(2)]})]}),e.jsxs("span",{children:["BrÄ«vdiena: ",e.jsxs("b",{className:"text-foreground",children:["â¬",Number(I.weekend_price).toFixed(2)]})]})]}),e.jsx(ns,{instructorId:a,initial:Number(I.commission_eur??5)})]})]}),e.jsx(ls,{instructorId:a}),e.jsxs(P,{children:[e.jsxs(M,{className:"flex flex-row items-center justify-between space-y-0",children:[e.jsx(V,{className:"text-base capitalize",children:c.toLocaleDateString("lv-LV",{month:"long",year:"numeric"})}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(x,{size:"icon",variant:"ghost",onClick:()=>y(new Date(c.getFullYear(),c.getMonth()-1,1)),children:e.jsx(Oe,{className:"w-4 h-4"})}),e.jsx(x,{size:"sm",variant:"outline",onClick:()=>{const s=new Date;y(new Date(s.getFullYear(),s.getMonth(),1)),r(E(s))},children:"Å odien"}),e.jsx(x,{size:"icon",variant:"ghost",onClick:()=>y(new Date(c.getFullYear(),c.getMonth()+1,1)),children:e.jsx(Ye,{className:"w-4 h-4"})})]})]}),e.jsxs(A,{children:[e.jsx("div",{className:"grid grid-cols-7 gap-1 mb-1",children:as.map(s=>e.jsx("div",{className:"text-xs text-muted-foreground text-center font-medium py-1",children:s},s))}),e.jsx("div",{className:"grid grid-cols-7 gap-1",children:ye.map(s=>{const t=E(s),g=s.getMonth()===c.getMonth(),w=Pe[t],S=t===d,K=t===Ee;return e.jsxs("button",{onClick:()=>r(t),className:Ne("aspect-square min-h-14 rounded-md border p-1 flex flex-col items-stretch text-left transition-colors",g?"bg-background":"bg-muted/30 text-muted-foreground",S?"ring-2 ring-primary border-primary":"hover:bg-muted",K&&!S&&"border-primary/60"),children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDate()}),e.jsxs("div",{className:"mt-auto flex flex-wrap gap-1 justify-end",children:[w?.available?e.jsx("span",{className:"text-[10px] leading-none font-semibold px-1.5 py-0.5 rounded bg-green-500/15 text-green-700 dark:text-green-400",children:w.available}):null,w?.booked?e.jsx("span",{className:"text-[10px] leading-none font-semibold px-1.5 py-0.5 rounded bg-blue-500/15 text-blue-700 dark:text-blue-400",children:w.booked}):null]})]},t)})})]})]}),e.jsxs(P,{children:[e.jsxs(M,{className:"flex flex-row items-center justify-between space-y-0",children:[e.jsx(V,{className:"text-base",children:new Date(d).toLocaleDateString("lv-LV",{weekday:"long",day:"numeric",month:"long"})}),e.jsxs(G,{open:Se,onOpenChange:ie,children:[e.jsx(we,{asChild:!0,children:e.jsxs(x,{size:"sm",onClick:()=>$({...N,date:d}),children:[e.jsx(Je,{className:"w-4 h-4 mr-1"})," Jauns slots"]})}),e.jsxs(W,{children:[e.jsx(H,{children:e.jsx(X,{children:"Jauns slots"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Datums"}),e.jsx(_,{type:"date",value:N.date,onChange:s=>$({...N,date:s.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"SÄkums"}),e.jsx(_,{type:"time",value:N.start_time,onChange:s=>$({...N,start_time:s.target.value})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Ilgums (min)"}),e.jsx(_,{type:"number",min:30,step:15,value:N.duration,onChange:s=>$({...N,duration:Number(s.target.value)})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Cena (â¬)"}),e.jsx(_,{type:"text",inputMode:"decimal",min:0,step:1,value:N.price,onChange:s=>$({...N,price:s.target.value})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Kategorija"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:N.price_category,onChange:s=>$({...N,price_category:s.target.value}),children:[e.jsx("option",{value:"weekday",children:"Darba diena"}),e.jsx("option",{value:"weekday_evening",children:"Vakars"}),e.jsx("option",{value:"weekend",children:"NedÄļas nogale"})]})]})]}),e.jsxs(Z,{children:[e.jsx(x,{variant:"outline",onClick:()=>ie(!1),children:"Atcelt"}),e.jsx(x,{onClick:()=>me.mutate(),disabled:me.isPending,children:me.isPending?e.jsx(C,{className:"w-4 h-4 animate-spin"}):"Izveidot"})]})]})]})]}),e.jsx(A,{className:"divide-y divide-border",children:qe?e.jsx("div",{className:"grid place-items-center py-10",children:e.jsx(C,{className:"w-5 h-5 animate-spin"})}):(fe??[]).length===0?e.jsx("div",{className:"py-10 text-center text-sm text-muted-foreground",children:"Å ajÄ dienÄ nav slotu."}):(fe??[]).map(s=>{const t=s.status==="booked";return e.jsxs("div",{className:"flex items-center gap-3 py-3",children:[e.jsxs("div",{className:"font-mono text-sm tabular-nums w-24 shrink-0",children:[s.start_time.slice(0,5),"â",s.end_time.slice(0,5)]}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-wrap gap-2 items-center",children:[e.jsx(J,{variant:s.status==="available"?"secondary":t?"default":"outline",children:s.status==="available"?"BrÄ«vs":t?"RezervÄts":s.status==="canceled"?"Atcelts":"Pabeigts"}),e.jsx(J,{variant:"outline",className:"text-xs",children:rs[s.price_category]??s.price_category}),e.jsxs("span",{className:"text-sm font-semibold text-primary",children:["â¬",Number(s.price).toFixed(0)]})]}),e.jsxs("div",{className:"flex gap-1 shrink-0",children:[t&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>i(s),title:"Atcelt",children:e.jsx(Ge,{className:"w-4 h-4"})}),s.status==="available"&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>Ae.mutate(s.id),title:"DzÄst",children:e.jsx(he,{className:"w-4 h-4 text-destructive"})})]})]},s.id)})})]}),e.jsx(ds,{instructorId:a}),e.jsxs(P,{children:[e.jsxs(M,{className:"flex flex-row items-center justify-between space-y-0 gap-2 flex-wrap",children:[e.jsx(V,{className:"text-base",children:"NodarbÄ«bas"}),e.jsx("div",{className:"flex gap-1 flex-wrap",children:["all","booked","completed","canceled"].map(s=>e.jsx(x,{size:"sm",variant:o===s?"default":"outline",onClick:()=>n(s),children:s==="all"?"Visas":s==="booked"?"Pieteiktas":s==="completed"?"NotikuÅ¡as":"Atceltas"},s))})]}),e.jsx(A,{className:"divide-y divide-border",children:(()=>{const s=(O??[]).filter(t=>o==="all"||t.status===o);return s.length===0?e.jsx("div",{className:"py-10 text-center text-sm text-muted-foreground",children:"Nav nodarbÄ«bu."}):s.map(t=>{const g=t.student_id?Fe?.[t.student_id]?.fullName??"Students":"â",w=new Date(`${t.date}T${t.start_time}`),S=De?.[t.id],K=t.status==="canceled"&&S?w.getTime()-new Date(S.created_at).getTime()<24*3600*1e3:!1,ae=t.status==="booked"?{label:"Pieteikta",variant:"default"}:t.status==="completed"?{label:"Notikusi",variant:"secondary"}:{label:"Atcelta",variant:"outline"};return e.jsxs("div",{className:Ne("flex items-start gap-3 py-3 px-2 -mx-2 rounded-md",K&&"bg-destructive/10 border border-destructive/30",t.admin_deleted_at&&"opacity-70"),children:[e.jsxs("div",{className:"font-mono text-xs tabular-nums w-28 shrink-0 text-muted-foreground",children:[e.jsx("div",{children:new Date(t.date).toLocaleDateString("lv-LV",{day:"2-digit",month:"2-digit",year:"2-digit"})}),e.jsxs("div",{children:[t.start_time.slice(0,5),"â",t.end_time.slice(0,5)]})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:g}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 mt-1",children:[e.jsx(J,{variant:ae.variant,className:"text-xs",children:ae.label}),t.admin_deleted_at&&e.jsx(J,{variant:"destructive",className:"text-xs",children:"DzÄsta (admin)"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["â¬",Number(t.price).toFixed(0)]}),t.status==="canceled"&&S&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["· ",S.action==="canceled_by_student"?"atcÄla students":"atcÄla instruktors"," ",new Date(S.created_at).toLocaleStr
1ing("lv-LV",{day:"2-digit",month:"2-digit",hour:"2-digit",minute:"2-digit"})]})]}),K&&e.jsxs("div",{className:"flex items-center gap-1 text-xs text-destructive font-medium mt-1",children:[e.jsx(_e,{className:"w-3.5 h-3.5"})," Atcelta mazÄk kÄ 24h pirms sÄkuma"]})]}),(t.late_cancel_paid||t.no_show)&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>{B(t),R("")},title:"Atcelt sodu (attaisnojoÅ¡s iemesls)",className:"shrink-0 text-amber-600 hover:text-amber-700",children:"Atcelt sodu"}),!t.admin_deleted_at&&e.jsx(x,{size:"sm",variant:"ghost",onClick:()=>F(t),title:"DzÄst nodarbÄ«bu",className:"shrink-0",children:e.jsx(he,{className:"w-4 h-4 text-destructive"})})]},t.id)})})()})]}),e.jsx(G,{open:!!k,onOpenChange:s=>!s&&F(null),children:e.jsxs(W,{children:[e.jsx(H,{children:e.jsx(X,{children:"DzÄst nodarbÄ«bu?"})}),(()=>{const s=k,t=!!s&&(s.status==="completed"||s.status==="canceled"&&(s.late_cancel_paid||s.no_show));return e.jsxs("div",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("p",{children:["Vai tieÅ¡Äm vÄlies dzÄst Å¡o nodarbÄ«bu? Summa â¬",Number(s?.price??0).toFixed(2)," tiks automÄtiski atgriezta kursanta makÄ un noÅemta no instruktora (un skolas) maka."]}),e.jsx("p",{children:'NodarbÄ«ba pazudÄ«s no kursanta un instruktora kalendÄra, bet paliks redzama tev kÄ "DzÄsta".'}),t&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-destructive",children:[e.jsx(_e,{className:"w-4 h-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs",children:[e.jsx("p",{className:"font-medium",children:"BrÄ«dinÄjums: šī ir jau finansiÄli noslÄgta nodarbÄ«ba."}),e.jsxs("p",{className:"mt-1",children:["Instruktora un skolas maki tiks samazinÄti par jau saÅemto summu. Ja instruktors savu daļu jau ir izÅÄmis ar rÄÄ·inu, viÅa balanss kļūs negatÄ«vs. AtgrieztÄ summa ",e.jsx("span",{className:"font-medium",children:"netiks"})," iekļauta nÄkamajÄ rÄÄ·inÄ."]})]})]})]})})(),e.jsxs(Z,{children:[e.jsx(x,{variant:"outline",onClick:()=>F(null),children:"NÄ"}),e.jsx(x,{variant:"destructive",onClick:()=>k&&de.mutate(k.id),disabled:de.isPending,children:de.isPending?e.jsx(C,{className:"w-4 h-4 animate-spin"}):"DzÄst nodarbÄ«bu"})]})]})}),e.jsx(G,{open:!!l,onOpenChange:s=>!s&&i(null),children:e.jsxs(W,{children:[e.jsx(H,{children:e.jsx(X,{children:"Atcelt rezervÄto nodarbÄ«bu?"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Å Ä« darbÄ«ba atzÄ«mÄs slotu kÄ atceltu. Studentam tiks paziÅots."}),e.jsxs(Z,{children:[e.jsx(x,{variant:"outline",onClick:()=>i(null),children:"NÄ"}),e.jsx(x,{variant:"destructive",onClick:()=>oe.mutate(l.id),disabled:oe.isPending,children:oe.isPending?e.jsx(C,{className:"w-4 h-4 animate-spin"}):"Atcelt nodarbÄ«bu"})]})]})}),e.jsx(G,{open:!!L,onOpenChange:s=>{s||(B(null),R(""))},children:e.jsxs(W,{children:[e.jsx(H,{children:e.jsx(X,{children:"Atcelt sodu par vÄlo atcelÅ¡anu?"})}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("p",{className:"text-muted-foreground",children:["Studentam tiks atgriezta pilna iekasÄtÄ summa (â¬",Number(L?.price??0).toFixed(2),"), un instruktora / skolas ieÅÄmumi par Å¡o slotu tiks atsaukti. DarbÄ«ba tiks ierakstÄ«ta audita žurnÄlÄ."]}),e.jsxs("div",{children:[e.jsx(j,{htmlFor:"waive-reason",children:"Iemesls (obligÄts)"}),e.jsx(_,{id:"waive-reason",value:re,onChange:s=>R(s.target.value),placeholder:"Piem. medicÄ«nisks attaisnojums, Ärsta zÄ«me",className:"mt-1"})]})]}),e.jsxs(Z,{children:[e.jsx(x,{variant:"outline",onClick:()=>{B(null),R("")},children:"NÄ"}),e.jsx(x,{onClick:()=>L&&ce.mutate({slotId:L.id,reason:re.trim()}),disabled:ce.isPending||re.trim().length<3,children:ce.isPending?e.jsx(C,{className:"w-4 h-4 animate-spin"}):"ApstiprinÄt"})]})]})}),e.jsx(ts,{instructorId:a})]})}function Q({label:a,value:u}){return e.jsx(P,{children:e.jsxs(A,{className:"p-4",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:a}),e.jsx("div",{className:"text-xl font-bold mt-1",children:u})]})})}function ns({instructorId:a,initial:u}){const p=se(),[v,c]=f.useState(String(u)),y=z({mutationFn:async()=>{const d=Number(v);if(Number.isNaN(d)||d<0)throw new Error("NederÄ«ga vÄrtÄ«ba");const{error:r}=await m.from("instructor_pricing").update({commission_eur:d,updated_at:new Date().toISOString()}).eq("instructor_id",a);if(r)throw r},onSuccess:()=>{h.success("Komisija atjauninÄta"),p.invalidateQueries({queryKey:["admin-instructor-pricing",a]})},onError:d=>h.error(d.message)});return e.jsxs("div",{className:"flex items-end gap-2 pt-2 border-t border-border",children:[e.jsxs("div",{className:"flex-1 max-w-[180px]",children:[e.jsx(j,{htmlFor:"indiv-comm",className:"text-xs",children:"Autoskolas komisija (â¬)"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground",children:"â¬"}),e.jsx(_,{id:"indiv-comm",type:"text",inputMode:"decimal",step:"0.5",min:"0",value:v,onCh
1ange:d=>c(d.target.value),className:"pl-6 h-8 text-sm"})]})]}),e.jsxs(x,{size:"sm",onClick:()=>y.mutate(),disabled:y.isPending,children:[y.isPending&&e.jsx(C,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"SaglabÄt"]})]})}function ls({instructorId:a}){const u=se(),{data:p,isLoading:v}=q({queryKey:["admin-instructor-cash",a],queryFn:async()=>{const[{data:n},{data:l}]=await Promise.all([m.from("instructors").select("cash_payment_allowed, cash_commission_eur").eq("id",a).maybeSingle(),m.from("app_settings").select("value").eq("key","cash_commission_default_eur").maybeSingle()]);return{allowed:!!n?.cash_payment_allowed,commission:Number(n?.cash_commission_eur??l?.value??6),globalDefault:Number(l?.value??6)}}}),[c,y]=f.useState(null),d=p,r=c??String(d?.commission??""),o=z({mutationFn:async n=>{const{error:l}=await m.rpc("admin_set_instructor_cash",{_instructor:a,_allowed:n.allowed,_commission:n.commission});if(l)throw new Error(l.message)},onSuccess:()=>{h.success("KlÄtienes iestatÄ«jumi saglabÄti"),u.invalidateQueries({queryKey:["admin-instructor-cash",a]})},onError:n=>h.error(n.message)});return e.jsxs(P,{children:[e.jsx(M,{className:"pb-2",children:e.jsx(V,{className:"text-base",children:"KlÄtienes maksÄjumi"})}),e.jsx(A,{className:"space-y-3",children:v||!d?e.jsx("div",{className:"text-sm text-muted-foreground",children:"IelÄdÄâ¦"}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"flex items-center gap-3 text-sm",children:[e.jsx(ee,{checked:d.allowed,onCheckedChange:n=>o.mutate({allowed:n===!0,commission:Number(r)||d.commission})}),e.jsx("span",{children:"Atļaut studentam maksÄt klÄtienÄ pÄc nodarbÄ«bas"})]}),e.jsxs("div",{className:"flex items-end gap-2 pt-2 border-t border-border",children:[e.jsxs("div",{className:"flex-1 max-w-[220px]",children:[e.jsx(j,{className:"text-xs",children:"KlÄtienes komisija (â¬)"}),e.jsxs("div",{className:"relative mt-1",children:[e.jsx("span",{className:"absolute left-2 top-1/2 -translate-y-1/2 text-xs text-muted-foreground",children:"â¬"}),e.jsx(_,{type:"text",inputMode:"decimal",step:"0.5",min:"0",value:r,onChange:n=>y(n.target.value),className:"pl-6 h-8 text-sm"})]}),e.jsxs("div",{className:"text-[11px] text-muted-foreground mt-1",children:["GlobÄlÄ vÄrtÄ«ba: â¬",d.globalDefault.toFixed(2)]})]}),e.jsxs(x,{size:"sm",disabled:o.isPending,onClick:()=>{const n=Number(r);if(!Number.isFinite(n)||n<0)return h.error("NederÄ«ga summa");o.mutate({allowed:d.allowed,commission:n})},children:[o.isPending&&e.jsx(C,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"SaglabÄt"]})]})]})})]})}const os=["LatvieÅ¡u","Krievu","Angļu"];function cs({instructor:a}){const u=se(),p=ge(Qe),[v,c]=f.useState(!1),[y,d]=f.useState(null),[r,o]=f.useState({name:a.name??"",email:a.email??"",phone:a.phone??"",city:a.city??"",start_address:a.start_address??"",car_make:a.car_make??"",car_model:a.car_model??"",car_year:a.car_year?String(a.car_year):"",car_plate:a.car_plate??"",car_transmission:a.car_transmission??"ManuÄlÄ",fuel_type:a.fuel_type??"BenzÄ«ns",languages:a.languages??["LatvieÅ¡u"],is_examiner:a.is_examiner,is_instructor:a.is_instructor,bio:a.bio??"",favorites_only_visible:a.favorites_only_visible,license_number:a.license_number??"",license_expiry_date:a.license_expiry_date??""}),n=z({mutationFn:async()=>{if(!r.name.trim())throw new Error("VÄrds ir obligÄts");if(!r.license_number.trim())throw new Error("Instruktora apliecÄ«bas Nr. ir obligÄts");if(!r.license_expiry_date)throw new Error("ApliecÄ«bas derÄ«guma termiÅÅ¡ ir obligÄts");if(r.email&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r.email.trim()))throw new Error("Nepareizs e-pasta formÄts");const i=(a.license_expiry_date??"")!==r.license_expiry_date,{error:k}=await m.from("instructors").update({name:r.name.trim(),email:r.email.trim()||null,phone:r.phone.trim()||null,city:r.city.trim()||null,start_address:r.start_address.trim()||null,car_make:r.car_make.trim()||null,car_model:r.car_model.trim()||null,car_year:r.car_year?Number(r.car_year):null,car_plate:r.car_plate.trim().toUpperCase()||null,car_transmission:r.car_transmission,fuel_type:r.fuel_type,languages:r.languages.length>0?r.languages:["LatvieÅ¡u"],is_examiner:r.is_examiner,is_instructor:r.is_instructor,bio:r.bio.trim()||null,favorites_only_visible:r.favorites_only_visible,license_number:r.license_number.trim(),license_expiry_date:r.license_expiry_date,...i?{license_expiry_notified_at:null}:{}}).eq("id",a.id);if(k)throw k},onSuccess:()=>
1{h.success("Profils atjauninÄts"),u.invalidateQueries({queryKey:["admin-instructor",a.id]}),u.invalidateQueries({queryKey:["admin-instructors-list"]}),u.invalidateQueries({queryKey:["instructors"]}),c(!1)},onError:i=>h.error(i.message)}),l=z({mutationFn:async()=>await p({data:{id:a.id}}),onSuccess:i=>{d(i.password),h.success(`Jauna parole nosÅ«tÄ«ta uz ${i.email}`)},onError:i=>h.error(i.message)});return e.jsxs(G,{open:v,onOpenChange:c,children:[e.jsx(we,{asChild:!0,children:e.jsxs(x,{variant:"outline",children:[e.jsx(We,{className:"w-4 h-4 mr-1"})," RediÄ£Ät"]})}),e.jsxs(W,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(H,{children:e.jsx(X,{children:"RediÄ£Ät instruktora profilu"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[e.jsx(j,{children:"VÄrds, uzvÄrds *"}),e.jsx(_,{value:r.name,onChange:i=>o({...r,name:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Telefons"}),e.jsx(_,{value:r.phone,onChange:i=>o({...r,phone:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"E-pasts"}),e.jsx(_,{type:"email",value:r.email,onChange:i=>o({...r,email:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"PilsÄta"}),e.jsx(_,{value:r.city,onChange:i=>o({...r,city:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[e.jsx(j,{children:"SÄkuma adrese"}),e.jsx(_,{value:r.start_address,onChange:i=>o({...r,start_address:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[e.jsx(j,{children:"Par sevi (bio)"}),e.jsx(_,{value:r.bio,onChange:i=>o({...r,bio:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Instruktora apliecÄ«bas Nr. *"}),e.jsx(_,{value:r.license_number,onChange:i=>o({...r,license_number:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"ApliecÄ«bas derÄ«ga lÄ«dz *"}),e.jsx(_,{type:"date",value:r.license_expiry_date,onChange:i=>o({...r,license_expiry_date:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Auto marka"}),e.jsx(_,{value:r.car_make,onChange:i=>o({...r,car_make:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Modelis"}),e.jsx(_,{value:r.car_model,onChange:i=>o({...r,car_model:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Gads"}),e.jsx(_,{type:"number",value:r.car_year,onChange:i=>o({...r,car_year:i.target.value})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"NumurzÄ«me"}),e.jsx(_,{value:r.car_plate,onChange:i=>o({...r,car_plate:i.target.value.toUpperCase()})})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"KÄrba"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:r.car_transmission,onChange:i=>o({...r,car_transmission:i.target.value}),children:[e.jsx("option",{children:"ManuÄlÄ"}),e.jsx("option",{children:"AutomÄts"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{children:"Degviela"}),e.jsxs("select",{className:"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm",value:r.fuel_type,onChange:i=>o({...r,fuel_type:i.target.value}),children:[e.jsx("option",{children:"BenzÄ«ns"}),e.jsx("option",{children:"DÄ«zelis"}),e.jsx("option",{children:"Elektro"})]})]}),e.jsxs("div",{className:"space-y-2 sm:col-span-2",children:[e.jsx(j,{children:"Valodas"}),e.jsx("div",{className:"flex flex-wrap gap-4",children:os.map(i=>{const k=r.languages.includes(i);return e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx(ee,{checked:k,onCheckedChange:F=>{o({...r,languages:F===!0?[...r.languages,i]:r.languages.filter(B=>B!==i)})}}),i]},i)})})]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer sm:col-span-2",children:[e.jsx(ee,{checked:r.is_instructor,onCheckedChange:i=>o({...r,is_instructor:i===!0})}),"Instruktors"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer sm:col-span-2",children:[e.jsx(ee,{checked:r.is_examiner,onCheckedChange:i=>o({...r,is_examiner:i===!0})}),"ArÄ« eksaminators"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer sm:col-span-2",children:[e.jsx(ee,{checked:r.favorites_only_visible,onCheckedChange:i=>o({...r,favorites_only_visible:i===!0})}),"Redzams tikai favorÄ«tu studentiem"]})]}),e.jsxs("div",{className:"border-t pt-4 space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:"Piekļuves parole"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Ä¢enerÄ jaunu paroli Å¡im instruktoram un nosÅ«ta to uz viÅa e-pastu (",r.email||"â",")."]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{confirm("Ä¢enerÄt un nosÅ«tÄ«t jaunu paroli instruktoram?")&&l.mutate()},disabled:l.isPending||!r.email,children:[l.isPending&&e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}),"NosÅ«tÄ«t jaunu paroli"]}
1),y&&e.jsxs("div",{className:"rounded-md border border-amber-300 bg-amber-50 p-2 text-xs text-amber-900",children:["JaunÄ parole: ",e.jsx("span",{className:"font-mono font-semibold",children:y}),e.jsx("div",{className:"mt-1 text-amber-800",children:"Parole nosÅ«tÄ«ta arÄ« uz e-pastu."})]})]})]}),e.jsxs(Z,{children:[e.jsx(x,{variant:"outline",onClick:()=>c(!1),children:"Atcelt"}),e.jsxs(x,{onClick:()=>n.mutate(),disabled:n.isPending,children:[n.isPending&&e.jsx(C,{className:"w-4 h-4 mr-2 animate-spin"}),"SaglabÄt"]})]})]})]})}function ds({instructorId:a}){const u=ge(ke),{data:p,isLoading:v}=q({queryKey:["admin-instr-fav-removals",a],queryFn:async()=>{const[l,i]=await Promise.all([m.from("favorite_removals").select("id, reason, created_at, student_id").eq("instructor_id",a).order("created_at",{ascending:!1}),m.from("favorite_instructors").select("id",{count:"exact",head:!0}).eq("instructor_id",a)]);if(l.error)throw l.error;const k=l.data??[],F=i.count??0;return{removals:k,currentCount:F}}}),c=p?.removals??[],y=p?.currentCount??0,d=c.length+y,r=d>0?Math.round(c.length/d*100):0,o=f.useMemo(()=>Array.from(new Set(c.map(l=>l.student_id).filter(Boolean))),[c]),{data:n}=q({queryKey:["admin-instr-fav-removal-names",o],queryFn:()=>u({data:{studentIds:o}}),enabled:o.length>0});return e.jsxs(P,{children:[e.jsx(M,{children:e.jsx(V,{className:"text-base",children:"Atteikumi no favorÄ«tiem"})}),e.jsx(A,{className:"space-y-3",children:v?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(C,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center",children:[e.jsxs("div",{className:"rounded-md border p-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Atteikumi"}),e.jsx("div",{className:"text-xl font-bold tabular-nums",children:c.length})]}),e.jsxs("div",{className:"rounded-md border p-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Å obrÄ«d favorÄ«tos"}),e.jsx("div",{className:"text-xl font-bold tabular-nums",children:y})]}),e.jsxs("div",{className:"rounded-md border p-2",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"% atteicÄs"}),e.jsxs("div",{className:"text-xl font-bold tabular-nums",children:[r,"%"]})]})]}),c.length===0?e.jsx("div",{className:"text-sm text-muted-foreground text-center py-3",children:"VÄl nav neviena atteikuma."}):e.jsx("div",{className:"divide-y divide-border",children:c.map(l=>{const k=(l.student_id?n?.[l.student_id]:void 0)?.fullName??"NezinÄms students";return e.jsxs("div",{className:"py-2",children:[e.jsx("div",{className:"text-sm font-medium",children:k}),e.jsx("div",{className:"text-sm text-muted-foreground mt-0.5 whitespace-pre-wrap",children:l.reason}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:new Date(l.created_at).toLocaleString("lv-LV")})]},l.id)})})]})})]})}export{Ps as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.