1import{a9 as S,r as g,j as e,G as k}from"./index-BkCXaXKa.js";import{u as v}from"./useMutation-HeNNX_A4.js";import{supabase as f}from"./client-BbU1qFW-.js";import{P as A}from"./Panel-BddOHuSM.js";import{C as x}from"./ConsoleButton-BHljfGyP.js";import{C as b}from"./ConsoleAlert-CTKm93I9.js";import{S as T}from"./StatusBadge-CiKmn8AI.js";import{a as C,L as E}from"./adminTime-Dt7W2DgA.js";import"./index-DJNj82Yw.js";const F="member_wall_photo_queue",_=500,j=["pending","printed","skipped"],P={pending:"approach",printed:"clear",skipped:"idle"},w={pending:"Pending",printed:"Printed",skipped:"Skipped"};function $(s){if(!s)return"â";const i=C(s)??new Date(s);return isNaN(i.getTime())?"â":new Intl.DateTimeFormat("en-US",{timeZone:E,month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0}).format(i)}function q(s){return s==null?"â":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(0)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`}function B(){return k({queryKey:["admin-wall-photo-queue"],staleTime:3e4,queryFn:async()=>{const{data:s,error:i}=await f.from(F).select("id,auth_user_id,original_object_path,content_type,byte_size,source,last_fetch_error,last_fetch_host,status,printed_at,printed_by,updated_at").order("updated_at",{ascending:!1}).limit(_);if(i)throw i;const n=s??[],r=Array.from(new Set(n.map(a=>a.auth_user_id))),d=new Map;if(r.length>0){const{data:a,error:u}=await f.from("member_profiles").select("auth_user_id, display_name").in("auth_user_id",r);if(u)throw u;for(const p of a??[])d.set(p.auth_user_id,p.display_name)}return{truncated:n.length>=_,rows:n.map(a=>({id:a.id,authUserId:a.auth_user_id,displayName:d.get(a.auth_user_id)??null,email:null,hasOriginal:!!a.original_object_path,contentType:a.content_type,byteSize:a.byte_size,source:a.source,lastFetchError:a.last_fetch_error,lastFetchHost:a.last_fetch_host,status:j.includes(a.status)?a.status:"pending",printedAt:a.printed_at,printedBy:a.printed_by,updatedAt:a.updated_at}))}}})}async function y(s,i){const{data:n,error:r}=await f.functions.invoke("admin-wall-photo-write",{body:{action:s,id:i}});if(r)throw r;if(n&&n.ok===!1)throw new Error(n.error??"Request failed");return n}const l="sy-label whitespace-nowrap px-cell-x py-2 text-left",o="px-cell-x py-3 align-top text-ui text-content-body";function K(){const{data:s,isPending:i,error:n}=B(),r=S(),[d,a]=g.useState("pending"),[u,p]=g.useState(null),h=v({mutationFn:({action:t,id:c})=>y(t,c),onSuccess:()=>{r.invalidateQueries({queryKey:["admin-wall-photo-queue"]})}});async function N(t){p(t);try{const c=await y("get_signed_url",t);c.signed_url&&window.open(c.signed_url,"_blank","noopener,noreferrer")}catch(c){console.error("wall_photo_signed_url_failed",c)}finally{p(null)}}const m=((s==null?void 0:s.rows)??[]).filter(t=>d==="all"||t.status===d);return e.jsxs("div",{className:"flex flex-col gap-stack",children:[e.jsx(b,{aspect:"info",title:"Member wall photo queue",children:"One row per member with a captured full-quality original -- from a direct upload, or a best-effort fetch of a pasted photo link. Download pulls a short-lived signed link to the original file for printing."}),s!=null&&s.truncated?e.jsxs(b,{aspect:"stop",title:"Showing partial data",children:["The query hit its ",_,"-row limit."]}):null,e.jsxs(A,{title:"Wall Photos",footer:e.jsxs("span",{children:[m.length," member",m.length===1?"":"s"," shown"]}),children:[e.jsx("div",{className:"flex flex-wrap items-end gap-3 border-b border-edge-subtle bg-surface-sunken px-4 py-3",children:e.jsxs("div",{children:[e.jsx("label",{htmlFor:"wp-status",className:"sy-label mb-1 block",children:"Status"}),e.jsxs("select",{id:"wp-status",value:d,onChange:t=>a(t.target.value),className:"h-control rounded-control border border-edge bg-surface-card px-3 text-ui text-content-body focus:outline-none focus:ring-2 focus:ring-[var(--focus-ring)]",children:[e.jsx("option",{value:"all",children:"All statuses"}),j.map(t=>e.jsx("option",{value:t,children:w[t]},t))]})]})}),n?e.jsxs("p",{className:"p-4 text-ui text-signal-stop-ink",children:["Failed to load: ",n.message]}):i?e.jsx("p",{className:"p-4 text-ui text-content-muted",children:"Loadingâ¦"}):m.length===0?e.jsx("p",{className:"p-4 text-ui text-content-muted",children:"No members match this filter."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[960px] border-collapse text-ui",children:[e.jsx("thead",{className:"border-b border-edge-subtle bg-surface-sunken",children:e.jsxs("tr",{children:[e.jsx("th",{className:`${l} min-w-[200px]`,children:"Member"}),e.jsx("th",{className:l,children:"Source"}),e.jsx("th",{className:l,children:"Size"}),e.jsx("th",{className:l,children:"Last fetch issue"}),e.jsx("th",{className:l,children:"Status"}),e.jsx("th",{className:`${l} min-w-[160px]`,children:"Updated"}),e.jsx("th",{className:l,children:e.jsx("span",{className:"sr-only",children:"Actions"})})]})}),e.jsx("tbody",{children:m.map(t=>e.jsxs("tr",{className:"border-b border-edge-subtle/60 last:border-b-0",children:[e.jsx("td",{className:o,children:e.jsx("div",{className:"max-w-[220px] truncate font-semibold text-content-strong",children:t.displayName??"â"})}),e.jsx("td",{className:o,children:t.source??"â"}),e.jsx("td",{className:`${o} sy-num`,children:q(t.byteSize)}),e.jsx("td",{className:`${o} text-ui-sm`,children:t.lastFetchError?`${t.lastFetchError}${t.lastFetchHost?` (${t.lastFetchHost})`:""}`:"â"}),e.jsx("td",{className:o,children:e.jsx(T,{aspect:P[t.status],children:w[t.status]})}),e.jsx("td",{className:`${o} sy-mono whitespace-nowrap`,children:$(t.updatedAt)}),e.jsx("td",{className:`${o} whitespace-nowrap`,children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{variant:"secondary",size:"sm",disabled:!t.hasOriginal||u===t.id,onClick:()=>void N(t.id),children:u===t.id?"Preparingâ¦":"Download"}),e.jsx(x,{variant:"secondary",size:"sm",disabled:t.status==="printed"||h.isPending,onClick:()=>h.mutate({action:"mark_printed",id:t.id}),children:"Mark printed"}),e.jsx(x,{variant:"ghost",size:"sm",disabled:t.status==="skipped"||h.isPending,onClick:()=>h.mutate({action:"mark_skipped",id:t.id}),children:"Skip"})]})})]},t.id))})]})})]})]})}export{K 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.