1import{r as e,j as t}from"./vendor-react-C9yDzYQD.js";import{B as s}from"./BoardPreviewAvatar-6XMyttho.js";import{I as n}from"./input-CJADGzyX.js";import{a as r}from"./runtime-utils-GN4cODRt.js";import{c as a,n as i}from"./boardViewSettings-CdKftBZg.js";import{supabase as o}from"./supabase-client-_h80EYw_.js";import{D as d,f as l,a as c,b as m,c as u,d as p}from"./dialog-DHNNRuDw.js";import{S as h}from"./search-D7ByVMw5.js";import{C as f}from"./chevron-down-BFi_I8Zn.js";const b=e=>{const t=new Map,s=new Map,n=(e,n)=>{if(!n)return;const r=t.get(e)||[];if(r.length>=12)return;const a=s.get(e)||new Set;a.has(n)||(a.add(n),s.set(e,a),r.push(n),t.set(e,r))};return Object.entries(e.canvasSectionOrders).forEach(([e,t])=>{t.forEach(t=>n(e,t))}),Object.entries(e.canvasAssignments).forEach(([e,t])=>{n(t,e)}),t},x=({open:x,onOpenChange:g,boards:v,onMove:w,trigger:j,title:y="Move to Board",description:N="Select a board to move the selected echoes to.",emptyMessage:S="No editable boards available.",disabled:I=!1,requireConfirmation:k=!1})=>{const[C,M]=e.useState(null),[E,_]=e.useState(()=>new Set),[O,T]=e.useState(""),[$,L]=e.useState({}),[B,H]=e.useState(null),[z,A]=e.useState(!1),P=e.useRef(!1),D=e.useRef(null);e.useEffect(()=>{x||(M(null),_(new Set),T(""),H(null))},[x]);const F=async(e,t)=>{if(!I&&!P.current){P.current=!0,A(!0);try{await w(e,t)}finally{P.current=!1,A(!1)}}},R=async(e,t)=>{k?H(((e,t)=>({boardId:e.id,boardName:e.name,sectionId:(null==t?void 0:t.id)??null,sectionName:(null==t?void 0:t.title)??null}))(e,t)):await F(e.id,(null==t?void 0:t.id)??null)};e.useEffect(()=>{if(!x||0===v.length)return;const e=v.filter(e=>void 0===e.view_config&&!(e.id in $)).map(e=>e.id);if(0===e.length)return;let t=!1;return o.from("boards").select("id, view_config").in("id",e).then(({data:s,error:n})=>{t||n||L(t=>{const n={...t};return(s||[]).forEach(e=>{n[e.id]=e.view_config??null}),e.forEach(e=>{e in n||(n[e]=null)}),n})}),()=>{t=!0}},[v,$,x]);const q=O.trim().toLowerCase(),K=e.useMemo(()=>v.map(e=>{const t=a(e.id),s=t.canvasSections.length>0?t:i(e.view_config??$[e.id]),n=s.canvasSections,r=(e=>{const t=new Map(e.map(e=>[e.id,e])),s=new Map,n=(e,r=new Set)=>{const a=s.get(e);if(a)return a;const i=t.get(e);if(!i||r.has(e))return(null==i?void 0:i.title)||"";r.add(e);const o=i.parentId?n(i.parentId,r):"",d=o?`${o} / ${i.title}`:i.title;return s.set(e,d),d};return e.forEach(e=>n(e.id)),s})(n);return{board:e,viewConfig:s,sections:n,boardSearchText:e.name.toLowerCase(),sectionSearchText:new Map(n.map(e=>[e.id,`${e.title} ${r.get(e.id)||""}`.toLowerCase()])),sectionPreviewIds:b(s)}}),[v,$]),V=e.useMemo(()=>K.flatMap(e=>{const t=!q||e.boardSearchText.includes(q),s=new Set;return q&&e.sectionSearchText.forEach((e,t)=>{e.includes(q)&&s.add(t)}),t||s.size>0?[{...e,boardMatches:t,matchingSectionIds:s}]:[]}),[q,K]);return t.jsxs(d,{open:x,onOpenChange:e=>{var t;if(!e){const e=document.activeElement;e instanceof HTMLElement&&(null==(t=D.current)?void 0:t.contains(e))&&e.blur()}g(e)},children:[j?t.jsx(l,{asChild:!0,children:j}):null,t.jsxs(c,{ref:D,overlayClassName:"bg-black/35 backdrop-blur-sm",className:"bg-background !border-0 rounded-[2.5rem] p-8 max-w-md w-[calc(100vw-2rem)] overflow-hidden",onOpenAutoFocus:e=>e.preventDefault(),children:[t.jsxs(m,{children:[t.jsx(u,{className:"text-2xl font-bold tracking-tight",children:y}),t.jsx(p,{className:"sr-only",children:N})]}),B?t.jsxs("div",{className:"mt-4 rounded-3xl border border-primary/20 bg-primary/5 p-5","data-confirm-board-id":B.boardId,children:[t.jsx("p",{className:"text-xs font-bold uppercase tracking-widest text-primary/60",children:"Confirm destination"}),t.jsx("p",{className:"mt-2 text-lg font-bold",children:B.boardName}),B.sectionName?t.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Section: ",B.sectionName]}):null,t.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:"The selected echoes will leave the current board and move here."}),t.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[t.jsx("button",{type:"button",onClick:()=>H(null),disabled:I||z,className:"h-10 rounded-xl px-4 text-sm font-semibold hover:bg-muted disabled:opacity-60",children:"Back"}),t.jsx("button",{type:"button",onClick:()=>{(async()=>
1{if(!B||P.current)return;const e=((e,t)=>{const s=e.find(e=>e.id===t.boardId);return s&&s.name===t.boardName?s:null})(v,B);if(e){if(B.sectionId){const t=a(e.id),s=(t.canvasSections.length>0?t:i(e.view_config??$[e.id])).canvasSections.find(e=>e.id===B.sectionId);if(!s||s.title!==B.sectionName)return void H(null)}await F(e.id,B.sectionId)}else H(null)})()},disabled:I||z,className:"h-10 rounded-xl bg-primary px-5 text-sm font-bold text-primary-foreground hover:bg-primary/90 disabled:opacity-60",children:z?"Movingâ¦":"Move here"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"relative mt-4",children:[t.jsx(h,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t.jsx(n,{value:O,onChange:e=>{T(e.target.value),_(new Set)},placeholder:"Search boards or sections",enterKeyHint:"search",autoCapitalize:"none",autoCorrect:"off",spellCheck:!1,disabled:I||0===v.length,className:"h-12 rounded-2xl border-0 bg-muted/30 pl-11 pr-4 text-sm font-semibold focus-visible:ring-1 focus-visible:ring-primary/25 focus-visible:ring-offset-0"})]}),t.jsx("div",{className:"grid grid-cols-1 gap-3 mt-4 max-h-[50vh] overflow-y-auto custom-scrollbar p-1",children:0===v.length?t.jsx("div",{className:"p-4 rounded-3xl bg-muted/20 text-sm text-muted-foreground",children:S}):0===V.length?t.jsx("div",{className:"p-4 rounded-3xl bg-muted/20 text-sm text-muted-foreground",children:"No boards or sections match that search."}):V.map(({board:e,sections:n,boardMatches:a,matchingSectionIds:i,sectionPreviewIds:o})=>{var d,l;const c=q.length>0,m=c?n.length>0&&(a||i.size>0)&&!E.has(e.id):C===e.id,u=c&&!a?n.filter(e=>i.has(e.id)):n;return t.jsxs("div",{className:"rounded-3xl bg-muted/30 border border-border/5 overflow-hidden",children:[t.jsxs("div",{className:"flex items-stretch group",children:[t.jsxs("button",{type:"button",onClick:()=>{R(e,null)},disabled:I||z,className:"flex flex-1 min-w-0 items-center gap-4 p-4 text-left hover:bg-primary/10 active:bg-primary/10 transition-colors disabled:opacity-60 disabled:pointer-events-none",children:[t.jsx("div",{className:"w-12 h-12 rounded-full overflow-hidden glass flex items-center justify-center text-xl shadow-soft group-hover:scale-105 group-active:scale-95 transition-transform shrink-0",children:t.jsx(s,{boardId:e.id,previewIds:(null==(d=e.preview_image_ids)?void 0:d.length)?e.preview_image_ids:void 0,previewMedia:(null==(l=e.preview_media)?void 0:l.length)?e.preview_media:void 0,fallbackIcon:e.icon})}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-bold text-lg truncate",children:e.name}),t.jsxs("p",{className:"text-[10px] font-bold text-primary/40 uppercase tracking-widest",children:[e.memory_count||0," Echoes"]})]})]}),n.length>0&&t.jsxs("button",{type:"button",onClick:()=>{c?_(t=>{const s=new Set(t);return m?s.add(e.id):s.delete(e.id),s}):M(m?null:e.id)},disabled:I||z,className:"shrink-0 flex items-center justify-center gap-1.5 px-4 text-[10px] font-bold uppercase tracking-widest text-primary/50 hover:text-primary hover:bg-primary/10 transition-colors disabled:opacity-60","aria-label":`${m?"Hide":"Show"} ${e.name} sections`,children:["Sections",t.jsx(f,{className:r("w-4 h-4 transition-transform",m&&"rotate-180")})]})]}),u.length>0&&m&&t.jsx("div",{className:"px-4 pb-4 pt-1 grid grid-cols-1 gap-2",children:u.map(n=>t.jsxs("button",{type:"button",onClick:()=>{R(e,n)},disabled:I||z,className:"flex items-center gap-3 rounded-2xl bg-background/40 px-4 py-3 text-left hover:bg-primary/10 active:bg-primary/10 transition-colors disabled:opacity-60 disabled:pointer-events-none",children:[t.jsx("span",{className:"h-9 w-9 rounded-full overflow-hidden glass flex items-center justify-center shrink-0",children:t.jsx(s,{boardId:e.id,previewIds:o.get(n.id),fallbackIcon:e.icon,maxItems:1})}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-bold",children:n.title})]},n.id))})]},e.id)})})]})]})]})};export{x as MoveToBoardDialog};
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.