PageSourceSearch

https://myechoboard.com/assets/AdminPinterestRequestsPanel-D49_l9k1.js

js myechoboard.com collected 2026-09-24 13:51:04 UTC 50,698 bytes, 1 lines download raw bytes

1import{r as e,j as t}from"./vendor-react-C9yDzYQD.js";import{supabase as r}from"./supabase-client-_h80EYw_.js";import{a as s,S as a}from"./supabase-config-Bge368iX.js";import{B as i}from"./button-CcIRk75H.js";import{I as n}from"./input-CJADGzyX.js";import{S as o,a as l,b as d,c as u,d as c}from"./select-BE1IGN5Z.js";import{u as m}from"./useAuth-Dz3EPsxs.js";import{s as p}from"./documentVisibleInterval-kwPiY7AC.js";import{a as x}from"./runtime-utils-GN4cODRt.js";import{T as g}from"./triangle-alert-FKyvs90R.js";import{L as h}from"./loader-circle-CWK_zhHB.js";import{R as f}from"./refresh-cw-Bjlnjg0v.js";import{P as b}from"./panels-top-left-CSwYcjk9.js";import{P as w}from"./plus-CNl86JwM.js";import{a as j}from"./vendor-date-D4HAbvGT.js";import{Z as v}from"./zap-BLOtyeeL.js";import{E as _}from"./eye-off-Dee1325O.js";import{X as N}from"./x-lNdY5pWw.js";import{C as y}from"./clock-Qxd67VZh.js";import{c as k}from"./createLucideIcon-DNcTU-zM.js";import{S as q}from"./search-D7ByVMw5.js";import{C as S}from"./circle-check-DwjPV3g7.js";import{L as C}from"./vendor-router-X7RJKav4.js";import{F as $}from"./folder-open-Bn7HwDJq.js";import{I as P}from"./image-Bt9rnFUc.js";import{T as M}from"./trash-2-B7zVZuh_.js";const I=k("ArrowDownUp",[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"m21 8-4-4-4 4",key:"1c9v7m"}],["path",{d:"M17 4v16",key:"7dpous"}]]),R={pinterest:"#E60023",instagram:"#E1306C",x:"#000000",reddit:"#FF4500",cosmos:"#5B4CF5",tiktok:"#010101",tumblr:"#35465C",deviantart:"#05CC47",behance:"#1769FF",dribbble:"#EA4C89",arena:"#333333",flickr:"#FF0084","500px":"#222222"},A="admin:pinterest-hidden-emails",F="admin:pinterest-sort-oldest-first",L="admin:pinterest-platform-filter",U="Both your Pinterest profile and board must be public for full-board imports, including in the Chrome extension. Open the board link while logged out of Pinterest to check access before retrying.",T=`Echo could not access this Pinterest board. It may be private, deleted, not publicly visible, or the link may be a Pinterest pin, profile, homepage, or shared-pin link instead of a board URL. ${U}`;function D(){var k,D,E;const[z,H]=e.useState([]),[O,B]=e.useState(!0),[Q,J]=e.useState(null),[V,G]=e.useState(!1),[W,K]=e.useState(null),[Z,X]=e.useState({}),[Y,ee]=e.useState(null),[te,re]=e.useState("all"),[se,ae]=e.useState(""),[ie,ne]=e.useState(()=>"undefined"==typeof window?"all":window.localStorage.getItem(L)||"all"),[oe,le]=e.useState(()=>"undefined"==typeof window?"":window.sessionStorage.getItem(A)||""),[de,ue]=e.useState(()=>"undefined"!=typeof window&&"true"===window.localStorage.getItem(F)),[ce,me]=e.useState(null),[pe,xe]=e.useState(null),[ge,he]=e.useState(1),[fe,be]=e.useState({}),[we,je]=e.useState(null),[ve,_e]=e.useState(!1),[Ne,ye]=e.useState({}),ke=e.useRef(0),qe=e.useRef(new Map),Se=e.useRef(null),[Ce,$e]=e.useState(null),[Pe,Me]=e.useState({}),[Ie,Re]=e.useState(null),[Ae,Fe]=e.useState(null),{toast:Le}=m(),Ue=e=>{const t=String(e||"pending").trim().toLowerCase();return"pending"===t||"processing"===t||"completed"===t||"error"===t||"unavailable"===t?t:"pending"},Te=async(e={})=>{e.silent||G(!0),e.silent||J(null);const t=new AbortController,s=window.setTimeout(()=>t.abort(),15e3);try{const{data:e,error:s}=await r.rpc("get_all_pinterest_requests").abortSignal(t.signal);if(s)throw s;const a=(e||[]).map(e=>({...e,id:e.request_id||e.id,status:Ue(e.status)}));return a&&(H(a),K(new Date),Oe(a)),a}catch(a){if(!e.silent){const e=a.message||("object"==typeof a?JSON.stringify(a):String(a)),t=/abort|failed to fetch|network/i.test(e)?"Could not refresh import requests. Check your connection and try again.":e;J(t),Le({title:"Failed to fetch requests",description:t,variant:"error"})}return null}finally{window.clearTimeout(s),B(!1),e.silent||G(!1)}},De=(e,t)=>{var r;qe.current.get(e)===t&&(qe.current.delete(e),qe.current.size>0||(null==(r=Se.current)||r.call(Se),Se.current=null))};e.useEffect(()=>{Te()},[]),e.useEffect(()=>()=>{var e;null==(e=Se.current)||e.call(Se),Se.current=null,qe.current.clear()},[]),e.useEffect(()=>{"undefined"!=typeof window&&window.sessionStorage.setItem(A,oe)},[oe]),e.useEffect(()=>{"undefined"!=typeof window&&window.localStorage.setItem(F,de?"true":"false")},[de]),e.useEffect(()=>{"undefined"!=typeof window&&window.localStorage.setItem(L,ie)},[ie]);const Ee=e=>String(e||"Something went wrong.").replace(/Remember: Make sure your Pinterest board is set to public before importing, or use Echo's Chrome extension(?: to import it while signed into Pinterest)?\./gi,U).replace(/Failed to insert memories:\s*canceling statement due to statement timeout/gi,"Echo found pins on this Pinterest board, but hit a temporary issue while saving them. Please try the import again.").replace(/Failed to insert memories:[^.]*/gi,"Echo found pins on this Pinterest board, but hit a temporary issue while saving them. Please try the import again.").replace(/Failed to link imported memories to board:[^.]*/gi,"Echo found pins on this Pinterest board, but hit a temporary issue while saving them. Please try the import again.").replace(/Could not resolve the Pinterest board id\./gi,T).replace(/PINTEREST_BOARD_ID_MISSING/gi,T).replace(/Paste a board URL like pinterest\.com\/name\/board\/\./gi,"Paste a public Pinterest board URL like pinterest.com/name/board/.").replace(/Paste a public board URL/gi,"Paste a public Pinterest board URL").replace(/Please submit a public board URL/gi,"Please submit a public Pinterest board URL").replace(/Please submit a public Pinterest board URL, or use the Echo Chrome extension to import it while signed into Pinterest\./gi,U),ze=e=>{var t;if(!e)return"Something went wrong.";if("string"==typeof e)return Ee(e);if((null==e?void 0:e.error_code)&&(null==e?void 0:e.message))return Ee(e.message);if(null==e?void 0:e.error)return Ee(e.error);const r=null==(t=null==e?void 0:e.context)?void 0:t.body;if(r)try{const e="string"==typeof r?JSON.parse(r):r;if((null==e?void 0:e.error_code)&&(null==e?void 0:e.error))return Ee(`${e.error_code}: ${e.error}`);if(null==e?void 0:e.error)return Ee(e.error);if(null==e?void 0:e.message)return Ee(e.message)}catch{if("string"==typeof r)return Ee(r)}if(null==e?void 0:e.message)return Ee(e.message);try{return Ee(JSON.stringify(e))}catch{return"Something went wrong."}},He=async e=>{const t=await(async()=>{var e,t;const{data:s}=await r.auth.getSession();let a=null==(e=null==s?void 0:s.session)?void 0:e.access_token;if(!a){const{data:e}=await r.auth.refreshSession();a=null==(t=null==e?void 0:e.session)?void 0:t.access_token}return a})(),i=await fetch(`${s}/functions/v1/pinterest-import`,{method:"POST",headers:{"Content-Type":"application/json",...t?{Authorization:`Bearer ${t}`}:{},apikey:a},body:JSON.stringify(e)}),n=await i.text();let o=null;if(n)try{o=JSON.parse(n)}catch{o={error:n}}if(!i.ok)throw{message:(null==o?void 0:o.error)||(null==o?void 0:o.message)||`Pinterest import failed with HTTP ${i.status}`,error_code:(null==o?void 0:o.error_code)||null,admin_error:(null==o?void 0:o.admin_error)||null,details:(null==o?void 0:o.details)||null,status:i.status};return o},Oe=async e=>{const t=Array.from(new Set(e.filter(e=>!e.target_board_id).map(e=>
1e.user_id).filter(Boolean)));for(const s of t)if(!Z[s])try{const{data:e}=await r.rpc("admin_get_user_boards",{p_user_id:s});e&&X(t=>({...t,[s]:e}))}catch{}},Be=async(e,t)=>{xe(e);const s=t?"unavailable":"error";try{const{error:a}=await r.rpc("update_pinterest_request_status",{request_id:e,new_status:s});if(a)throw a;H(t=>t.map(t=>t.id===e?{...t,status:s}:t)),Le({title:t?"Failure marked reviewed":"Moved back to Failed"})}catch(a){Le({title:"Status update failed",description:a.message,variant:"error"})}finally{xe(null)}},Qe=async e=>{Me(t=>({...t,[e.id]:t[e.id]||[]})),Fe({requestId:e.id,email:e.user_email||"Unknown user",title:"Auto import requested",message:"Sending this board to the Pinterest auto importer...",statusFilter:"queued",tone:"blue"}),be(t=>({...t,[e.id]:!0})),H(t=>t.map(t=>t.id===e.id?{...t,status:"processing",import_queued_at:(new Date).toISOString(),import_started_at:(new Date).toISOString(),import_state:{...t.import_state||{},queuedForAutoImport:!0,phase:"starting"},import_progress_message:"Starting Pinterest import..."}:t));let t=!1;const r=t=>{const s=t.find(t=>t.id===e.id||t.request_id===e.id);if(s&&["completed","error","unavailable"].includes(s.status))if(De(e.id,r),be(t=>{const r={...t};return delete r[e.id],r}),"completed"===s.status)Fe({requestId:e.id,email:s.user_email||e.user_email||"Unknown user",title:"Pinterest import complete",message:s.import_progress_message||`${s.import_imported_count||0} echoes imported.`,statusFilter:"completed",tone:"green"}),We(e.id),Le({title:"Pinterest import complete",description:s.import_progress_message||`${s.import_imported_count||0} echoes imported.`});else{const t=Ee(s.error_reason||s.import_progress_message||"Something went wrong.");Fe({requestId:e.id,email:s.user_email||e.user_email||"Unknown user",title:"Auto import failed",message:t,statusFilter:"unavailable"===s.status?"unavailable":"error",tone:"red"}),We(e.id),Le({title:"Auto import failed",description:t,variant:"error"})}};qe.current.set(e.id,r),Se.current||(Se.current=p(()=>{Te({silent:!0}).then(e=>{e&&qe.current.forEach(t=>{t(e)})})},2e3,{runOnResume:!0}));try{const r=await He({requestId:e.id,importMode:"public-pinterest-board",skipAI:!1});if(null==r?void 0:r.started)return t=!0,Fe({requestId:e.id,email:e.user_email||"Unknown user",title:(null==r?void 0:r.queued)?"Pinterest import queued":"Pinterest import started",message:(null==r?void 0:r.queued)?"It will start automatically when an import slot opens.":"The request moved to Processing. Progress and events will update here.",statusFilter:(null==r?void 0:r.queued)?"queued":"processing",tone:(null==r?void 0:r.queued)?"amber":"blue"}),We(e.id),Le({title:(null==r?void 0:r.queued)?"Pinterest import queued":"Pinterest import started",description:(null==r?void 0:r.queued)?"It will start automatically when an import slot opens.":"I’ll keep showing progress here while the board imports."}),void Te({silent:!0});if(null==r?void 0:r.queued)return t=!0,Fe({requestId:e.id,email:e.user_email||"Unknown user",title:"Pinterest import queued",message:"It will start automatically when an import slot opens.",statusFilter:"queued",tone:"amber"}),We(e.id),Le({title:"Pinterest import queued",description:"It will start automatically when an import slot opens."}),void Te({silent:!0});Fe({requestId:e.id,email:e.user_email||"Unknown user",title:"Import request refreshed",message:(null==r?void 0:r.message)||"The importer responded without a start/queue status, so the request was refreshed.",statusFilter:"all",tone:"amber"}),Le({title:"Import request refreshed",description:(null==r?void 0:r.message)||"No start/queue status came back. I refreshed the row so you can inspect it."}),Te({silent:!0})}catch(s){const t=ze(s),r=(new Date).toISOString();H(s=>s.map(s=>s.id===e.id?{...s,status:"error",error_reason:t,import_progress_message:t,processed_at:r,import_finished_at:r}:s)),We(e.id),Fe({requestId:e.id,email:e.user_email||"Unknown user",title:"Auto import failed",message:t,statusFilter:"error",tone:"red"}),Le({title:"Auto import failed",description:t,variant:"error"})}finally{t||De(e.id,r),t||window.setTimeout(()=>{be(t=>{const r={...t};return delete r[e.id],r})},1200)}},Je=async e=>He({requestId:e,importMode:"public-pinterest-board",skipAI:!1}),Ve=async(e={})=>{_e(!0);try{const t=await He({importMode:"public-pinterest-queue-drain"});if(!e.silent){const e=(null==t?void 0:t.scanned_count)?` · ${t.scanned_count} checked`:"";Le({title:"Queue checked",description:`${(null==t?void 0:t.started_count)||0} started${(null==t?void 0:t.skipped_count)?` · ${t.skipped_count}
1 skipped`:""}${e}.`})}Te({silent:!0})}catch(t){e.silent||Le({title:"Queue nudge failed",description:ze(t),variant:"error"})}finally{_e(!1)}},Ge=async e=>{ye(t=>({...t,[e]:!0}));try{await He({requestId:e,importMode:"public-pinterest-queue-cancel"}),Le({title:"Removed from queue"}),Te({silent:!0})}catch(t){Le({title:"Remove failed",description:ze(t),variant:"error"})}finally{ye(t=>{const r={...t};return delete r[e],r})}},We=async(e,t={})=>{t.silent||Re(e);try{const{data:t,error:s}=await r.rpc("get_pinterest_import_events",{p_request_id:e});if(s)throw s;Me(r=>({...r,[e]:t||[]}))}catch(s){Le({title:"Failed to load import events",description:s.message,variant:"error"})}finally{t.silent||Re(null)}},Ke=async e=>{const t=Ce===e?null:e;$e(t),t&&!Pe[e]&&await We(e)},Ze=e.useMemo(()=>new Set(oe.split(/[\s,;]+/).map(e=>e.trim().toLowerCase()).filter(Boolean)),[oe]),Xe=e.useMemo(()=>0===Ze.size?z:z.filter(e=>!Ze.has(String(e.user_email||"").trim().toLowerCase())),[z,Ze]),Ye=z.length-Xe.length,et=e=>String(e||"pinterest").trim().toLowerCase()||"pinterest",tt=e=>e.split(/[\s_-]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")||"Unknown",rt=e.useMemo(()=>{const e=new Map;return Xe.forEach(t=>{const r=et(t.platform);e.set(r,(e.get(r)||0)+1)}),Array.from(e.entries()).sort(([e],[t])=>"pinterest"===e?-1:"pinterest"===t?1:e.localeCompare(t)).map(([e,t])=>({id:e,label:tt(e),count:t}))},[Xe]),st=e.useMemo(()=>"all"===ie?Xe:Xe.filter(e=>et(e.platform)===ie),[Xe,ie]),at="all"===ie?"All platforms":(null==(k=rt.find(e=>e.id===ie))?void 0:k.label)||tt(ie),it=e=>e.import_state&&"object"==typeof e.import_state?e.import_state:{},nt=e=>"pending"===e.status&&!!e.next_retry_at,ot=e=>{const t=it(e);return"pending"===e.status&&!nt(e)&&!!e.import_queued_at&&!!t.queuedForAutoImport},lt=st.filter(e=>"processing"===e.status||ot(e)).sort((e,t)=>{const r=new Date(e.import_started_at||e.import_queued_at||e.created_at).getTime(),s=new Date(t.import_started_at||t.import_queued_at||t.created_at).getTime();return"processing"===e.status&&"processing"!==t.status?-1:"processing"!==e.status&&"processing"===t.status?1:r-s}),dt=lt.filter(e=>"processing"===e.status).length,ut=lt.length-dt,ct=Object.keys(fe).length,mt=lt.length>0||ct>0||"queued"===te||"delayed"===te||"processing"===te||Boolean(Ce);if(e.useEffect(()=>{if(O||ut<=0||dt>=2||ve)return;const e=Date.now();e-ke.current<15e3||(ke.current=e,Ve({silent:!0}))},[O,ut,dt,ve]),e.useEffect(()=>{if(!(O||!mt||ct>0))return p(()=>{Te({silent:!0}).then(()=>{Ce&&We(Ce,{silent:!0})})},4e3)},[ct,O,mt,Ce]),O)return t.jsx("div",{className:"p-8 text-center text-muted-foreground",children:"Loading import requests..."});if(Q&&0===z.length)return t.jsxs("div",{className:"flex flex-col items-center gap-3 p-8 text-center text-muted-foreground",children:[t.jsx(g,{className:"h-8 w-8 text-amber-500"}),t.jsx("p",{className:"max-w-md text-sm",children:Q}),t.jsxs(i,{variant:"outline",size:"sm",onClick:()=>Te(),disabled:V,children:[V?t.jsx(h,{className:"mr-2 h-4 w-4 animate-spin"}):t.jsx(f,{className:"mr-2 h-4 w-4"}),"Try again"]})]});if(0===z.length)return t.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[t.jsx(b,{className:"w-12 h-12 mx-auto mb-4 opacity-10"}),t.jsx("p",{className:"text-xs font-medium",children:"No import requests found."})]});const pt={all:st.length,pending:st.filter(e=>"pending"===e.status&&!ot(e)&&!nt(e)).length,queued:st.filter(e=>ot(e)).length,delayed:st.filter(e=>nt(e)).length,processing:st.filter(e=>"processing"===e.status).length,completed:st.filter(e=>"completed"===e.status).length,error:st.filter(e=>"error"===e.status).length,unavailable:st.filter(e=>"unavailable"===e.status).length},xt="all"===te?st:"queued"===te?st.filter(e=>ot(e)):"delayed"===te?st.filter(e=>nt(e)):"pending"===te?st.filter(e=>"pending"===e.status&&!ot(e)&&!nt(e)):st.filter(e=>e.status===te),gt=se.trim().toLowerCase().replace(/^@/,""),ht=gt?xt.filter(e=>{const t=String(e.user_email||"").toLowerCase(),r=String(e.user_username||"").toLowerCase().replace(/^@/,"");return t.includes(gt)||r.includes(gt)}):xt,ft=e=>{const t=[e.import_finished_at,e.processed_at,e.error_emailed_at,e.error_notified_at,e.completed_emailed_at,e.completed_notified_at,e.import_started_at,e.import_queued_at,e.next_retry_at,e.import_last_heartbeat_at,e.created_at];let r=0;for(const s of t){const e=new Date(s||0).getTime();Number.isFinite(e)&&e>r&&(r=e)}return r},bt=[...ht].sort((e,t)=>
1{const r="error"===te||"unavailable"===te||"completed"===te||"queued"===te||"delayed"===te||"processing"===te,s=r?ft(e):new Date(e.created_at||0).getTime(),a=r?ft(t):new Date(t.created_at||0).getTime(),i=de?s-a:a-s;return 0!==i?i:String(e.id||"").localeCompare(String(t.id||""))}),wt=Math.max(1,Math.ceil(bt.length/20)),jt=Math.min(ge,wt),vt=bt.slice(20*(jt-1),20*jt),_t=[{id:"all",label:"All",color:"text-foreground"},{id:"pending",label:"Ready",color:"text-amber-500"},{id:"queued",label:"Queued",color:"text-sky-500"},{id:"delayed",label:"Retry later",color:"text-violet-500"},{id:"processing",label:"Processing",color:"text-blue-500"},{id:"completed",label:"Completed",color:"text-green-500"},{id:"error",label:"Failed",color:"text-red-500"},{id:"unavailable",label:"Reviewed",color:"text-slate-500"}],Nt=(null==(D=_t.find(e=>e.id===te))?void 0:D.label.toLowerCase())||te,yt=pt.queued+pt.processing,kt=e=>{if(!e)return"";const t=Math.max(0,Date.now()-new Date(e).getTime()),r=Math.floor(t/6e4);if(r<60)return`${Math.max(1,r)}m`;const s=Math.floor(r/60);return s<48?`${s}h`:`${Math.floor(s/24)}d`},qt=st.filter(e=>"pinterest"===et(e.platform)&&"pending"===e.status&&!ot(e)&&!nt(e)).sort((e,t)=>new Date(e.created_at).getTime()-new Date(t.created_at).getTime()),St=qt[0],Ct=St?kt(St.created_at):"",$t=[{label:"Ready",value:pt.pending,detail:Ct?`Oldest ${Ct}`:"Can start now",filter:"pending",icon:v,className:"border-amber-500/10 bg-amber-500/5 text-amber-500"},{label:"Live",value:yt,detail:`${pt.processing} running · ${pt.queued} queued`,filter:pt.processing>0?"processing":"queued",icon:f,className:"border-blue-500/10 bg-blue-500/5 text-blue-500"},{label:"Failed",value:pt.error,detail:"Needs review",filter:"error",icon:g,className:"border-red-500/10 bg-red-500/5 text-red-500"},{label:"Reviewed",value:pt.unavailable,detail:"Reviewed failures",filter:"unavailable",icon:_,className:"border-slate-500/10 bg-slate-500/5 text-slate-500"}],Pt=st.filter(e=>"error"===e.status).sort((e,t)=>new Date(t.updated_at||t.created_at).getTime()-new Date(e.updated_at||e.created_at).getTime())[0];return t.jsxs("div",{className:"space-y-4",children:[t.jsxs("div",{className:"flex items-center justify-between gap-4 pb-2",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:t.jsx(w,{className:"w-5 h-5 text-primary"})}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-sm font-bold uppercase tracking-widest text-foreground/80",children:"Auto Imports"}),t.jsxs("p",{className:"text-[11px] text-muted-foreground font-bold mt-0.5",children:[at," · Missing board imports go to Unsorted"]})]})]}),t.jsxs("div",{className:"hidden items-center gap-2 md:flex",children:[t.jsx("span",{className:"rounded-full px-2.5 py-1 text-[10px] font-bold uppercase tracking-widest "+(mt?"bg-blue-500/10 text-blue-500":"bg-muted text-muted-foreground"),children:mt?"Live refresh":"Manual refresh"}),W&&t.jsxs("span",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:["Updated ",j(W,"HH:mm:ss")]}),t.jsxs(i,{size:"sm",variant:"outline",disabled:V,onClick:()=>Te(),className:"h-8 rounded-xl px-2.5 text-[10px] font-bold gap-1.5",children:[t.jsx(f,{className:"h-3.5 w-3.5 "+(V?"animate-spin":"")}),"Refresh"]})]})]}),t.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:$t.map(e=>{const r=e.icon;return t.jsx("button",{type:"button",onClick:()=>{re(e.filter),he(1)},className:`group rounded-2xl border p-3 text-left transition hover:-translate-y-0.5 hover:bg-background/70 ${e.className}`,children:t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest opacity-80",children:e.label}),t.jsx("p",{className:"mt-1 text-2xl font-black leading-none text-foreground",children:e.value}),t.jsx("p",{className:"mt-1 truncate text-[11px] font-bold opacity-75",children:e.detail})]}),t.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xl bg-background/70 ring-1 ring-current/10",children:t.jsx(r,{className:"h-4 w-4"})})]})},e.label)})}),St&&t.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-amber-500/10 bg-amber-500/5 p-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-amber-500",children:"Next import ready"}),t.jsxs("p",{className:"mt-1 truncate text-xs font-bold text-foreground",children:[St.user_email||"Unknown user"," · ",St.target_board_name||"Unsorted",Ct?` · waiting ${Ct}`:""," · ",qt.length," ready"]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsxs(i,{size:"sm",onClick:()=>Qe(St),disabled:!!fe[St.id]||null!==we,className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:[fe[St.id]?t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(v,{className:"h-3.5 w-3.5"}),"Start oldest"]}),[5,10].map(e=>t.jsxs(i,{size:"sm",variant:"outline",onClick:()=>(async e=>{const t=qt.slice(0,e);if(0===t.length)return void Le({title:"No ready Pinterest boards",de
1scription:"There are no ready Pinterest requests to queue in this view."});const r=(new Date).toISOString();je(e),be(e=>({...e,...Object.fromEntries(t.map(e=>[e.id,!0]))})),H(e=>e.map(e=>t.some(t=>t.id===e.id)?{...e,import_queued_at:e.import_queued_at||r,import_state:{...e.import_state||{},queuedForAutoImport:!0,phase:"queued"},import_progress_message:"Queued for Pinterest auto import..."}:e)),Fe({requestId:t[0].id,email:`${t.length} Pinterest ${1===t.length?"board":"boards"}`,title:"Bulk queue started",message:`Queueing ${t.length} ready ${1===t.length?"request":"requests"}. Up to 2 can process at once; the rest wait in order.`,statusFilter:"queued",tone:"blue"});let s=0,a=0;for(const n of t)try{const e=await Je(n.id);(null==e?void 0:e.started)||null==e||e.queued,s+=1}catch(i){a+=1}Fe({requestId:t[0].id,email:`${s} queued/started`,title:a?"Bulk queue finished with errors":"Bulk queue finished",message:a?`${s} queued or started · ${a} failed. Open Error for details.`:`${s} ready ${1===s?"request is":"requests are"} now queued or processing.`,statusFilter:a?"error":"queued",tone:a?"amber":"green"}),Le({title:a?"Bulk queue finished with errors":"Bulk queue finished",description:a?`${s} queued/started · ${a} failed.`:`${s} queued or started. The server will process 2 at a time.`,variant:a?"default":void 0}),await Te({silent:!0}),be(e=>{const r={...e};return t.forEach(e=>delete r[e.id]),r}),je(null)})(e),disabled:null!==we||0===qt.length,className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",title:`Queue the next ${Math.min(e,qt.length)} ready Pinterest imports. Two process at a time.`,children:[we===e?t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(v,{className:"h-3.5 w-3.5"}),"Queue ",Math.min(e,qt.length)]},e))]})]}),Pt&&t.jsxs("button",{type:"button",onClick:()=>{re("error"),he(1),$e(Pt.id),We(Pt.id)},className:"w-full rounded-2xl border border-red-500/10 bg-red-500/5 p-3 text-left transition hover:bg-background/70",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-red-500",children:"Latest failure"}),t.jsxs("p",{className:"mt-1 truncate text-xs font-bold text-foreground",children:[Pt.user_email||"Unknown user"," · ",Pt.import_error_code||Pt.error_reason||"Open events"]})]}),lt.length>0&&t.jsxs("div",{className:"rounded-2xl border border-blue-500/10 bg-blue-500/5 p-4",children:[t.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3",children:[t.jsxs("div",{children:[t.jsx("h4",{className:"text-xs font-bold uppercase tracking-widest text-blue-500",children:"Live Import Queue"}),t.jsxs("p",{className:"mt-0.5 text-[11px] font-medium text-blue-500/75",children:[dt," running · ",ut," waiting"]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"rounded-full bg-blue-500/10 px-2.5 py-1 text-[10px] font-bold uppercase tracking-widest text-blue-500",children:[lt.length," active"]}),t.jsxs(i,{size:"sm",variant:"outline",disabled:ve,onClick:()=>{Ve()},className:"h-8 rounded-xl px-2.5 text-[10px] font-bold gap-1.5",title:"Start queued imports if a slot is open",children:[ve?t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(f,{className:"h-3.5 w-3.5"}),"Run Queue"]})]})]}),t.jsxs("div",{className:"space-y-2",children:[lt.slice(0,8).map((e,r)=>{const s=it(e),a=Number(e.import_total_count||0),i=Number(e.import_fetched_count||0),n=Number(e.import_imported_count||0),o=Number(e.import_skipped_count||0),l=Number(s.accessibleFetched||i||0),d=Number(s.reportedTotal||a||0),u="completed"===e.status&&d>0&&l>0&&l<d?`${l} accessible / ${d} reported`:a>0?`${Math.min(i,a)}/${a}`:"processing"===e.status?`${i} fetched`:"Waiting",c=a>0?Math.min("completed"===e.status?100:98,Math.round(i/a*100)):"processing"===e.status?8:0,m=String(s.phase||("processing"===e.status?"starting":"queued"));return t.jsxs("div",{className:"rounded-xl border border-blue-500/10 bg-background/70 p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"rounded-full bg-blue-500/10 px-2 py-0.5 text-[10px] font-bold uppercase tracking-widest text-blue-500",children:"processing"===e.status?"Running":`#${r+1}`}),t.jsx("p",{className:"truncate text-xs font-bold text-foreground",children:e.user_email||"Unknown User"})]}),t.jsxs("p",{className:"mt-1 truncate text-[10px] font-medium text-muted-foreground",children:[e.target_board_name||"Unsorted"," · ",m]}
1)]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsx("p",{className:"text-[10px] font-bold text-blue-500",children:u}),"processing"!==e.status&&t.jsx("button",{type:"button",disabled:!!Ne[e.id],onClick:()=>Ge(e.id),className:"flex h-6 w-6 items-center justify-center rounded-lg text-muted-foreground hover:bg-red-500/10 hover:text-red-500 disabled:opacity-50",title:"Remove from queue",children:Ne[e.id]?t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(N,{className:"h-3.5 w-3.5"})})]})]}),t.jsx("div",{role:"progressbar","aria-label":`Pinterest import progress for ${e.target_board_name||e.user_email||"queued import"}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":c,className:"h-2 overflow-hidden rounded-full bg-blue-500/10",children:t.jsx("div",{className:"h-full rounded-full bg-blue-500 transition-all duration-500",style:{width:`${c}%`}})}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 text-[10px] font-bold text-blue-500/75",children:[t.jsx("span",{children:Ee(e.import_progress_message||("processing"===e.status?"Starting Pinterest import...":"Waiting for an import slot..."))}),t.jsxs("span",{children:[n," imported",o?` · ${o} skipped`:""]})]})]},e.id)}),lt.length>8&&t.jsxs("p",{className:"px-1 text-[10px] font-bold uppercase tracking-widest text-blue-500/70",children:["+",lt.length-8," more waiting below"]})]})]}),Ae&&t.jsx("div",{className:"rounded-2xl border p-3 "+("green"===Ae.tone?"border-green-500/10 bg-green-500/5":"red"===Ae.tone?"border-red-500/10 bg-red-500/5":"amber"===Ae.tone?"border-amber-500/10 bg-amber-500/5":"border-blue-500/10 bg-blue-500/5"),children:t.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest "+("green"===Ae.tone?"text-green-500":"red"===Ae.tone?"text-red-500":"amber"===Ae.tone?"text-amber-500":"text-blue-500"),children:Ae.title}),t.jsx("p",{className:"mt-1 truncate text-xs font-bold text-foreground",children:Ae.email}),t.jsx("p",{className:"mt-0.5 text-[11px] font-medium text-muted-foreground",children:Ae.message})]}),t.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[t.jsxs(i,{size:"sm",variant:"outline",onClick:()=>{re(Ae.statusFilter),he(1),$e(Ae.requestId),We(Ae.requestId)},className:"h-8 rounded-xl px-2.5 text-[10px] font-bold gap-1.5",children:[t.jsx(y,{className:"h-3.5 w-3.5"}),"Show request"]}),t.jsx("button",{type:"button",onClick:()=>Fe(null),className:"flex h-8 w-8 items-center justify-center rounded-xl text-muted-foreground hover:bg-background/70 hover:text-foreground","aria-label":"Dismiss import action",children:t.jsx(N,{className:"h-3.5 w-3.5"})})]})]})}),t.jsxs("div",{className:"space-y-3",children:[t.jsx("div",{className:"grid w-full grid-cols-2 gap-2 rounded-2xl bg-muted/25 p-2 sm:grid-cols-4 lg:grid-cols-8",children:_t.map(e=>t.jsxs("button",{onClick:()=>{re(e.id),he(1)},className:"flex min-h-12 items-center justify-between gap-2 rounded-xl px-3 py-2 text-left text-[11px] font-bold transition-all "+(te===e.id?"bg-background shadow-sm ring-1 ring-foreground/10":"text-muted-foreground hover:bg-background/50 hover:text-foreground"),children:[t.jsx("span",{className:`${e.color} truncate`,children:e.label}),pt[e.id]>0&&t.jsx("span",{className:`shrink-0 px-2 py-0.5 rounded-full text-[10px] font-bold ${te===e.id?e.color:"text-muted-foreground"}
1 bg-foreground/5`,children:pt[e.id]})]},e.id))}),t.jsxs("div",{className:"flex flex-col gap-2 rounded-2xl border border-foreground/5 bg-background/40 p-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:(null==(E=_t.find(e=>e.id===te))?void 0:E.label)||"Imports"}),t.jsx("p",{className:"mt-1 text-xs font-medium text-foreground/80",children:{all:"Every import request for the selected platform, including ready, queued, running, completed, and failed imports.",pending:"Ready to auto import. If no board is set, pins import to Unsorted.",queued:"Clicked for auto import and waiting for an import slot.",delayed:"Temporarily unavailable Pinterest boards parked outside the active queue until their next bounded retry.",processing:"Currently running in the importer.",completed:"Finished imports, with automated update status below each request.",error:"Failed imports. Open Import events to inspect the exact error code and phase.",unavailable:"Failures that an admin has reviewed and moved out of the active Failed queue."}[te]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"rounded-full px-2.5 py-1 text-[10px] font-bold uppercase tracking-widest md:hidden "+(mt?"bg-blue-500/10 text-blue-500":"bg-muted text-muted-foreground"),children:mt?"Live refresh":"Manual refresh"}),W&&t.jsxs("span",{className:"rounded-full bg-muted px-2.5 py-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:["Updated ",j(W,"HH:mm:ss")]}),t.jsxs(i,{size:"sm",variant:"outline",disabled:V,onClick:()=>Te(),className:"h-8 rounded-xl px-2.5 text-[10px] font-bold gap-1.5 md:hidden",children:[t.jsx(f,{className:"h-3.5 w-3.5 "+(V?"animate-spin":"")}),"Refresh"]})]})]}),t.jsxs("div",{className:"grid w-full gap-2 lg:grid-cols-[minmax(180px,220px)_auto_minmax(220px,1fr)_minmax(260px,1fr)] lg:items-start",children:[t.jsxs(o,{value:ie,onValueChange:e=>{ne(e),he(1)},children:[t.jsx(l,{className:"h-10 rounded-xl bg-background text-xs font-bold",children:t.jsx(d,{placeholder:"Platform"})}),t.jsxs(u,{children:[t.jsxs(c,{value:"all",children:["All platforms (",Xe.length,")"]}),rt.map(e=>t.jsxs(c,{value:e.id,children:[e.label," (",e.count,")"]},e.id))]})]}),t.jsxs(i,{type:"button",variant:de?"default":"outline",onClick:()=>{ue(e=>!e),he(1)},className:"h-10 justify-center rounded-xl px-3 text-[11px] font-bold gap-1.5",title:de?"Showing oldest requests first":"Showing newest requests first",children:[t.jsx(I,{className:"h-3.5 w-3.5"}),de?"Oldest first":"Newest first"]}),t.jsxs("div",{className:"relative w-full",children:[t.jsx(q,{className:"absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(n,{value:se,onChange:e=>{ae(e.target.value),he(1)},placeholder:"Search email or username...",className:"h-10 rounded-xl bg-background pl-9 pr-9 text-xs font-medium"}),se&&t.jsx("button",{type:"button",onClick:()=>{ae(""),he(1)},className:"absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Clear user search",children:t.jsx(N,{className:"h-3.5 w-3.5"})})]}),t.jsxs("div",{className:"space-y-1",children:[t.jsxs("div",{className:"relative w-full",children:[t.jsx(_,{className:"absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(n,{value:oe,onChange:e=>{le(e.target.value),he(1)},placeholder:"Hide email(s) temporarily...",className:"h-10 rounded-xl bg-background pl-9 pr-9 text-xs font-medium"}),oe&&t.jsx("button",{type:"button",onClick:()=>{le(""),he(1)},className:"absolute right-2 top-1/2 flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-lg text-muted-foreground hover:bg-muted hover:text-foreground","aria-label":"Clear hidden emails",children:t.jsx(N,{className:"h-3.5 w-3.5"})})]}),Ze.size>0&&t.jsxs("p",{className:"px-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:["Hiding ",Ze.size," ",1===Ze.size?"email":"emails",Ye>0?` · ${Ye} ${1===Ye?"request":"requests"}`:""]})]})]})]}),0===bt.length&&t.jsxs("div",{className:"rounded-2xl border border-foreground
1/5 bg-background/40 py-10 text-center text-muted-foreground",children:[t.jsx("div",{className:"mx-auto mb-3 flex h-10 w-10 items-center justify-center rounded-2xl bg-muted",children:"error"===te?t.jsx(S,{className:"h-5 w-5 text-green-500"}):"processing"===te||"queued"===te?t.jsx(y,{className:"h-5 w-5 text-blue-500"}):t.jsx(q,{className:"h-5 w-5"})}),t.jsx("p",{className:"text-xs font-bold text-foreground",children:Ze.size>0&&0===st.length?"All requests are hidden by the temporary email filter.":gt?`No ${"all"===te?"":Nt} ${at.toLowerCase()} requests match "${se.trim()}".`:"all"===te?`No ${at.toLowerCase()} requests.`:`No ${Nt} ${at.toLowerCase()} requests.`}),t.jsx("p",{className:"mx-auto mt-1 max-w-sm text-[11px] font-medium",children:"queued"===te||"processing"===te?"Live imports will appear here as soon as a request is queued or running.":"pending"===te?"Ready requests will show here, oldest-first if that sort is enabled.":"Try another tab or clear the platform/search/hide filters."})]}),vt.map(e=>{Z[e.user_id];const s=e.target_board_name||(e.target_board_id?`Board ${String(e.target_board_id).slice(0,8)}`:null),a=e.platform?e.platform.charAt(0).toUpperCase()+e.platform.slice(1):"Pinterest",n=(o=e.platform||"pinterest",R[null==o?void 0:o.toLowerCase()]||"#9b87f5");var o;const l=(e=>"completed"===e.status?{emailAt:e.completed_emailed_at,notifAt:e.completed_notified_at}:"error"===e.status||"unavailable"===e.status?{emailAt:e.error_emailed_at,notifAt:e.error_notified_at}:{emailAt:null,notifAt:null})(e),d=!!fe[e.id],u=nt(e),c=ot(e),m=Number(e.import_total_count||0),p=Number(e.import_fetched_count||0),g=Number(e.import_imported_count||0),b=Number(e.import_skipped_count||0),w=String(e.import_error_code||"").trim(),_=e.import_state&&"object"==typeof e.import_state?e.import_state:{},k=String(_.phase||("completed"===e.status?"complete":"error"===e.status||"unavailable"===e.status?e.status:"pending")),q=Number(_.accessibleFetched||p||0),I=Number(_.reportedTotal||m||0),A="completed"===e.status&&I>0&&q>0&&q<I,F=A?`${q} accessible / ${I} reported`:m>0?`${Math.min(p,m)}/${m}`:`${p} fetched`,L=(e=>"completed"===e.status&&"duplicate-skipped"===it(e).phase)(e),T=Number(_.sectionsCreated||0),D=Number(_.sectionAssignments||0),E=m>0?Math.min("completed"===e.status?100:98,Math.round(p/m*100)):"processing"===e.status||d?8:0,z=d||c||!!e.import_started_at,O="completed"===e.status?"green":"error"===e.status||"unavailable"===e.status?"red":"blue",B=e.import_last_heartbeat_at?new Date(e.import_last_heartbeat_at).getTime():0,Q="processing"===e.status&&B>0&&Date.now()-B>3e5,J="pinterest"===String(e.platform||"pinterest").toLowerCase()&&"completed"!==e.status&&"processing"!==e.status&&!c&&!d,V="pinterest"===String(e.platform||"pinterest").toLowerCase()&&"processing"===e.status&&Q&&!d,G=Pe[e.id]||[],W=Ce===e.id,K=l.emailAt?`Email ${j(new Date(l.emailAt),"MMM dd, HH:mm")}`:"Email not sent",X=l.notifAt?`Notification ${j(new Date(l.notifAt),"MMM dd, HH:mm")}`:"Notification not sent",Y=(()=>{try{return new URL(e.board_url).hostname.replace(/^www\./,"")}catch{return"Invalid URL"}})(),ee=("error"===e.status||"unavailable"===e.status)&&/(private|access|permission|unavailable|not found|empty|no pins)/i.test(`${e.error_reason||""} ${w}`),te="completed"===e.status||"error"===e.status||"unavailable"===e.status||"processing"===e.status||c||u?ft(e):new Date(e.created_at||0).getTime(),re=te>0?new Date(te):new Date(e.created_at),se=kt(re.toISOString()),ae="pending"===e.status&&!c&&new Date(e.created_at).getTime()<Date.now()-864e5,ie="completed"===e.status?"Completed":"error"===e.status?"Failed":"unavailable"===e.status?"Reviewed":"processing"===e.status?"Active":u?"Retry due":c?"Queued":"",ne=d?"Starting":u?"Retry now":c?"Queued":V?"Resume":"Start import";return t.jsx("div",{className:"rounded-2xl border overflow-hidden "+("error"===e.status?"border-red-500/15 bg-red-500/[0.03]":u?"border-violet-500/15 bg-violet-500/[0.03]":c||"processing"===e.status?"border-blue-500/15 bg-blue-500/[0.03]":ae?"border-amber-500/15 bg-amber-500/[0.03]":"border-foreground
1/5 bg-muted/20"),children:t.jsxs("div",{className:"p-5 space-y-4",children:[t.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-start lg:justify-between",children:[t.jsxs("div",{className:"min-w-0 space-y-1",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider",style:{backgroundColor:n+"18",color:n},children:a}),t.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold uppercase tracking-wider "+(u?"bg-violet-500/10 text-violet-500":c?"bg-blue-500/10 text-blue-500":"pending"===e.status?"bg-amber-500/10 text-amber-500":"completed"===e.status?"bg-green-500/10 text-green-500":"processing"===e.status?"bg-blue-500/10 text-blue-500":"error"===e.status?"bg-red-500/10 text-red-500":"unavailable"===e.status?"bg-slate-500/10 text-slate-500":"bg-muted text-muted-foreground"),children:u?"retry later":c?"queued":e.status}),t.jsxs("span",{className:"text-[10px] font-bold text-muted-foreground/60 uppercase tracking-widest",children:[ie?`${ie} `:"",j(re,"MMM dd, HH:mm")]}),se&&t.jsxs("span",{className:"rounded-full px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider "+(ae?"bg-amber-500/10 text-amber-500":"bg-muted text-muted-foreground"),children:[se," old"]})]}),t.jsx("h4",{className:"text-sm font-bold text-foreground",children:e.user_email||"Unknown User"}),t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:[t.jsx("span",{children:s||"Unsorted"}),t.jsx("span",{children:Y}),e.import_queued_at&&t.jsxs("span",{children:["Queued ",j(new Date(e.import_queued_at),"MMM dd, HH:mm")]}),u&&e.next_retry_at&&t.jsxs("span",{children:["Retry ",j(new Date(e.next_retry_at),"MMM dd, HH:mm")]})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0",children:[t.jsxs(i,{size:"sm",variant:J||V?"default":"outline",disabled:!J&&!V,onClick:()=>Qe(e),className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",title:u?"Retry this temporarily unavailable board now":c?"This request is already queued":V?"Re-queue the next import chunk":"Fetch public Pinterest pins and import them",children:[d?t.jsx(h,{className:"w-3.5 h-3.5 animate-spin"}):V?t.jsx(f,{className:"w-3.5 h-3.5"}):t.jsx(v,{className:"w-3.5 h-3.5"}),ne]}),"completed"===e.status&&e.target_board_id&&t.jsx(i,{size:"sm",variant:"default",asChild:!0,className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:t.jsxs(C,{to:`/admin/boards/${e.target_board_id}`,children:[t.jsx($,{className:"h-3.5 w-3.5"}),"Echo board"]})}),e.board_url&&t.jsx(i,{size:"sm",variant:"outline",asChild:!0,className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:t.jsxs("a",{href:e.board_url,target:"_blank",rel:"noopener noreferrer",title:"Open the original Pinterest board. Pinterest may redirect this page by browser/session even when Ec
1ho imported it successfully.",children:[t.jsx(P,{className:"h-3.5 w-3.5"}),"Pinterest"]})}),(e.import_started_at||e.import_queued_at||e.import_progress_message||"error"===e.status||G.length>0)&&t.jsxs(i,{size:"sm",variant:"outline",onClick:()=>Ke(e.id),className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:[t.jsx(y,{className:"h-3.5 w-3.5"}),"Events",G.length>0&&t.jsx("span",{className:"rounded-full bg-foreground/10 px-1.5 py-0.5 text-[9px]",children:G.length})]}),c&&t.jsx(i,{size:"sm",variant:"ghost",disabled:!!Ne[e.id],onClick:()=>Ge(e.id),className:"h-9 w-9 p-0 rounded-xl text-muted-foreground hover:text-red-500 hover:bg-red-500/10",title:"Remove from queue",children:Ne[e.id]?t.jsx(h,{className:"w-4 h-4 animate-spin"}):t.jsx(N,{className:"w-4 h-4"})}),"error"===e.status&&t.jsxs(i,{size:"sm",variant:"outline",disabled:pe===e.id,onClick:()=>Be(e.id,!0),className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:[pe===e.id?t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}):t.jsx(S,{className:"h-3.5 w-3.5"}),"Mark reviewed"]}),"unavailable"===e.status&&t.jsxs(i,{size:"sm",variant:"outline",disabled:pe===e.id,onClick:()=>Be(e.id,!1),className:"h-9 rounded-xl px-3 text-[11px] font-bold gap-1.5",children:[pe===e.id&&t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}),"Return to Failed"]}),t.jsx(i,{size:"sm",variant:"ghost",disabled:ce===e.id,onClick:()=>(async e=>{me(e);try{const{error:t}=await r.rpc("admin_delete_import_request",{p_request_id:e});if(t)throw t;H(t=>t.filter(t=>t.id!==e)),Le({title:"Request deleted"})}catch(t){Le({title:"Delete failed",description:t.message,variant:"error"})}finally{me(null)}})(e.id),className:"h-9 w-9 p-0 rounded-xl text-muted-foreground hover:text-red-500 hover:bg-red-500/10",children:ce===e.id?t.jsx(h,{className:"w-4 h-4 animate-spin"}):t.jsx(M,{className:"w-4 h-4"})})]})]}),("error"===e.status||"unavailable"===e.status)&&t.jsxs("div",{className:x("p-3 rounded-xl border","error"===e.status?"bg-red-500/5 border-red-500/10":"bg-slate-500/5 border-slate-500/10"),children:[t.jsxs("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[t.jsx("p",{className:x("text-[10px] font-bold uppercase tracking-widest","error"===e.status?"text-red-500":"text-slate-500"),children:"error"===e.status?"Error reason":"Reviewed failure"}),w&&t.jsx("span",{className:"rounded-full bg-red-500/10 px-2 py-0.5 font-mono text-[10px] font-bold text-red-500",children:w})]}),t.jsx("p",{className:"text-xs text-foreground",children:Ee(e.error_reason||"No reason added yet.")}),ee&&t.jsxs("div",{className:"mt-2 rounded-lg border border-red-500/10 bg-background/50 p-2 text-[11px] font-medium text-muted-foreground",children:["Likely private, unavailable, or empty Pinterest board. ",U]})]}),z&&t.jsxs("div",{className:"rounded-xl border p-3 "+("green"===O?"border-green-500/10 bg-green-500/5":"red"===O?"border-red-500/10 bg-red-500/5":"border-blue-500/10 bg-blue-500/5"),children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest "+("green"===O?"text-green-500":"red"===O?"text-red-500":"text-blue-500"),children:L?"Already imported":A?"Import complete · accessible pins":"completed"===e.status?"Import complete":"error"===e.status?"Import failed":u?"Pinterest retry scheduled":"Auto importing pins"}),t.jsx("p",{className:"text-[10px] font-bold "+("green"===O?"text-green-500":"red"===O?"text-red-500":"text-blue-500"),children:F})]}),t.jsx("div",{role:"progressbar","aria-label":"Pinterest import progress","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":"completed"===e.status?100:E,className:"h-2 overflow-hidden rounded-full "+("green"===O?"bg-green-500/10":"red"===O?"bg-red-500/10":"bg-blue-500/10"),children:t.jsx("div",{className:"h-full rounded-full transition-all duration-500 "+("green"===O?"bg-green-500":"red"===O?"bg-red-500":"bg-blue-500"),style:{width:`${"completed"===e.status?100:E}%`}})}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center justify-between gap-2 text-[10px] font-bold "+("green"===O?"text-green-500/80":"red"===O?"text-red-500/80":"text-blue-500/80"),children:[t.jsx("span",{children:Ee(e.import_progress_message||"Fetching Pinterest board...")}),t.jsx("span",{children:L?"No new echoes added":`${g} imported${b?` · ${b} skipped`:""}`})]}),A&&t.jsx("p",{className:"mt-2 text-[10px] font-bold "+("green"===O?"text-green-500/70":"text-blue-500/70"),children:"Pinterest reported more total pins than its public import endpoints exposed. Echo imported the accessible pins."}),t.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-[10px] font-bold "+("green"===O?"text-green-500/70":"red"===O?"text-red-500/70":"text-blue-500/70"),children:[t.jsxs("span",{children:["Phase ",k]}),e.import_attempt_count?t.jsxs("span",{children:[e.import_attempt_count," chunks"]}):null,T?t.jsxs("span",{children:[T," sections created"]}):null,D?t.jsxs("span",{children:[D," section assignments"]}):null,w?t.jsx("span",{className:"font-mono",children:w}):null,e.import_last_heartbeat_at?t.jsxs("span",{children:["Heartbeat ",j(new Date(e.import_last_heartbeat_at),"MMM dd, HH:mm:ss")]}):null,Q?t.jsx("span",{className:"text-amber-500",children:"Stale heartbeat"}):null]})]}),(e.import_started_at||e.import_queued_at||e.import_progress_message||"error"===e.status||d||c||G.length>0)&&t.jsxs("div",{className:"rounded-xl border border-foreground
1/5 bg-background/40",children:[t.jsxs("button",{type:"button",onClick:()=>Ke(e.id),className:"flex w-full items-center justify-between gap-3 px-3 py-2 text-left",children:[t.jsxs("span",{className:"flex items-center gap-2 text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:[t.jsx(y,{className:"h-3.5 w-3.5"}),"Import events",G.length>0&&t.jsx("span",{className:"rounded-full bg-muted px-2 py-0.5 text-[9px] text-muted-foreground",children:G.length})]}),t.jsx("span",{className:"text-[10px] font-bold text-muted-foreground",children:Ie===e.id&&0===G.length?"Loading...":W?"Hide":"Show"})]}),W&&t.jsx("div",{className:"border-t border-foreground/5 p-3",children:Ie===e.id&&0===G.length?t.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[t.jsx(h,{className:"h-3.5 w-3.5 animate-spin"}),"Loading events..."]}):0===G.length?t.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"No events loaded yet. If this was just queued, the first importer event should appear after the next refresh."}):t.jsx("div",{className:"max-h-64 space-y-2 overflow-y-auto pr-1",children:G.map(e=>{const r=e.details&&Object.keys(e.details).length>0?JSON.stringify(e.details):"";return t.jsxs("div",{className:"rounded-lg bg-muted/30 p-2",children:[t.jsxs("div",{className:"flex items-start justify-between gap-3",children:[t.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest "+("error"===e.level?"text-red-500":"warning"===e.level?"text-amber-500":"text-muted-foreground"),children:e.error_code||e.phase||e.level}),t.jsx("p",{className:"shrink-0 text-[10px] font-bold text-muted-foreground/70",children:j(new Date(e.created_at),"MMM dd, HH:mm:ss")})]}),t.jsx("p",{className:"mt-1 text-xs font-medium text-foreground",children:e.message}),r&&t.jsx("p",{className:"mt-1 break-all font-mono text-[10px] text-muted-foreground",children:r.length>420?`${r.slice(0,420)}...`:r})]},e.id)})})})]}),t.jsxs("div",{className:"p-3 rounded-xl bg-background/50 border border-foreground
1/5 space-y-3",children:[t.jsx("div",{className:"flex items-center justify-between gap-4",children:t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mb-1",children:"Target Board"}),s?t.jsx("p",{className:"text-xs font-bold text-foreground truncate",children:s}):t.jsx("p",{className:"text-xs font-bold text-foreground",children:"Unsorted"})]})}),t.jsxs("div",{className:"pt-2 border-t border-foreground/5",children:[t.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-widest mb-1",children:"Source URL"}),t.jsx("a",{href:e.board_url,target:"_blank",rel:"noopener noreferrer",title:"Open the original Pinterest board. Pinterest may redirect this page by browser/session even when Echo imported it successfully.",className:"text-[11px] text-primary hover:underline block truncate font-bold",children:e.board_url})]})]}),["completed","error","unavailable"].includes(e.status)&&t.jsxs("div",{className:"p-3 rounded-xl bg-background/50 border border-foreground
1/5 flex flex-wrap items-center gap-2",children:[t.jsx("span",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:"Automated update"}),t.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold "+(l.notifAt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:X}),t.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold "+(l.emailAt?"bg-green-500/10 text-green-600":"bg-amber-500/10 text-amber-600"),children:K})]})]})},e.id)}),wt>1&&t.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-foreground/5",children:[t.jsxs("p",{className:"text-[11px] text-muted-foreground font-bold",children:[bt.length," requests · Page ",jt," of ",wt]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(i,{size:"sm",variant:"outline",disabled:jt<=1,onClick:()=>he(e=>Math.max(1,e-1)),className:"h-8 px-3 rounded-xl text-[11px] font-bold",children:"Previous"}),t.jsx(i,{size:"sm",variant:"outline",disabled:jt>=wt,onClick:()=>he(e=>Math.min(wt,e+1)),className:"h-8 px-3 rounded-xl text-[11px] font-bold",children:"Next"})]})]})]})}export{D as AdminPinterestRequestsPanel};

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.