1import{j as e,k as F,n as q,p as o,o as h,al as B,B as w,aH as P,r as d,u as E,b as u,c as _,a as C,d as M,L as $,e as U,A as R,aK as D,$ as I,a1 as K,a2 as z,a3 as Q,a4 as H,a5 as j,t as S,aL as V}from"./index-AvtpnLYm.js";const G={high:"bg-red-50 text-red-700 border-red-200",low:"bg-orange-50 text-orange-700 border-orange-200"};function O({anomaly:a,onMarkGood:n,onMarkUnreliable:c,isUpdating:x}){return e.jsx(F,{className:"border-0 shadow-sm",children:e.jsx(q,{className:"p-5",children:e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-start lg:justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-2",children:[e.jsx(o,{variant:"outline",children:a.brand||"Unknown brand"}),e.jsx("h3",{className:"font-bold text-gray-900 truncate",children:a.name}),e.jsxs(o,{className:a.type==="high"?"bg-red-100 text-red-700 border-0":"bg-orange-100 text-orange-700 border-0",children:[e.jsx(h,{className:"h-3 w-3 mr-1"})," ",a.type==="high"?"Above cap":"Below floor"]}),a.price_quality_flag&&e.jsx(o,{variant:"outline",className:"capitalize",children:a.price_quality_flag}),a.status_unreliable_prices&&e.jsx(o,{className:"bg-yellow-100 text-yellow-700 border-0",children:"Unreliable"})]}),e.jsxs("p",{className:"text-sm text-gray-500 flex items-center gap-1 mb-3",children:[e.jsx(B,{className:"h-3.5 w-3.5"})," ",[a.suburb,a.city,a.province].filter(Boolean).join(", ")||"No location"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-gray-50 rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Fuel grade"}),e.jsx("p",{className:"text-sm font-bold text-gray-800",children:a.fuelLabel})]}),e.jsxs("div",{className:`rounded-xl p-3 border ${G[a.type]}`,children:[e.jsx("p",{className:"text-xs opacity-70",children:"Current price"}),e.jsxs("p",{className:"text-xl font-black",children:["R",Number(a.price).toFixed(2)]})]}),e.jsxs("div",{className:"bg-gray-50 rounded-xl p-3",children:[e.jsx("p",{className:"text-xs text-gray-400",children:"Expected range"}),e.jsxs("p",{className:"text-sm font-bold text-gray-800",children:[a.min!=null?`R${Number(a.min).toFixed(2)}`:"â"," â ",a.max!=null?`R${Number(a.max).toFixed(2)}`:"â"]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row lg:flex-col gap-2 lg:w-44",children:[e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>n(a),disabled:x,className:"gap-2",children:[e.jsx(P,{className:"h-4 w-4"})," Mark good"]}),e.jsxs(w,{size:"sm",onClick:()=>c(a),disabled:x,className:"bg-yellow-600 hover:bg-yellow-700 gap-2",children:[e.jsx(h,{className:"h-4 w-4"})," Unreliable"]})]})]})})})}const J=[{field:"diesel_10ppm_price",fuelType:"diesel_10ppm",anyType:"any_diesel",label:"Diesel 10ppm"},{field:"diesel_50ppm_price",fuelType:"diesel_50ppm",anyType:"any_diesel",label:"Diesel 50ppm"},{field:"diesel_500ppm_price",fuelType:"diesel_500ppm",anyType:"any_diesel",label:"Diesel 500ppm"},{field:"petrol_95_price",fuelType:"petrol_95",anyType:"any_petrol",label:"Petrol 95"},{field:"petrol_93_price",fuelType:"petrol_93",anyType:"any_petrol",label:"Petrol 93"}],W=async()=>(await V()).filter(n=>n.price_stale!==!0);function Y(){const[a,n]=d.useState(null),[c,x]=d.useState(""),[g,T]=d.useState("all"),L=E();d.useEffect(()=>{u.auth.me().then(s=>{(s==null?void 0:s.role)!=="owner"?window.location.href=_("Home"):n(s)}).catch(()=>u.auth.redirectToLogin())},[]);const{data:y=[],isLoading:k}=C({queryKey:["price-anomaly-stations"],queryFn:W,enabled:!!a,staleTime:6e4}),{data:N=[],isLoading:A}=C({queryKey:["admin-price-settings"],queryFn:()=>u.entities.AdminPriceSetting.list("-created_date",100),enabled:!!a,staleTime:6e4}),p=d.useMemo(()=>{const s=N.filter(r=>r.is_active!==!1);return y.flatMap(r=>J.flatMap(l=>{const i=Number(r[l.field]);if(!Number.isFinite(i)||i<=0)return[];const m=s.filter(t=>[l.fuelType,l.anyType].includes(t.fuel_type)),f=[];return m.forEach(t=>{t.value!=null&&i>Number(t.value)&&f.push({...r,fuelLabel:l.label,price:i,max:t.value,min:t.min_value,type:"high",capLabel:t.label}),t.min_value!=null&&Number(t.min_value)>0&&i<Number(t.min_value)&&f.push({...r,fuelLabel:l.label,price:i,max:t.value,min:t.min_value,type:"low",capLabel:t.label})}),f}))},[y,N]),v=p.filter(s=>{if(g!=="all"&&s.type!==g)return!1;if(!c.trim())return!0;const r=c.toLowerCase();return[s.name,s.brand,s.city,s.suburb,s.province,s.fuelLabel].filter(
1Boolean).join(" ").toLowerCase().includes(r)}),b=M({mutationFn:async({anomaly:s,data:r})=>{var i,m;const l=await u.functions.invoke("manageStation",{operation:"update",station_id:s.id,data:r});if((i=l.data)!=null&&i.error)throw new Error(l.data.error);return(m=l.data)==null?void 0:m.result},onSuccess:()=>{L.invalidateQueries({queryKey:["price-anomaly-stations"]}),S.success("Station reviewed")},onError:s=>S.error(`Update failed: ${s.message}`)});return!a||k||A?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx($,{className:"h-8 w-8 animate-spin text-purple-600"})}):e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx("div",{className:"bg-gradient-to-br from-slate-950 via-purple-950 to-slate-950 text-white py-8",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs(U,{to:_("AdminDashboard"),className:"inline-flex items-center text-sm text-purple-200 hover:text-white mb-4",children:[e.jsx(R,{className:"h-4 w-4 mr-1"})," Back to dashboard"]}),e.jsxs("div",{className:"flex flex-col md:flex-row md:items-end md:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(o,{className:"bg-purple-500/20 text-purple-200 border-purple-400/30 mb-3",children:"Owner Review"}),e.jsxs("h1",{className:"text-3xl font-black tracking-tight flex items-center gap-3",children:[e.jsx(h,{className:"h-8 w-8"})," Price Anomalies"]}),e.jsx("p",{className:"text-gray-300 mt-1 text-sm",children:"Fresh cached prices above maximum caps or below minimum floors."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[e.jsxs("div",{className:"bg-white/10 rounded-xl px-4 py-3",children:[e.jsx("p",{className:"text-2xl font-black",children:p.length}),e.jsx("p",{className:"text-xs text-gray-300",children:"Total"})]}),e.jsxs("div",{className:"bg-red-500/20 rounded-xl px-4 py-3",children:[e.jsx("p",{className:"text-2xl font-black",children:p.filter(s=>s.type==="high").length}),e.jsx("p",{className:"text-xs text-red-100",children:"Above"})]}),e.jsxs("div",{className:"bg-orange-500/20 rounded-xl px-4 py-3",children:[e.jsx("p",{className:"text-2xl font-black",children:p.filter(s=>s.type==="low").length}),e.jsx("p",{className:"text-xs text-orange-100",children:"Below"})]})]})]})]})}),e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm p-4 mb-5 flex flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx(I,{value:c,onChange:s=>x(s.target.value),placeholder:"Search station, brand, city or fuel grade...",className:"pl-9"})]}),e.jsxs(K,{value:g,onValueChange:T,children:[e.jsx(z,{className:"sm:w-44",children:e.jsx(Q,{})}
1),e.jsxs(H,{children:[e.jsx(j,{value:"all",children:"All anomalies"}),e.jsx(j,{value:"high",children:"Above caps"}),e.jsx(j,{value:"low",children:"Below floors"})]})]})]}),v.length===0?e.jsxs("div",{className:"bg-white rounded-2xl shadow-sm p-12 text-center text-gray-500",children:[e.jsx(h,{className:"h-10 w-10 mx-auto mb-3 text-gray-300"}),"No price anomalies found."]}):e.jsx("div",{className:"space-y-3",children:v.map((s,r)=>e.jsx(O,{anomaly:s,isUpdating:b.isPending,onMarkGood:l=>b.mutate({anomaly:l,data:{price_quality_flag:"good",status_unreliable_prices:!1}}),onMarkUnreliable:l=>b.mutate({anomaly:l,data:{price_quality_flag:"suspicious",status_unreliable_prices:!0}})},`${s.id}-${s.fuelLabel}-${s.type}-${r}`))})]})]})}export{Y 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.