1import{f as V,P as G,r as v,b as J,j as e,w as u,C as W,K as X,N as Y,c as Z,Q as A,B as l,v as ee,s as M,J as B}from"./index-PtGACUVf.js";import{u as se}from"./useMutation-B6B2ZZTv.js";import{T as ae}from"./textarea-B113Ozlu.js";import{S as te,a as ie,b as ne,c as re,d as h}from"./select-BwSQ4ldD.js";import{T as le,a as de,b as q,c as d,d as ce,e as c}from"./table-BzCEyvEt.js";import{D as oe,a as me,b as xe,c as ue,e as he}from"./dialog-1knjOMG6.js";import{F}from"./flag-bMSkjfyE.js";import{C as je}from"./circle-alert-zZK6adB6.js";import{E as I}from"./external-link-ByXnn-Nj.js";import{S as L}from"./square-pen-BoD06PhD.js";import{E as O}from"./eye-B9hDvAFW.js";import{C as Q}from"./circle-check-big-sSf7dLsd.js";import{C as H}from"./circle-x-D8wBAwq0.js";import"./index-BdQq_4o_.js";import"./chevron-up-BZ1Up2zp.js";import"./index-DU2LHGu_.js";const z={name_incorrect:"Name incorrect",address_wrong:"Address wrong",phone_wrong:"Phone wrong",website_wrong:"Website wrong",permanently_closed:"Permanently closed",doesnt_exist:"Doesn't exist",duplicate:"Duplicate",other:"Other"},b={pending:{label:"Pending",color:"bg-yellow-500/10 text-yellow-600",icon:ee},reviewed:{label:"Reviewed",color:"bg-blue-500/10 text-blue-600",icon:O},resolved:{label:"Resolved",color:"bg-green-500/10 text-green-600",icon:Q},dismissed:{label:"Dismissed",color:"bg-gray-500/10 text-gray-600",icon:H}};function Pe(){var S,R,D;const{user:p}=V(),N=G(),[j,K]=v.useState("all"),[a,g]=v.useState(null),[w,y]=v.useState(""),{data:n,isLoading:$}=J({queryKey:["admin-reports",j],queryFn:async()=>{let s=M.from("business_reports").select(` 2 *, 3 businesses:business_id (id, name, city, slug, city_id, cities:city_id (domain)) 4 `).order("created_at",{ascending:!1});j!=="all"&&(s=s.eq("status",j));const{data:t,error:r}=await s;if(r)throw r;return t}}),o=se({mutationFn:async({reportId:s,status:t,notes:r})=>{const i={status:t};r!==void 0&&(i.admin_notes=r),(t==="resolved"||t==="dismissed")&&(i.resolved_at=new Date().toISOString(),i.resolved_by=p==null?void 0:p.id);const{error:m}=await M.from("business_reports").update(i).eq("id",s);if(m)throw m},onSuccess:()=>{N.invalidateQueries({queryKey:["admin-reports"]}),N.invalidateQueries({queryKey:["pending-reports-count"]}),B.success("Report updated"),g(null)},onError:s=>{console.error("Error updating report:",s),B.error("Failed to update report")}}),f=(s,t)=>{o.mutate({reportId:s,status:t})},U=()=>{a&&o.mutate({reportId:a.id,status:a.status,notes:w})},C=s=>{var i;const t=s.businesses;return t?`https://${((i=t.cities)==null?void 0:i.domain)||window.location.host}/business/${t.slug||t.id}`:"#"},_=(n==null?void 0:n.filter(s=>s.status==="pending").length)||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-display font-bold",children:"Business Reports"}),e.jsx("p",{className:"text-muted-foreground",children:"Review and manage reports about incorrect business information"})]}),_>0&&e.jsxs(u,{variant:"destructive",className:"text-sm",children:[_," pending"]})]}),e.jsxs(W,{children:[e.jsx(X,{className:"pb-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Y,{className:"text-lg",children:"All Reports"}),e.jsxs(te,{value:j,onValueChange:K,children:[e.jsx(ie,{className:"w-40",children:e.jsx(ne,{})}),e.jsxs(re,{children:[e.jsx(h,{value:"all",children:"All Status"}),e.jsx(h,{value:"pending",children:"Pending"}),e.jsx(h,{value:"reviewed",children:"Reviewed"}),e.jsx(h,{value:"resolved",children:"Resolved"}),e.jsx(h,{value:"dismissed",children:"Dismissed"})]})]})]})}),e.jsx(Z,{children:$?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading reports..."}):(n==null?void 0:n.length)===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No reports found"})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(le,{children:[e.jsx(de,{children:e.jsxs(q,{children:[e.jsx(d,{children:"Business"}),e.jsx(d,{children:"City"}),e.jsx(d,{children:"Report Type"}),e.jsx(d,{className:"max-w-xs",children:"Description"}),e.jsx(d,{children:"Status"}),e.jsx(d,{children:"Date"}),e.jsx(d,{className:"text-right",children:"Actions"})]})}),e.jsx(ce,{children:n==null?void 0:n.map(s=>{var r,i,m,T,k,E,P;const t=((r=b[s.status])==null?void 0:r.icon)||je;return e.jsxs(q,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>{g(s),y(s.admin_notes||"")},children:[e.jsx(c,{className:"font-medium",children:((i=s.businesses)==null?void 0:i.name)||"Unknown"}),e.jsx(c,{children:((m=s.businesses)==null?void 0:m.city)||"-"}),e.jsx(c,{children:e.jsxs("div",{className:"flex flex-wrap gap-1",children:[(T=s.report_type)==null?void 0:T.slice(0,2).map(x=>e.jsx(u,{variant:"outline",className:"text-xs",children:z[x]||x},x)),((k=s.report_type)==null?void 0:k.length)>2&&e.jsxs(u,{variant:"outline",className:"text-xs",children:["+",s.report_type.length-2]})]})}),e.jsx(c,{className:"max-w-xs truncate",children:s.description}),e.jsx(c,{children:e.jsxs(u,{className:(E=b[s.status])==null?void 0:E.
4color,children:[e.jsx(t,{className:"h-3 w-3 mr-1"}),(P=b[s.status])==null?void 0:P.label]})}),e.jsx(c,{className:"text-muted-foreground text-sm",children:A(new Date(s.created_at),"MMM d, yyyy")}),e.jsx(c,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",onClick:x=>x.stopPropagation(),children:[e.jsx(l,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx("a",{href:C(s),target:"_blank",rel:"noopener noreferrer",children:e.jsx(I,{className:"h-4 w-4"})})}),e.jsx(l,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx("a",{href:`/admin/listings/${s.business_id}`,children:e.jsx(L,{className:"h-4 w-4"})})})]})})]},s.id)})})]})})})]}),e.jsx(oe,{open:!!a,onOpenChange:s=>!s&&g(null),children:e.jsxs(me,{className:"max-w-2xl",children:[e.jsxs(xe,{children:[e.jsxs(ue,{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-5 w-5 text-destructive"}),"Report Details"]}),e.jsx(he,{children:"Review the report and take appropriate action"})]}),a&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50",children:[e.jsx("h4",{className:"font-semibold mb-1",children:(S=a.businesses)==null?void 0:S.name}),e.jsx("p",{className:"text-sm text-muted-foreground",children:(R=a.businesses)==null?void 0:R.city}),e.jsxs("div",{className:"flex gap-2 mt-3",children:[e.jsx(l,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:C(a),target:"_blank",rel:"noopener noreferrer",children:[e.jsx(I,{className:"h-3 w-3 mr-1"}),"View Listing"]})}),e.jsx(l,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:`/admin/listings/${a.business_id}`,children:[e.jsx(L,{className:"h-3 w-3 mr-1"}),"Edit Business"]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Issues Reported"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(D=a.report_type)==null?void 0:D.map(s=>e.jsx(u,{variant:"secondary",children:z[s]||s},s))})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Description"}),e.jsx("p",{className:"text-sm text-muted-foreground bg-muted/50 p-3 rounded-lg",children:a.description})]}),a.reporter_email&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-1",children:"Reporter Email"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.reporter_email})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-1",children:"Submitted"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:A(new Date(a.created_at),"MMMM d, yyyy 'at' h:mm a")})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"Admin Notes"}),e.jsx(ae,{placeholder:"Add notes about this report...",value:w,onChange:s=>y(s.target.value),rows:3}),e.jsx(l,{variant:"outline",size:"sm",className:"mt-2",onClick:U,disabled:o.isPending,children:"Save Notes"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 pt-4 border-t",children:[e.jsxs(l,{variant:a.status==="reviewed"?"default":"outline",onClick:()=>f(a.id,"reviewed"),disabled:o.isPending,children:[e.jsx(O,{className:"h-4 w-4 mr-1"}),"Mark Reviewed"]}),e.jsxs(l,{variant:a.status==="resolved"?"default":"outline",onClick:()=>f(a.id,"resolved"),disabled:o.isPending,children:[e.jsx(Q,{className:"h-4 w-4 mr-1"}),"Mark Resolved"]}),e.jsxs(l,{variant:"ghost",onClick:()=>f(a.id,"dismissed"),disabled:o.isPending,children:[e.jsx(H,{className:"h-4 w-4 mr-1"}),"Dismiss"]})]})]})]})})]})}export{Pe 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.