1import{c as Q,r as n,j as e,a as x,e as G,I as X,N as Y,B as N,L as F,x as m,s as B}from"./index-Cd3yfEY4.js";import{u as Z}from"./useQuery-B9V2mnBX.js";import{u as I}from"./useMutation-CHg1FgJ7.js";import{u as J}from"./useAdminCheck-B7yL939R.js";import{L as D,X as W,Z as ee,_ as te,$ as se,a8 as ae,a9 as re}from"./Layout-CWsKUMHa.js";import{I as C}from"./input-ngZeYjwv.js";import{C as ie}from"./checkbox-CVwVPVZp.js";import{L as E}from"./label-CWkYTPuc.js";import{L as k}from"./proxy-CiwD0GLZ.js";import{A as ne}from"./arrow-left-D1WGQH6t.js";import{S as oe}from"./search-C57BDup3.js";import{S as H}from"./save-B_qNJfxx.js";import{S as le}from"./star-CNjf9caQ.js";import"./roborock-zJhBC4At.js";import"./ubtech-walker-D0z2glW5.js";import"./hobot-s7-pro-DxrqYLtB.js";import"./user-BFckHMGj.js";import"./building-2-BZx1tvLM.js";import"./linkedin-bzOJfBud.js";import"./shield-DfWjdcyG.js";import"./credit-card-C-xMxSWe.js";import"./package-nndDci9z.js";import"./chevron-down-BLZN2Zcl.js";import"./index-CT8mPTgS.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const de=Q("SquareCheckBig",[["path",{d:"M21 10.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h12.5",key:"1uzm8b"}],["path",{d:"m9 11 3 3L22 4",key:"1pflzl"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ce=Q("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]),M=n.forwardRef(({className:s,...r},i)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:i,className:x("w-full caption-bottom text-sm",s),...r})}));M.displayName="Table";const U=n.forwardRef(({className:s,...r},i)=>e.jsx("thead",{ref:i,className:x("[&_tr]:border-b",s),...r}));U.displayName="TableHeader";const K=n.forwardRef(({className:s,...r},i)=>e.jsx("tbody",{ref:i,className:x("[&_tr:last-child]:border-0",s),...r}));K.displayName="TableBody";const me=n.forwardRef(({className:s,...r},i)=>e.jsx("tfoot",{ref:i,className:x("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s),...r}));me.displayName="TableFooter";const _=n.forwardRef(({className:s,...r},i)=>e.jsx("tr",{ref:i,className:x("border-b transition-colors data-[state=selected]:bg-muted hover:bg-muted/50",s),...r}));_.displayName="TableRow";const v=n.forwardRef(({className:s,...r},i)=>e.jsx("th",{ref:i,className:x("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s),...r}));v.displayName="TableHead";const b=n.forwardRef(({className:s,...r},i)=>e.jsx("td",{ref:i,className:x("p-4 align-middle [&:has([role=checkbox])]:pr-0",s),...r}));b.displayName="TableCell";const ue=n.forwardRef(({className:s,...r},i)=>e.jsx("caption",{ref:i,className:x("mt-4 text-sm text-muted-foreground",s),...r}));ue.displayName="TableCaption";function Ee(){const{user:s,loading:r}=G(),{data:i,isLoading:L}=J(),p=X(),[l,j]=n.useState(new Set),[u,T]=n.useState(""),[S,h]=n.useState(!1),[w,R]=n.useState(""),[y,o]=n.useState(""),{data:c,isLoading:O}=Z({queryKey:["admin-robot-ratings"],queryFn:async()=>{const{data:t,error:a}=await B.from("robot_ratings").select("*").order("robot_id");if(a)throw a;return t},enabled:i===!0}),g=n.useMemo(()=>{if(!c)return[];if(!u.trim())return c;const t=u.toLowerCase();return c.filter(a=>a.robot_id.toLowerCase().includes(t))},[c,u]),q=I({mutationFn:async({ids:t,rating:a,reviewCount:d})=>{const f={};a!==void 0&&(f.display_rating=a),d!==void 0&&(f.display_review_count=d),f.updated_by=s?.id;const{error:z}=await B.from("robot_ratings").update(f).in("id",t);if(z)throw z},onSuccess:()=>{p.invalidateQueries({queryKey:["admin-robot-ratings"]}),p.invalidateQueries({queryKey:["robot-ratings"]}),m.success(`Updated ${l.size} robots`),j(new Set),h(!1),R(""),o("")},onError:t=>{m.error("Failed to update: "+t.message)}}),A=I({mutationFn:async({id:t,rating:a,reviewCount:d})=>{const{error:f}=await B.from("robot_ratings").update({display_rating:a,display_review_count:d,updated_by:s?.id}).eq("id",t);if(f)throw f},onSuccess:()=>{p.invalidateQueries({queryKey:["admin-robot-ratings"]}),p.invalidateQueries({queryKey:["robot-ratings"]}),m.success("Rating updated")},onError:t=>{m.error("Update failed: "+t.message)}}),P=t=>{j(a=>
11{const d=new Set(a);return d.has(t)?d.delete(t):d.add(t),d})},V=()=>{l.size===g.length?j(new Set):j(new Set(g.map(t=>t.id)))},$=()=>{const t={ids:Array.from(l)};if(w.trim()){const a=parseFloat(w);if(isNaN(a)||a<0||a>5){m.error("Rating must be between 0 and 5");return}t.rating=Math.round(a*10)/10}if(y.trim()){const a=parseInt(y,10);if(isNaN(a)||a<0){m.error("Review count must be a positive number");return}t.reviewCount=a}if(t.rating===void 0&&t.reviewCount===void 0){m.error("Enter at least one value to update");return}q.mutate(t)};return r||L?e.jsx(D,{children:e.jsx("div",{className:"flex items-center justify-center min-h-[60vh]",children:e.jsx(k,{className:"h-8 w-8 animate-spin text-primary"})})}):s?i===!1?e.jsx(D,{children:e.jsxs("div",{className:"container py-16 text-center",children:[e.jsx("h1",{className:"text-2xl font-bold text-destructive mb-4",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You don't have permission to access this page."}),e.jsx(N,{asChild:!0,children:e.jsx(F,{to:"/",children:"Go Home"})})]})}):e.jsx(D,{children:e.jsxs("div",{className:"container py-8 max-w-6xl",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[e.jsx(N,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs(F,{to:"/settings",children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Back"]})}),e.jsx("h1",{className:"text-2xl font-bold",children:"Admin: Robot Ratings"})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(C,{placeholder:"Search by robot ID...",value:u,onChange:t=>T(t.target.value),className:"pl-10"})]}),e.jsxs(N,{onClick:()=>h(!0),disabled:l.size===0,children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),"Bulk Edit (",l.size,")"]})]}),O?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(k,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsx("div",{className:"border rounded-lg overflow-hidden",children:e.jsxs(M,{children:[e.jsx(U,{children:e.jsxs(_,{children:[e.jsx(v,{className:"w-12",children:e.jsx("button",{onClick:V,className:"p-1 hover:bg-muted rounded","aria-label":"Select all",children:l.size===g.length&&g.length>0?e.jsx(de,{className:"h-4 w-4"}):e.jsx(ce,{className:"h-4 w-4"})})}),e.jsx(v,{children:"Robot ID"}),e.jsx(v,{className:"w-32",children:"Rating"}),e.jsx(v,{className:"w-36",children:"Review Count"}),e.jsx(v,{className:"w-20",children:"Actions"})]})}),e.jsxs(K,{children:[g.map(t=>e.jsx(he,{rating:t,selected:l.has(t.id),onToggle:()=>P(t.id),onSave:(a,d)=>A.mutate({id:t.id,rating:a,reviewCount:d}),saving:A.isPending},t.id)),g.length===0&&e.jsx(_,{children:e.jsx(b,{colSpan:5,className:"text-center py-8 text-muted-foreground",children:"No ratings found"})})]})]})}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-4",children:[g.length," robots ⢠",l.size," selected"]}),e.jsx(W,{open:S,onOpenChange:h,children:e.jsxs(ee,{children:[e.jsxs(te,{children:[e.jsx(se,{children:"Bulk Edit Ratings"}),e.jsxs(ae,{children:["Update ",l.size," selected robots. Leave a field empty to keep current values."]})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"bulk-rating",children:"New Rating (0-5)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{className:"h-4 w-4 text-yellow-500"}),e.jsx(C,{id:"bulk-rating",type:"number",step:"0.1",min:"0",max:"5",placeholder:"e.g. 4.5",value:w,onChange:t=>R(t.target.value)})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(E,{htmlFor:"bulk-count",children:"New Review Count"}),e.jsx(C,{id:"bulk-count",type:"number",min:"0",placeholder:"e.g. 150",value:y,onChange:t=>o(t.target.value)})]})]}),e.jsxs(re,{children:[e.jsx(N,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),e.jsxs(N,{onClick:$,disabled:q.isPending,children:[q.isPending&&e.jsx(k,{className:"h-4 w-4 mr-2 animate-spin"}),"Update All"]})]})]})})]})}):e.jsx(Y,{to:"/auth",replace:!0})}function he({rating:s,selected:r,onToggle:i,onSave:L,saving:p}){const[l,j]=n.useState(s.display_rating.toString()),[u,T]=n.useState(s.display_review_count?.toString()||""),[S,h]=n.useState(!1),w=o=>{j(o),h(!0)},R=o=>{T(o),h(!0)},y=()=>{const o=parseFloat(l);
11if(isNaN(o)||o<0||o>5){m.error("Rating must be 0-5");return}const c=u.trim()?parseInt(u,10):null;if(c!==null&&(isNaN(c)||c<0)){m.error("Review count must be positive");return}L(Math.round(o*10)/10,c),h(!1)};return e.jsxs(_,{className:r?"bg-primary/5":"",children:[e.jsx(b,{children:e.jsx(ie,{checked:r,onCheckedChange:i})}),e.jsx(b,{className:"font-mono text-sm",children:s.robot_id}),e.jsx(b,{children:e.jsx(C,{type:"number",step:"0.1",min:"0",max:"5",value:l,onChange:o=>w(o.target.value),className:"w-20 h-8"})}),e.jsx(b,{children:e.jsx(C,{type:"number",min:"0",value:u,onChange:o=>R(o.target.value),className:"w-24 h-8",placeholder:"â"})}),e.jsx(b,{children:e.jsx(N,{size:"sm",variant:S?"default":"ghost",onClick:y,disabled:!S||p,children:p?e.jsx(k,{className:"h-3 w-3 animate-spin"}):e.jsx(H,{className:"h-3 w-3"})})})]})}export{Ee as default};
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.