1import{r as o,j as e,m as F,A as lt}from"./motion-BCivUG58.js";import{cE as ko,a4 as dr,i as ne,b as O,c0 as No,bN as Is,a0 as Ue,C as vt,X as Kr,a as be,G as Gr,bX as sr,$ as _t,a3 as Sr,bY as Co,V as Bt,L as Et,x as So,bd as Io,be as ys,t as ja,B as st,a2 as ar,bl as at,bL as wr,ap as hs,bO as Po,c as Xe,at as or,bc as pt,A as ir,bQ as Mo,bW as wa,N as Jt,ax as ka,ar as Ps,J as Zt,bK as Ms,bJ as Ts,bG as To,cF as Rs,cG as Es,f as zt,as as ft,bT as Na,bU as Ca,ba as Ro,bu as Eo,cH as _o,cI as zo,P as Do,bE as Ao,j as $o,bz as Uo,by as Lo,bB as Fo,bD as _s,bA as zs}from"./main-D6o_kCL1.js";import{o as Ds}from"./call-flow-store-z2wbJBqa.js";import{a as Oo,M as Bo,C as bs,F as Ko,b as Sa}from"./memory-project-labels-ClRv0Lpu.js";import{t as Go}from"./plans-modal-utils-CihfM_aF.js";import{P as vr}from"./pencil-DcFD-omG.js";import{B as Ia,S as qo}from"./shield-B9NQvJpA.js";import{T as gt}from"./trash-2-D2M4kTkq.js";import{L as Pa}from"./log-out-BBf1gwmq.js";import{S as Ma}from"./settings-BcJhvECu.js";import{u as Wo}from"./use-debounced-value-Ds5L36FN.js";import{C as ss}from"./circle-alert-DCbjf8vg.js";import{L as as}from"./link-2-CL5tjSEZ.js";import{X as fe}from"./x-NZpd45E0.js";import{S as $r}from"./search-bYqCEHav.js";import{F as Vo,b as Ho,a as Yo,C as Qo,E as Jo}from"./FileViewer-BYRnfNWR.js";import{C as Xo}from"./chevron-left-BWlwywiZ.js";import{S as Zo}from"./send-B4uRoRB6.js";import{C as ei}from"./copy-C-trlee0.js";import{p as ti}from"./page-destination-BYO754WP.js";import{P as As,T as Ir,F as ri,S as si,C as ai}from"./PageCard-4w_S0ZnC.js";import{U as br}from"./upload-B78ObAeJ.js";import{C as cr}from"./circle-check-DIGzc0-2.js";import{E as os}from"./EmptyState-cTohUctQ.js";import{u as fs,g as oi}from"./collection-store-BBUpZC4l.js";import{e as Ta,u as Ra,a as Ur,D as Ea,c as _a,b as za,v as Da,d as ii,C as ni,B as li,s as Aa,K as $a,P as Ua,S as di,f as ci,g as mi}from"./BookPreviewModal-BZZiFHCE.js";import{E as $s}from"./constants-Dym7XrD0.js";import{F as mr}from"./folder-open-CvjPbHQy.js";import{F as qr}from"./folder-plus-BxNC9qL1.js";import{E as ui}from"./eye-off-qb65RKhs.js";import{Q as is}from"./quote-CCopuVla.js";import{G as La}from"./grip-vertical-CqB38Eg5.js";import{M as kr}from"./message-circle-uGtiFQAc.js";import{C as Fa}from"./chevron-up-BK9uICKE.js";import{F as nr}from"./film-gCrrshdf.js";import{a as ns}from"./minimize-2-BNZh9RzS.js";import{I as Lr}from"./image-plus-zVv2_769.js";import{E as xi}from"./external-link-D9qB1w80.js";import{L as Us}from"./lock-C3CXnIW5.js";import{C as Ls}from"./credit-card-Di_E2wfK.js";import"./observability-BKSdqxbK.js";import"./skip-forward-BycsPHQ7.js";import"./analytics-payload-C1ZM-KMC.js";import"./download-Cvcv65sY.js";function pi(t,r){if(t===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in t)return t;if(typeof t=="function")return{shouldBlockFn:async()=>await t(),enableBeforeUnload:!0,withResolver:!1};const s=!!(t.condition??!0),a=t.blockerFn;return{shouldBlockFn:async()=>s&&a!==void 0?await a():s,enableBeforeUnload:s,withResolver:a===void 0}}function gi(t,r){const{shouldBlockFn:s,enableBeforeUnload:a=!0,disabled:i=!1,withResolver:l=!1}=pi(t),d=ko(),{history:m}=d,[p,f]=o.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return o.useEffect(()=>{const j=async y=>{function b(N){const P=d.parseLocation(N),w=d.getMatchedRoutes(P.pathname);return w.foundRoute===void 0?{routeId:"__notFound__",fullPath:P.pathname,pathname:P.pathname,params:w.routeParams,search:d.options.parseSearch(N.search)}:{routeId:w.foundRoute.id,fullPath:w.foundRoute.fullPath,pathname:P.pathname,params:w.routeParams,search:d.options.parseSearch(N.search)}}const g=b(y.currentLocation),h=b(y.nextLocation);if(g.routeId==="__notFound__"&&h.routeId!=="__notFound__")return!1;const x=await s({action:y.action,current:g,next:h});if(!l)return x;if(!x)return!1;const k=await new Promise(N=>{f({status:"blocked",current:g,next:h,action:y.action,proceed:()=>N(!1),reset:()=>N(!0)})});return f({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),k};return i?void 0:m.block({blockerFn:j,enableBeforeUnload:a})},[s,a,i,l,m,d]),p}const yi=[["path",{d:"M21 21H8a2 2 0 0 1-1.42-.587l-3.994-3.999a2 2 0 0 1 0-2.828l10-10a2 2 0 0 1 2.829 0l5.999 6a2 2 0 0 1 0 2.828L12.834 21",key:"g5wo59"}],["path",{d:"m5.082 11.09 8.828 8.828",key:"1wx5vj"}]],hi=dr("eraser",yi);const bi=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["circle",{cx:"10",cy:"12",r:"2",key:"737tya"}],["path",{d:"m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22",key:"wt3hpn"}]],fi=dr("file-image",bi);const vi=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M15.033 13.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56v-4.704a.645.645 0 0 1 .967-.56z",key:"1tzo1f"}]],ji=dr("file-play",vi);const wi=[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M20 11v8a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-8",key:"1sqzm4"}],["path",{d:"M7.5 7a1 1 0 0 1 0-5A4.8 8 0 0 1 12 7a4.8 8 0 0 1 4.5-5 1 1 0 0 1 0 5",key:"kc0143"}],["rect",{x:"3",y:"7",width:"18",height:"4",rx:"1",key:"1hberx"}]],ki=dr("gift",wi);const Ni=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],Ci=dr("info",Ni);const Si=[["path",{d:"M13 21h8",key:"1jsn5i"}],["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]],Ii=dr("pen-line",Si),Pi=[{label:"Family",emojis:["â¤ï¸","ð","ð¨âð©âð§âð¦","ðµ","ð´","ð ","ð«","ð¶","ð","ð¤"]},{label:"Memories",emojis:["ð¸","ð¥","ð","â¨","ð","ð«","ð°ï¸","ð","ð","ðª"]},{label:"Places",emojis:["ð","ðï¸","ð","ðï¸","ð³","ðº","ðï¸","âª","ð
","ðºï¸"]},{label:"Celebrations",emojis:["ð","ð","ð","ð¥","ð","ð","ð","ð","ð","ð"]},{label:"Nature",emojis:["ð¿","ð","ð»","ð¦","ð¦","ð","âï¸","ð","â","ð"]},{label:"Activities",emojis:["ðµ","ð¨","ð","ð³","â½","ð","âï¸","ð£","ðï¸","ð¹"]}],Mi={heart:"â¤ï¸",star:"â",users:"ð¥"},Ti="https://images.unsplash.com/photo-1519741497674-611481863552?w=1600&h=700&fit=crop",Fs=224,Os=16;function Ri({group:t,coverPreview:r,coverUploading:s,coverInputRef:a,handleCoverUpload:i,currentEmoji:l,currentName:d,isEditingName:m,editName:p,setEditName:f,editEmoji:j,setEditEmoji:y,showEmojiPicker:b,setShowEmojiPicker:g,emojiPickerRef:h,startEditing:x,cancelEditing:S,saveEditing:k,acceptedMembers:N,pendingMembersFromBackend:P,isOwner:w,notificationsOn:U,onToggleNotifications:q,onDeleteGroup:K,onLeaveGroup:Z,memoryProjectHeader:E}){const B=r||t.coverImageUrl,le=ne(O.groups.update),[$,X]=o.useState(!1),[G,ae]=o.useState(null),[ee,Q]=o.use
1State(null),[M,_]=o.useState(null),T=o.useRef(null),z=o.useRef(null),C=o.useRef([]),L=o.useRef(null),H=o.useRef(!1),v="group-settings-menu",D="group-settings-trigger",se=o.useCallback(()=>{const oe=T.current;if(!oe||typeof window>"u")return;const te=oe.getBoundingClientRect(),re=window.innerWidth-Fs-Os;_({top:te.bottom+8,left:Math.max(Os,Math.min(te.right-Fs,re))})},[]),de=o.useCallback((oe=!1)=>{X(!1),ae(null),Q(null),_(null),H.current=!1,oe&&window.requestAnimationFrame(()=>{T.current?.focus()})},[]),ze=U??!0,ke=o.useCallback(()=>Array.from(z.current?.querySelectorAll("button:not(:disabled)")??[]),[]);o.useEffect(()=>{if(!$)return;se(),H.current&&(H.current=!1,ke()[0]?.focus());function oe(Ce){T.current?.contains(Ce.target)||z.current&&!z.current.contains(Ce.target)&&de()}function te(Ce){if(Ce.key==="Escape"){de(!0);return}if(Ce.key!=="ArrowDown"&&Ce.key!=="ArrowUp"||!z.current?.contains(document.activeElement))return;const c=ke();if(c.length===0)return;Ce.preventDefault();const Y=c.indexOf(document.activeElement),ie=Ce.key==="ArrowDown"?1:-1,ue=Y===-1?0:(Y+ie+c.length)%c.length;c[ue]?.focus()}function re(Ce){const he=Ce.target,c=z.current,Y=T.current,ie=!!c&&c.contains(he),ue=!!Y&&Y.contains(he);if(!ie&&!ue)return;const Se=Ce.relatedTarget,Ee=!!Se&&!!c&&c.contains(Se),Ke=!!Se&&!!Y&&Y.contains(Se);(!Se||!Ee&&!Ke)&&de()}function me(){se()}return document.addEventListener("pointerdown",oe),document.addEventListener("keydown",te),document.addEventListener("focusout",re,!0),window.addEventListener("resize",me),window.addEventListener("scroll",me,!0),()=>{document.removeEventListener("pointerdown",oe),document.removeEventListener("keydown",te),document.removeEventListener("focusout",re,!0),window.removeEventListener("resize",me),window.removeEventListener("scroll",me,!0)}},[de,ke,$,se]),o.useEffect(()=>{if(!E){L.current=null;return}if(L.current===E.activeTab)return;const oe=E.tabs.findIndex(re=>re.key===E.activeTab),te=C.current[oe];!te||typeof te.scrollIntoView!="function"||(te.scrollIntoView({block:"nearest",inline:"center"}),L.current=E.activeTab)},[E]);const Pe=async(oe,te)=>{if(!ee){Q(oe);try{await te?.(),de()}catch{Q(null)}}},Ne=$&&M&&typeof document<"u"?No.createPortal(e.jsxs(F.div,{ref:z,id:v,initial:{opacity:0,y:4},animate:{opacity:1,y:0},transition:{duration:.15},style:{left:M.left,top:M.top},className:"fixed z-50 w-56 overflow-hidden rounded-xl border border-grey-1 bg-white py-1 shadow-lg dark:border-transparent dark:bg-grey-1",role:"menu","aria-labelledby":D,children:[e.jsx("div",{className:"border-b border-grey-1 px-3 py-2 dark:border-grey-2",role:"presentation",children:e.jsx("p",{className:"text-xs font-semibold text-grey-6",children:"Group settings"})}),w&&e.jsxs("button",{type:"button",onClick:()=>{de(),x()},role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-grey-6 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:hover:bg-grey-2",children:[e.jsx(vr,{size:14,"aria-hidden":"true"}),"Change group name"]}),w&&E&&e.jsxs("button",{type:"button",onClick:()=>{de(!0),a.current?.click()},disabled:s,role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-grey-6 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-70 dark:hover:bg-grey-2",children:[e.jsx(Is,{size:14,"aria-hidden":"true"}),s?"Uploading cover...":B?"Change cover image":"Add cover image"]}),e.jsxs("button",{type:"button",onClick:()=>{q?.()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm text-grey-6 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:hover:bg-grey-2",role:"menuitemcheckbox","aria-checked":ze,children:[e.jsx(Ia,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"flex-1",children:"Notifications"}),e.jsx("span",{className:"text-xs font-medium text-grey-4",children:ze?"On":"Off"})]}),w?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>ae("delete"),role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm font-medium text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-500/10",children:[e.jsx(gt,{size:14,"aria-hidden":"true"}),"Delete group"]}),G==="delete"&&e.jsxs("div",{className:"border-t border-grey-1 px-3 py-3 dark:border-grey-2",children:[e.jsxs("p",{className:"text-xs text-grey-5",children:['Move "',t.name,'" to trash?']}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae(null),disabled:ee==="delete",role:"menuitem",className:"rounded-full bg-grey-1 px-3 py-1 text-xs font-medium text-grey-5 transition-colors hover:bg-grey-2 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-grey-2 dark:hover:bg-grey-3",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>Pe("delete",K),disabled:ee==="delete","aria-busy":ee==="delete",role:"menuitem",className:"rounded-full bg-red-500 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-70",children:ee==="delete"?"Moving...":"Move to trash"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>ae("leave"),role:"menuitem",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-sm font-medium text-red-500 transition-colors hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-500/10",children:[e.jsx(Pa,{size:14,"aria-hidden":"true"}),"Leave group"]}),G==="leave"&&e.jsxs("div",{className:"border-t border-grey-1 px-3 py-3 dark:border-grey-2",children:[e.jsxs("p",{className:"text-xs text-grey-5",children:['Leave "',t.name,'"?']}),e.jsxs("div",{className:"mt-2 flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae(null),disabled:ee==="leave",role:"menuitem",className:"rounded-full bg-grey-1 px-3 py-1 text-xs font-medium text-grey-5 transition-colors hover:bg-grey-2 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-grey-2 dark:hover:bg-grey-3",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>Pe("leave",Z),disabled:ee==="leave","aria-busy":ee==="leave",role:"menuitem",className:"rounded-full bg-red-500 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-70",children:ee==="leave"?"Leaving...":"Leave"})]})]})]})]}),document.body):null,ce=e.jsxs("div",{className:"relative",children:[e.jsx(F.button,{ref:T,id:D,type:"button",whileHover:{scale:1.05},whileTap:{scale:.95},onClick:()=>
1{if($){de();return}se(),H.current=!0,X(!0)},onKeyDown:oe=>{if(oe.key==="ArrowDown"){if(oe.preventDefault(),!$){se(),H.current=!0,X(!0);return}ke()[0]?.focus()}},className:"flex h-9 w-9 items-center justify-center rounded-full border border-grey-1 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-6 dark:border-transparent dark:hover:bg-grey-2","aria-label":"Open group settings menu","aria-haspopup":"menu","aria-expanded":$,"aria-controls":$?v:void 0,children:e.jsx(Ma,{size:16})}),Ne]});if(E){const oe=B||Ti,te=(re,me)=>{const Ce=E.tabs.length-1;let he=null;if(re.key==="ArrowRight"&&(he=me===Ce?0:me+1),re.key==="ArrowLeft"&&(he=me===0?Ce:me-1),re.key==="Home"&&(he=0),re.key==="End"&&(he=Ce),he===null)return;re.preventDefault();const c=E.tabs[he];c&&(E.onTabChange(c.key),window.requestAnimationFrame(()=>{C.current[he]?.focus()}))};return e.jsxs(F.div,{variants:Ue,className:"contents",children:[e.jsx("input",{ref:a,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:re=>{const me=re.target.files?.[0];me&&i(me),re.target.value=""}}),e.jsxs("div",{className:"-mx-4 relative min-h-[240px] rounded-t-none border-t border-grey-2 bg-cover bg-center shadow-sm dark:border-grey-2 sm:mx-0 sm:rounded-t-lg sm:border-x",style:{backgroundImage:`url(${oe})`},children:[e.jsx("div",{className:"absolute inset-0 rounded-t-none bg-[linear-gradient(90deg,rgba(69,61,60,0.78),rgba(69,61,60,0.56)_58%,rgba(69,61,60,0.26)),linear-gradient(0deg,rgba(69,61,60,0.38),rgba(69,61,60,0.08)_56%)] sm:rounded-t-lg dark:bg-[linear-gradient(90deg,rgba(69,61,60,0.92),rgba(69,61,60,0.72)_56%,rgba(69,61,60,0.32)),linear-gradient(0deg,rgba(69,61,60,0.42),rgba(69,61,60,0.12)_56%)]"}),e.jsx("div",{className:"absolute right-4 top-4 z-10 rounded-full bg-white/85 shadow-sm backdrop-blur-sm dark:bg-grey-1/85",children:ce}),e.jsxs("div",{className:"relative flex min-h-[240px] flex-col justify-end p-5 text-white sm:p-8",children:[e.jsx("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:E.chips.map(re=>e.jsx("span",{className:"rounded-md border border-white/25 bg-white/15 px-2.5 py-1 text-xs font-semibold text-white backdrop-blur",children:re},re))}),m?e.jsxs("div",{className:"max-w-3xl",children:[e.jsx("input",{type:"text",value:p,onChange:re=>f(re.target.value),onKeyDown:re=>{re.key==="Enter"&&k(),re.key==="Escape"&&S()},autoFocus:!0,"aria-label":"Group name",className:"w-full border-b-2 border-white/40 bg-transparent font-primary text-4xl leading-tight text-white outline-none placeholder:text-white/50 focus:border-white sm:text-5xl"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs(F.button,{type:"button",whileTap:{scale:.95},onClick:k,className:"inline-flex items-center gap-1.5 rounded-lg bg-white px-3 py-1.5 text-xs font-semibold text-grey-7 shadow-sm transition-colors hover:bg-grey-0",children:[e.jsx(vt,{size:12}),"Save"]}),e.jsx("button",{type:"button",onClick:S,className:"rounded-lg border border-white/25 bg-white/10 px-3 py-1.5 text-xs font-semibold text-white backdrop-blur transition-colors hover:bg-white/20",children:"Cancel"})]})]}):w?e.jsx("h1",{className:"max-w-3xl",children:e.jsx("button",{type:"button",onClick:x,className:"block max-w-full text-left font-primary text-4xl leading-tight text-white outline-none transition-colors focus-visible:rounded-lg focus-visible:ring-2 focus-visible:ring-white/70 sm:text-5xl","aria-label":`Edit ${E.title} name`,children:E.title})}):e.jsx("h1",{className:"max-w-3xl font-primary text-4xl leading-tight text-white sm:text-5xl",children:E.title})]})]}),e.jsx("nav",{"aria-label":"Memory Project sections","data-testid":"memory-project-tabs",className:"sticky top-0 z-30 -mx-4 mb-4 border-y border-grey-2 bg-grey-0/95 px-3 py-3 shadow-sm backdrop-blur dark:border-grey-2 dark:bg-grey-0/95 sm:mx-0 sm:mb-5 sm:rounded-b-lg sm:border-x",children:e.jsx("div",{role:"tablist","aria-label":"Memory Project sections",className:"flex gap-2 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:E.tabs.map((re,me)=>{const Ce=re.icon,he=E.activeTab===re.key;return e.jsxs("button",{id:`memory-project-tab-${re.key}`,ref:c=>{C.current[me]=c},type:"button",role:"tab","aria-selected":he,"aria-controls":`memory-project-panel-${re.key}`,tabIndex:he?0:-1,onKeyDown:c=>te(c,me),onClick:()=>E.onTabChange(re.key),className:`inline-flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm font-semibold transition-colors ${he?"bg-[#453D3C] text-white dark:bg-[#453D3C] dark:text-white":"text-grey-5 hover:bg-white hover:text-grey-7 dark:hover:bg-grey-1"}`,children:[e.jsx(Ce,{size:16,"aria-hidden":"true"}),re.label,re.count!==void 0&&re.count>0&&e.jsx("span",{className:`rounded-full px-1.5 py-0.5 text-[10px] font-semibold ${he?"bg-white/15 text-white":"bg-primary-light text-primary"}`,children:re.count})]},re.key)})})})]})}return e.jsxs(e.Fragment,{children:[e.jsx(F.div,{variants:Ue,className:"relative -mx-4 sm:-mx-0",children:w?e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:a,type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:oe=>{const te=oe.target.files?.[0];te&&i(te),oe.target.value=""}}),e.jsxs("button",{type:"button",onClick:()=>a.current?.click(),disabled:s,"aria-label":B?"Change group cover photo":"Add group cover photo",className:"group relative h-44 w-full overflow-hidden rounded-2xl bg-gradient-to-br from-primary/20 via-primary/10 to-transparent transition-all hover:from-primary/25 hover:via-primary/15 dark:from-primary/10 dark:via-primary/5 sm:h-56",children:[B&&e.jsx("img",{src:B,alt:"",className:"absolute inset-0 h-full w-full object-cover"}),e.jsx("div",{className:`absolute inset-0 flex items-center justify-center transition-opacity ${s?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-white/80 px-4 py-2 text-xs font-medium text-grey-6 shadow-sm backdrop-blur-sm dark:bg-grey-1/80 dark:text-grey-4",children:[e.jsx(Is,{size:14}),s?"Uploading...":B?"Change cover photo":"Add cover photo"]})})]})]}):e.jsx("div",{className:"relative h-44 w-full overflow-hidden rounded-2xl bg-gradient-to-br from-primary/20 via-primary/10 to-transparent dark:from-primary/10 dark:via-primary/5 sm:h-56",children:B&&e.jsx("img",{src:B,alt:"",className:"absolute inset-0 h-full w-full object-cover"})})}),e.jsxs(F.div,{variants:Ue,className:"flex items-start gap-3 pt-3 sm:gap-5",children:[e.jsxs("div",{className:"relative",ref:h,children:[e.jsx("button",{type:"button",onClick:()=>{w&&(m||x(),g(!b))},className:`flex h-16 w-16 items-center justify-center rounded-2xl bg-grey-1 text-2xl transition-transform dark:bg-grey-2 ${w?"hover:scale-105":"cursor-default"} ${m?"ring-2 ring-primary/30":""}`,children:l}),b&&e.jsx(F.div,{initial:{opacity:0,y:4}
1,animate:{opacity:1,y:0},transition:{duration:.15},className:"absolute top-full left-0 z-20 mt-2 max-h-72 w-56 overflow-y-auto rounded-xl border border-grey-1 bg-white p-2 shadow-lg dark:border-transparent dark:bg-grey-1",children:Pi.map(oe=>e.jsxs("div",{children:[e.jsx("p",{className:"px-1 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-grey-3",children:oe.label}),e.jsx("div",{className:"grid grid-cols-5 gap-1",children:oe.emojis.map(te=>e.jsx("button",{type:"button",onClick:()=>{if(!w)return;y(te),g(!1);const re=Object.entries(Mi).find(([,me])=>me===te)?.[0];le({groupId:t.id,emoji:re||te})},className:`flex h-9 w-9 items-center justify-center rounded-lg text-lg transition-colors hover:bg-grey-1 dark:hover:bg-grey-2 ${j===te?"bg-primary-light ring-1 ring-primary/30":""}`,children:te},te))})]},oe.label))})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m?e.jsx("input",{type:"text",value:p,onChange:oe=>f(oe.target.value),onKeyDown:oe=>{oe.key==="Enter"&&k(),oe.key==="Escape"&&S()},autoFocus:!0,className:"min-w-0 flex-1 border-b-2 border-primary/30 bg-transparent font-primary text-2xl font-bold leading-tight text-grey-7 outline-none focus:border-primary sm:text-3xl"}):w?e.jsx("h1",{children:e.jsx("button",{type:"button",onClick:x,className:"text-left font-primary text-2xl font-bold text-grey-7 outline-none transition-colors hover:text-primary focus-visible:rounded-lg focus-visible:ring-2 focus-visible:ring-primary/30 sm:text-3xl","aria-label":`Edit ${d} name`,children:d})}):e.jsx("h1",{className:"font-primary text-2xl font-bold text-grey-7 sm:text-3xl",children:d}),w&&e.jsx("span",{className:"rounded-full bg-primary-light px-2 py-0.5 text-[10px] font-semibold text-primary",children:"Owner"})]}),e.jsxs("p",{className:"mt-1 text-sm text-grey-4",children:[N.length," ",N.length===1?"member":"members",P.length>0&&e.jsxs("span",{className:"text-amber-500",children:[" · ",P.length," pending"]})]}),m&&e.jsxs(F.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},className:"mt-2 flex items-center gap-2",children:[e.jsxs(F.button,{type:"button",whileTap:{scale:.95},onClick:k,className:"inline-flex items-center gap-1.5 rounded-lg bg-primary px-3 py-1.5 text-xs font-medium text-white",children:[e.jsx(vt,{size:12}),"Save"]}),e.jsx("button",{type:"button",onClick:S,className:"rounded-lg px-3 py-1.5 text-xs font-medium text-grey-5 transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:"Cancel"})]})]}),ce]})]})}const yr=t=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t.trim()),Ei=5,_i=30;function Pr(t){return t.contactId?`contact:${t.contactId}`:t.email?`email:${t.email.toLowerCase()}`:`name:${t.name.trim().toLowerCase()}:${t.initials}`}function zi(t,r,s,a){const i=new Map,l=[];function d(m,p,f,j,y,b,g){const h=m.trim().toLowerCase(),x=[b?`contact:${b}`:null,y?`email:${y.toLowerCase()}`:null].filter(Boolean),S=h?`name:${h}`:null,k=x.length>0;let N=x.map(U=>i.get(U)).find(Boolean);if(!N&&S){const U=i.get(S),q=!!(U?.email||U?.contactId);U&&(!q||!k)&&(N=U)}const P=[...x,S].filter(Boolean);if(N){N.email??=y,N.contactId??=b,N.avatarUrl??=j;for(const U of P)i.set(U,N);return}const w={name:m,initials:p,avatarColor:f,avatarUrl:j,email:y,contactId:b,context:g};l.push(w);for(const U of P)i.set(U,w)}for(const m of t)d(`${m.firstName} ${m.lastName}`,m.initials,m.avatarColor,m.avatarUrl,m.email,void 0,m.relation);for(const m of r)d(m.sharedBy.name,m.sharedBy.initials,m.sharedBy.avatarColor,m.sharedBy.avatarUrl,void 0,m.sharedBy.contactId,"Shared pages with you");for(const m of s)d(m.owner.name,m.owner.initials,m.owner.avatarColor,m.owner.avatarUrl,void 0,m.owner.contactId,`Owns "${m.name}"`);for(const m of a)for(const p of m.members)d(p.name,p.initials,p.avatarColor,p.avatarUrl,p.email,void 0,`Member of ${m.name}`);return l}function Bs(t){return typeof window>"u"?`/memory-project/join/${t}`:new URL(`/memory-project/join/${t}`,window.location.origin).toString()}function Mr(t,r){return t instanceof Error?t.message:r}function Ks(t,r,s=`${r}s`){return t===1?r:s}function Di(t){if(!t||t.role!=="contributor")return[];const r=[],s=t.scheduledCallCount??0,a=t.completedCallCount??0,i=t.uploadedSourceCount??0;return s>0&&r.push({key:"scheduled",label:s===1?"Call scheduled":`${s}
1 calls scheduled`,tone:"scheduled"}),a>0&&r.push({key:"completed",label:`${a} completed ${Ks(a,"call")}`,tone:"completed"}),i>0&&r.push({key:"uploads",label:`${i} ${Ks(i,"upload")}`,tone:"upload"}),r.length===0&&r.push({key:"idle",label:"No activity yet",tone:"idle"}),r}function Ai(t){return t==="scheduled"?"bg-blue-50 text-blue-700 dark:bg-blue-500/10 dark:text-blue-300":t==="completed"?"bg-emerald-50 text-emerald-700 dark:bg-emerald-500/10 dark:text-emerald-300":t==="upload"?"bg-primary-light text-primary dark:bg-primary/10 dark:text-primary":"bg-grey-1 text-grey-5 dark:bg-grey-2 dark:text-grey-4"}function $i({groupId:t,slug:r,acceptedMembers:s,pendingInvites:a,isOwner:i,inviteRequestKey:l=0,inviteLinksRequestKey:d=0,onInviteLinksRequestHandled:m,onInviteRequestHandled:p,memoryProjectSummary:f,canEvaluateMemoryProjectInvitePrompt:j,isMemoryProjectInvitePromptDismissed:y,onDismissMemoryProjectInvitePrompt:b}){const{STORYTELLERS:g,SHARED_WITH_ME:h,SHARED_COLLECTIONS:x,GROUPS:S}=Kr(),k=ne(O.groups.inviteMember),N=ne(O.groups.removeMember),P=ne(O.groups.resendInvite),w=ne(O.groups.cancelInvite),U=ne(O.memoryProjects.enablePublicLink),q=ne(O.memoryProjects.revokePublicLink),K=be(O.memoryProjects.getLinkManagementForGroup,i?{groupId:t}:"skip"),Z=f?.capabilities,E=!!f||!!K,B=Z?.canEnableContributorLink??K?.canEnableContributorLink??!E,le=Z?.canEnableViewerLink??K?.canEnableViewerLink??!E,[$,X]=o.useState(!1),[G,ae]=o.useState(!1),ee=G&&!!K,[Q,M]=o.useState(""),_=Wo(Q.trim(),250),[T,z]=o.useState([]),[C,L]=o.useState(!1),[H,v]=o.useState(null),[D,se]=o.useState(!1),[de,ze]=o.useState(new Set),[ke,Pe]=o.useState("contributor"),[Ne,ce]=o.useState(""),[oe,te]=o.useState(1),[re,me]=o.useState(null),[Ce,he]=o.useState(new Set),[c,Y]=o.useState(null),[ie,ue]=o.useState(null),[Se,Ee]=o.useState(null),Ke=o.useRef(null),Me=o.useRef(null),Nt=o.useRef(null),He=o.useRef(null),tt=o.useRef(null),Oe=o.useRef(null),ct=o.useRef(null),Ye=be(O.members.searchContacts,_.length>=2?{query:_}:"skip");o.useEffect(()=>{function u(A){Ke.current&&!Ke.current.contains(A.target)&&L(!1)}return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]),o.useEffect(()=>{!i||l<=0||(X(!0),L(!0),p?.())},[l,i,p]),o.useEffect(()=>{if(!i||!$)return;const u=window.requestAnimationFrame??(we=>window.setTimeout(we,0)),A=window.cancelAnimationFrame??(we=>window.clearTimeout(we)),ge=u(()=>{Me.current?.scrollIntoView?.({behavior:"smooth",block:"center"}),Nt.current?.focus({preventScroll:!0})});return()=>A(ge)},[i,$]),o.useEffect(()=>{!i||d<=0||!K||(X(!1),ae(!0),m?.())},[d,i,K,m]),o.useEffect(()=>{if(!ee)return;const u=Oe.current;u&&!u.open&&u.showModal();const A=window.requestAnimationFrame??(xe=>window.setTimeout(xe,0)),ge=window.cancelAnimationFrame??(xe=>window.clearTimeout(xe)),we=A(()=>{ct.current?.focus({preventScroll:!0})});return()=>{ge(we),u?.open&&u.close()}},[ee]),o.useEffect(()=>{if(!re)return;const u=He.current;u&&!u.open&&u.showModal();const A=window.requestAnimationFrame??(xe=>window.setTimeout(xe,0)),ge=window.cancelAnimationFrame??(xe=>window.clearTimeout(xe)),we=A(()=>{tt.current?.focus({preventScroll:!0})});return()=>{ge(we),u?.open&&u.close()}},[re]);const ot=o.useMemo(()=>zi(g,h,x,S),[g,h,x,S]),Ve=o.useMemo(()=>{const u=Q.trim().toLowerCase(),A=ot.filter(xe=>!T.some(Te=>Te.email&&xe.email?Te.email===xe.email:Te.initials===xe.initials)),ge=u?A.filter(xe=>xe.name.toLowerCase().includes(u)||xe.email?.toLowerCase().includes(u)):C?A:[],we=(Ye??[]).filter(xe=>xe.email).filter(xe=>!T.some(Te=>Te.email===xe.email)).filter(xe=>!ge.some(Te=>Te.email===xe.email)).map(xe=>{const Te=xe.email??"Contact";return{name:`${xe.firstName} ${xe.lastName}`.trim()||Te,initials:xe.initials,avatarColor:xe.avatarColor,email:xe.email,contactId:void 0,context:Te}});return[...ge,...we]},[Q,T,ot,C,Ye]),Qe=u=>{z(A=>[...A,u]),M("")},Dt=u=>{z(A=>A.filter(ge=>Pr(ge)!==u))},Le=u=>{const A=u.trim();return{name:A,initials:A.substring(0,2).toUpperCase(),avatarColor:"bg-grey-4",email:A}},Ze=u=>{const A=u.trim();T.some(ge=>ge.email===A)||(z(ge=>[...ge,Le(A)]),M(""))},jt=async()=>{const u=Q.trim(),ge=yr(u)&&!T.some(xe=>xe.email?.toLowerCase()===u.toLowerCase())?[...T,Le(u)]:T;if(ge.length===0)return;const we=E&&ke==="viewer"&&!le?"Viewer invites open after capture closes.":E&&ke==="contributor"&&!B?"Contributor invites are closed for this Memory Project.":null;if(we){v(we),setTimeout(()=>v(null),4e3);return}se(!0);try{await Promise.all(ge.filter(_e=>_e.email||_e.contactId).map(_e=>
1{const Yt={groupId:t,recipientName:_e.name!==_e.email?_e.name:void 0,role:ke};return _e.email?k({...Yt,recipientEmail:_e.email}):_e.contactId?k({...Yt,recipientContactId:_e.contactId}):Promise.resolve()}));const xe=ge.filter(_e=>_e.email||_e.contactId),Te=ge.filter(_e=>!_e.email&&!_e.contactId),Ae=xe.map(_e=>_e.name);let it;Ae.length===0?it="No invites sent â selected people have no email on file":Te.length>0?it=Ae.length===1?`Invited ${Ae[0]} (${Te.length} skipped â no email)`:`Invited ${Ae.length} people (${Te.length} skipped â no email)`:it=Ae.length===1?`Invited ${Ae[0]}`:`Invited ${Ae.length} people`,v(it),setTimeout(()=>v(null),3e3)}catch(xe){v(Mr(xe,"Failed to invite")),setTimeout(()=>v(null),4e3)}finally{se(!1)}X(!1),M(""),z([]),Pe("contributor")},Ct=u=>K?u==="contributor"?B:le:!1,St=u=>u==="contributor"?"Contributor invites are closed for this Memory Project.":"Viewer links are available after capture closes.",De=yr(Q)&&!T.some(u=>u.email?.toLowerCase()===Q.trim().toLowerCase()),rt=T.length>0||De,Fe=async u=>{if(!(!K||!Ct(u))){ue(u);try{await U({memoryProjectId:K.memoryProjectId,kind:u}),v(u==="contributor"?"Contributor link updated":"Viewer link updated"),setTimeout(()=>v(null),3e3)}catch(A){v(Mr(A,"Could not update link")),setTimeout(()=>v(null),4e3)}finally{ue(null)}}},yt=async u=>{if(K){ue(u);try{await q({memoryProjectId:K.memoryProjectId,kind:u}),v(u==="contributor"?"Contributor link revoked":"Viewer link revoked"),setTimeout(()=>v(null),3e3)}catch(A){v(Mr(A,"Could not revoke link")),setTimeout(()=>v(null),4e3)}finally{ue(null)}}},V=async u=>{if(ie===u)return;const A=K?.links[u]?.token;if(A)try{await navigator.clipboard.writeText(Bs(A)),Ee(u),v(u==="contributor"?"Contributor link copied":"Viewer link copied"),setTimeout(()=>Ee(null),2e3),setTimeout(()=>v(null),3e3)}catch{v("Could not copy link"),setTimeout(()=>v(null),4e3)}},pe=u=>{u.contactId&&me({contactId:u.contactId,name:u.name,roleLabel:Je(u.role,u.isAdmin)})},ye=async()=>{if(!re)return;const{contactId:u,name:A}=re;me(null),he(ge=>new Set(ge).add(u)),Y(`Removing ${A}`);try{await N({groupId:t,contactId:u}),v(`${A} removed`),Y(`${A} removed`),setTimeout(()=>v(null),3e3)}catch(ge){const we=Mr(ge,`Could not remove ${A}`);v(we),Y(we),setTimeout(()=>v(null),4e3)}finally{he(ge=>{const we=new Set(ge);return we.delete(u),we})}},Ge=async u=>{await P({groupId:t,inviteId:u})},ht=u=>{w({groupId:t,inviteId:u}).catch(console.error)},je=!!f,ve=je?_i:Ei,At=o.useMemo(()=>new Map((f?.memberStatuses??[]).map(u=>[u.contactId,u])),[f?.memberStatuses]),qt=Ne.trim().toLowerCase(),qe=qt?s.filter(u=>u.name?.toLowerCase().includes(qt)||u.email?.toLowerCase().includes(qt)):s,mt=Math.max(1,Math.ceil(qe.length/ve)),et=Math.min(oe,mt),$t=(et-1)*ve,Wt=Math.min($t+ve,qe.length),Ut=qe.slice($t,Wt),ur=qe.filter(u=>u.isAdmin||u.role==="owner"),xr=qe.filter(u=>!u.isAdmin&&u.role!=="viewer"),bt=qe.filter(u=>u.role==="viewer"),It=Ut.filter(u=>u.isAdmin||u.role==="owner"),We=Ut.filter(u=>!u.isAdmin&&u.role!=="viewer"),pr=Ut.filter(u=>u.role==="viewer");o.useEffect(()=>{oe>mt&&te(mt)},[oe,mt]);const Je=(u,A)=>A||u==="owner"?"Owner":u==="viewer"?"Viewer":"Contributor",Pt=(u,A)=>A||u==="owner"?"bg-primary-light text-primary dark:bg-primary/10":u==="viewer"?"bg-grey-1 text-grey-5 dark:bg-grey-2 dark:text-grey-4":"bg-emerald-50 text-emerald-600 dark:bg-emerald-500/10 dark:text-emerald-400",gr=[{key:"owner",label:"Owner",members:It,total:ur.length},{key:"contributor",label:"Contributors",members:We,total:xr.length},{key:"viewer",label:"Viewers",members:pr,total:bt.length}].filter(u=>u.members.length>0),Vt=qe.length>ve,Ht=je?"inline-flex h-9 items-center justify-center gap-1 rounded-lg border border-grey-2 px-3 text-sm font-semibold text-grey-6 transition-colors hover:bg-grey-0 disabled:cursor-not-allowed disabled:opacity-40 dark:border-grey-2 dark:hover:bg-grey-2":"inline-flex h-9 items-center justify-center gap-1 rounded-full border border-grey-1 px-3 text-sm font-medium text-grey-6 transition-colors hover:bg-grey-0 disabled:cursor-not-allowed disabled:opacity-40 dark:border-grey-2 dark:hover:bg-grey-2",Lt=f?.counts?.contributors??0,wt=f?.plan?.contributorLimit,tr=je&&i&&j&&B&&Lt<2&&!y,ut=je?"inline-flex h-10 items-center justify-center gap-2 rounded-lg px-3 text-sm font-semibold transition-colors":"inline-flex items-center justify-center gap-2 rounded-full px-4 py-2 text-sm font-medium transition-colors";return e.jsxs(e.Fragment,{children:[e.jsx("output",{"aria-live":"polite",className:"sr-only",children:c}),e.jsx(lt,{children:H&&e.jsx(F.div,{initial:{opacity:0,y:-20}
1,animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"fixed top-6 left-1/2 z-50 -translate-x-1/2 rounded-full border border-grey-1 dark:border-transparent bg-white px-5 py-2.5 text-sm font-medium text-grey-6 shadow-lg dark:bg-grey-1",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[H.startsWith("No invites")||H.startsWith("Failed")?e.jsx(ss,{size:14,className:"text-amber-500"}):e.jsx(vt,{size:14,className:"text-emerald-500"}),H]})})}),e.jsxs(F.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.18,ease:"easeOut"},className:je?"rounded-lg border border-grey-2 bg-white p-5 shadow-sm dark:border-transparent dark:bg-grey-1":void 0,children:[e.jsxs("div",{className:"mb-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[je&&e.jsx(Gr,{"data-testid":"memory-project-members-heading-icon",size:18,className:"text-primary","aria-hidden":"true"}),e.jsx("h3",{className:je?"text-sm font-bold uppercase text-grey-7":"font-primary text-xl font-bold text-grey-7",children:"Members"})]}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:f?.counts?`Contributors ${f.counts.contributors??0}${f.plan?.contributorLimit!==null&&f.plan?.contributorLimit!==void 0?` / ${f.plan.contributorLimit}`:""}`:`${s.length} people with access to this group.`})]}),i&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[K&&e.jsxs(F.button,{type:"button",whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>ae(!0),className:je?`${ut} border border-grey-2 bg-white text-grey-6 hover:bg-grey-0 dark:border-transparent dark:bg-grey-1`:`${ut} border border-grey-1 bg-white text-grey-6 shadow-sm hover:bg-grey-0 dark:border-transparent dark:bg-grey-1`,children:[e.jsx(as,{size:16}),je?"Manage invite links":"Invite links"]}),e.jsxs(F.button,{type:"button",whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>X(!0),className:je?`${ut} bg-memory-cta text-white shadow-sm hover:bg-memory-cta/90 dark:bg-grey-2 dark:text-grey-7 dark:hover:bg-grey-3`:`${ut} bg-primary text-white shadow-sm`,children:[e.jsx(sr,{size:16}),je?"Invite contributors":"Invite"]})]})]}),tr&&e.jsxs("div",{"data-testid":"memory-project-members-invite-banner",className:"mb-4 flex items-start gap-3 rounded-xl border border-memory/20 bg-memory/10 px-4 py-3 dark:border-grey-2 dark:bg-grey-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-bold text-grey-7",children:"Invite contributors next"}),e.jsxs("p",{className:"mt-1 text-sm text-grey-5",children:["Calls and uploads come from contributors. ",wt!=null?`${Lt} of ${wt} contributor spots are filled.`:`${Lt} contributors are active.`]})]}),e.jsx("button",{type:"button",onClick:b,className:"inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-grey-4 transition-colors hover:bg-white/70 hover:text-grey-7 dark:hover:bg-grey-1","aria-label":"Dismiss invite contributors reminder",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:je?"mb-4 flex items-center gap-2 rounded-lg border border-grey-2 bg-white px-4 py-2.5 dark:border-transparent dark:bg-grey-1":"mb-4 flex items-center gap-2 rounded-full border border-grey-1 bg-white px-4 py-2.5 dark:border-transparent dark:bg-grey-1",children:[e.jsx($r,{size:16,className:"text-grey-3"}),e.jsx("input",{type:"search",value:Ne,onChange:u=>{ce(u.target.value),te(1)},placeholder:"Search by name or email",className:"min-w-0 flex-1 bg-transparent text-sm text-grey-6 outline-none placeholder:text-grey-3"})]}),e.jsxs(F.div,{initial:"hidden",animate:"show",variants:_t,className:"space-y-2",children:[gr.map(u=>e.jsxs("div",{"data-testid":je?`memory-project-member-role-group-${u.key}`:void 0,className:je?"overflow-hidden rounded-xl border border-grey-1 bg-grey-0/60 dark:border-transparent dark:bg-grey-0":"overflow-hidden rounded-xl border border-grey-1 bg-white dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"border-b border-grey-1 px-4 py-2 text-xs font-semibold text-grey-4 dark:border-grey-2",children:[u.label," · ",u.members.length===u.total?u.total:`${u.members.length} of ${u.total}`]}),e.jsx(lt,{initial:!1,children:u.members.map((A,ge)=>{const we=A.contactId?At.get(A.contactId):void 0,xe=je?Di(we):[],Te=!!A.contactId&&Ce.has(A.contactId);return e.jsxs(F.div,{variants:Ue,exit:{opacity:0,x:36,scale:.98,transition:{duration:.18,ease:"easeInOut"}},className:`flex items-center gap-3 px-4 py-3 transition-colors ${ge>0?"border-t border-grey-1 dark:border-grey-2":""} ${Te?"bg-red-50/80 dark:bg-red-500/10":""}`,children:[e.jsx(Sr,{avatarColor:A.avatarColor,avatarUrl:A.avatarUrl,alt:A.initials,className:`h-10 w-10 text-sm transition-transform ${Te?"scale-90 opacity-70":""}`,children:A.initials}),e.jsxs("div",{className:`min-w-0 flex-1 transition-opacity ${Te?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"truncate text-sm font-medium text-grey-7",children:A.name}),e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold ${Pt(A.role,A.isAdmin)}`,children:[(A.isAdmin||A.role==="owner")&&e.jsx(qo,{size:9}),Je(A.role,A.isAdmin)]}),Te&&e.jsx("span",{"aria-hidden":"true",className:"inline-flex items-center rounded-full bg-red-100 px-2 py-0.5 text-[10px] font-semibold text-red-600 dark:bg-red-500/15 dark:text-red-300",children:"Removing..."})]}),A.email&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-grey-4",children:A.email}),xe.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-1.5",children:xe.map(Ae=>e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-[10px] font-semibold ${Ai(Ae.tone)}`,children:[Ae.tone==="scheduled"&&e.jsx(Co,{size:11,"aria-hidden":"true"}),Ae.tone==="completed"&&e.jsx(vt,{size:11,"aria-hidden":"true"}),Ae.tone==="upload"&&e.jsx(Vo,{size:11,"aria-hidden":"true"}),Ae.tone==="idle"&&e.jsx(Bt,{size:11,"aria-hidden":"true"}),Ae.label]},Ae.key))})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(()=>{const Ae=g.find(it=>`${it.firstName} ${it.lastName}`===A.name);return Ae?e.jsx(Et,{to:"/$slug/storyteller/$storytellerId",params:{slug:r,
1storytellerId:Ae.id},className:"text-xs font-medium text-primary transition-colors hover:text-primary/80",children:"View profile"}):null})(),i&&!A.isAdmin&&A.contactId&&e.jsx("button",{type:"button",onClick:()=>pe(A),disabled:Te,className:"flex items-center gap-1 rounded-full px-2 py-1 text-[10px] font-medium text-red-500 transition-colors hover:bg-red-50 disabled:cursor-wait disabled:opacity-50 dark:hover:bg-red-500/10","aria-label":`Remove ${A.name} from group`,title:`Remove ${A.name}`,children:e.jsx(gt,{size:12})})]})]},A.contactId??A.initials)})})]},u.key)),qe.length===0&&e.jsx("div",{className:je?"rounded-xl border border-dashed border-grey-2 bg-grey-0/60 px-4 py-6 text-center text-sm text-grey-4 dark:bg-grey-0":"rounded-xl border border-dashed border-grey-2 px-4 py-6 text-center text-sm text-grey-4",children:"No people match this search."}),Vt&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("p",{className:"text-xs font-medium text-grey-4",children:["Showing ",$t+1,"-",Wt," of ",qe.length]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>te(u=>Math.max(1,u-1)),disabled:et===1,className:Ht,children:[e.jsx(Xo,{size:15}),"Previous"]}),e.jsxs("span",{className:"rounded-lg bg-grey-1 px-3 py-2 text-xs font-semibold text-grey-5 dark:bg-grey-2",children:["Page ",et," of ",mt]}),e.jsxs("button",{type:"button",onClick:()=>te(u=>Math.min(mt,u+1)),disabled:et===mt,className:Ht,children:["Next",e.jsx(So,{size:15})]})]})]}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"flex items-center gap-1.5 pt-2 text-xs font-medium text-grey-4",children:[e.jsx(Bt,{size:12}),"Pending invites"]}),a.map(u=>e.jsxs(F.div,{variants:Ue,className:"flex items-center gap-3 rounded-xl border border-amber-200 dark:border-amber-500/30 bg-amber-50/40 dark:bg-amber-500/5 px-4 py-3",children:[e.jsx(Sr,{avatarColor:u.avatarColor,className:"h-10 w-10 opacity-80 text-sm",children:u.initials}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium text-grey-6 dark:text-grey-3",children:u.name}),e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-amber-100 dark:bg-amber-500/20 px-2 py-0.5 text-[10px] font-semibold text-amber-700 dark:text-amber-400",children:[e.jsx(Bt,{size:10}),"Pending"]}),e.jsx("span",{className:"inline-flex rounded-full bg-white/70 px-2 py-0.5 text-[10px] font-semibold capitalize text-grey-5 dark:bg-grey-2",children:u.role??"contributor"})]}),u.email&&u.email!==u.name&&e.jsx("p",{className:"text-xs text-grey-4",children:u.email})]}),i&&u.id&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{type:"button",disabled:de.has(u.id),onClick:async()=>{ze(A=>new Set(A).add(u.id));try{await Ge(u.id),v("Invitation resent!"),setTimeout(()=>v(null),3e3)}catch(A){console.error("Failed to resend invite:",A)}finally{ze(A=>{const ge=new Set(A);return ge.delete(u.id),ge})}},className:"inline-flex items-center gap-1 rounded-full bg-primary-light dark:bg-primary/10 px-2.5 py-1 text-[10px] font-medium text-primary transition-colors hover:bg-primary/20 disabled:opacity-50",title:"Resend invitation",children:[e.jsx(Zo,{size:10}),de.has(u.id)?"Sending...":"Resend"]}),e.jsx("button",{type:"button",onClick:()=>ht(u.id),className:"flex items-center gap-1 rounded-full px-2 py-1 text-[10px] font-medium text-red-500 transition-colors hover:bg-red-50 dark:hover:bg-red-500/10","aria-label":"Cancel invitation",title:"Cancel invitation",children:e.jsx(fe,{size:12})})]})]},u.id??u.initials))]}),i&&$?e.jsxs(F.div,{ref:Me,initial:{opacity:0,y:8},animate:{opacity:1,y:0},className:"rounded-xl border border-primary/20 bg-white p-4 dark:bg-grey-1",children:[T.length>0&&e.jsx("div",{className:"mb-2 flex flex-wrap gap-1.5",children:T.map(u=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full bg-primary-light py-1 pl-1 pr-2.5 text-xs font-medium text-primary",children:[e.jsx(Sr,{avatarColor:u.avatarColor,avatarUrl:u.avatarUrl,alt:u.initials,className:"h-5 w-5 text-[9px]",children:u.initials}),u.name,e.jsx("button",{type:"button",onClick:()=>Dt(Pr(u)),className:"ml-0.5 text-primary/60 hover:text-primary","aria-label":`Remove ${u.name}`,children:e.jsx(fe,{size:12})})]},Pr(u)))}),e.jsx("div",{className:"mb-3 inline-flex rounded-full border border-grey-1 bg-grey-0 p-1 dark:border-transparent dark:bg-grey-2",children:["contributor","viewer"].map(u=>{const A=E&&(u==="viewer"&&!le||u==="contributor"&&!B);return e.jsx("button",{type:"button",disabled:A,title:A?St(u):void 0,onClick:()=>Pe(u),className:`rounded-full px-3 py-1 text-xs font-medium capitalize transition-colors ${ke===u?"bg-white text-grey-7 shadow-sm dark:bg-grey-1":A?"cursor-not-allowed text-grey-3":"text-grey-4 hover:text-grey-6"}`,children:u},u)})}),e.jsxs("div",{className:"relative",ref:Ke,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{ref:Nt,type:"text","aria-label":"Name or email of person to invite",placeholder:"Name or email",value:Q,onChange:u=>M(u.target.value),onFocus:()=>L(!0),onKeyDown:u=>{u.key==="Escape"&&(X(!1),M(""),L(!1)),u.key==="Enter"&&Q.trim()&&yr(Q)&&(u.preventDefault(),Ze(Q),L(!0))},autoFocus:!0,className:"min-w-0 flex-1 rounded-lg border border-grey-2 px-3 py-2 text-sm text-grey-6 placeholder:text-grey-3 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20"}),e.jsxs(F.button,{type:"button",whileTap:{scale:.95},onClick:jt,disabled:D||!rt,className:`flex h-9 items-center gap-1.5 rounded-lg px-4 text-sm font-medium text-white ${D||!rt?"bg-primary/50":"bg-primary"}`,children:[e.jsx(vt,{size:14}),D?"Sending...":"Invite"]}),e.jsx("button",{type:"button",onClick:()=>{X(!1),M(""),L(!1)},className:"flex h-9 w-9 items-center justify-center rounded-lg text-grey-4 hover:bg-grey-1 dark:hover:bg-grey-2","aria-label":"Cancel invite form",children:e.jsx(fe,{size:16})})]}),e.jsx(lt,{children:(Ve.length>0||Q.trim()&&yr(Q))&&e.jsxs(F.div,{initial:{opacity:0,y:4}
1,animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.12},className:"absolute left-0 right-12 z-40 mt-1 max-h-52 overflow-y-auto rounded-xl border border-grey-1 bg-white py-1 shadow-lg dark:border-transparent dark:bg-grey-1",children:[!Q.trim()&&e.jsx("p",{className:"px-3 py-1.5 text-[10px] font-semibold uppercase tracking-wider text-grey-3",children:"Suggestions"}),Ve.map(u=>e.jsxs("button",{type:"button",onClick:()=>{Qe(u),L(!0)},className:"flex w-full items-center gap-3 px-3 py-2.5 text-left transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx(Sr,{avatarColor:u.avatarColor,avatarUrl:u.avatarUrl,alt:u.initials,className:"h-9 w-9 text-xs",children:u.initials}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-grey-7",children:u.name}),e.jsx("p",{className:"truncate text-xs text-grey-4",children:u.context})]})]},`${Pr(u)}:${u.context}`)),Q.trim()&&yr(Q)&&!T.some(u=>u.email===Q.trim())&&e.jsxs("button",{type:"button",onClick:()=>{Ze(Q),L(!0)},className:"flex w-full items-center gap-3 px-3 py-2.5 text-left transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx("span",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-primary/10 text-xs font-bold text-primary",children:e.jsx(Io,{size:16})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-medium text-grey-7",children:["Invite ",Q.trim()]}),e.jsx("p",{className:"text-xs text-grey-4",children:"Send email invitation"})]})]})]})}),De&&e.jsxs("p",{className:"mt-2 text-xs font-medium text-primary",children:["Ready to invite ",Q.trim(),"."]})]})]}):i?e.jsxs(F.button,{type:"button",variants:Ue,whileHover:{scale:1.01},whileTap:{scale:.98},onClick:()=>X(!0),className:"flex w-full items-center justify-center gap-2 rounded-xl border-2 border-dashed border-grey-2 py-4 text-sm font-medium text-primary transition-colors hover:border-primary/30 hover:bg-primary-light",children:[e.jsx(sr,{size:16}),"Invite someone"]}):null]})]}),e.jsx(lt,{children:re&&e.jsx(F.dialog,{ref:He,initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},"aria-labelledby":"remove-member-confirmation-title","aria-modal":"true",className:"fixed inset-0 z-50 m-0 flex h-dvh max-h-none w-dvw max-w-none items-center justify-center border-0 bg-black/35 px-4 backdrop:bg-transparent backdrop:backdrop-blur-sm",onMouseDown:u=>{u.target===u.currentTarget&&me(null)},onCancel:u=>{u.preventDefault(),me(null)},children:e.jsxs(F.div,{initial:{opacity:0,y:16,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:16,scale:.98},className:"w-full max-w-md rounded-xl border border-grey-1 bg-white p-5 shadow-xl dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-red-50 text-red-500 dark:bg-red-500/10",children:e.jsx(ss,{size:20,"aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h3",{id:"remove-member-confirmation-title",className:"font-primary text-xl font-bold text-grey-7",children:["Remove ",re.name,"?"]}),e.jsxs("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:["This will remove their ",re.roleLabel.toLowerCase()," access to this group. They will no longer see project details, sources, sessions, or stories shared here."]})]})]}),e.jsxs("div",{className:"mt-5 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[e.jsx("button",{ref:tt,type:"button",onClick:()=>me(null),className:"inline-flex items-center justify-center rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition-colors hover:bg-grey-0 dark:border-grey-2 dark:hover:bg-grey-2",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:ye,className:"inline-flex items-center justify-center gap-2 rounded-lg bg-red-500 px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-red-600",children:[e.jsx(gt,{size:15,"aria-hidden":"true"}),"Remove member"]})]})]})})}),e.jsx(lt,{children:ee&&K&&e.jsxs(F.dialog,{ref:Oe,initial:{opacity:0,y:16,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:16,scale:.98},className:"fixed inset-0 m-auto w-[calc(100%-2rem)] max-w-2xl rounded-xl border border-grey-1 bg-white p-6 shadow-xl backdrop:bg-black/35 backdrop:backdrop-blur-sm dark:border-transparent dark:bg-grey-1","aria-labelledby":"memory-project-links-heading","aria-modal":"true",onMouseDown:u=>{u.target===u.currentTarget&&ae(!1)},onCancel:u=>{u.preventDefault(),ae(!1)},children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"memory-project-links-heading",className:"font-primary text-2xl font-bold text-grey-7",children:"Invite links"}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-grey-5",children:"Share a Contributor link during capture, then open a separate Viewer link after capture closes."})]}),e.jsx("button",{ref:ct,type:"button",onClick:()=>ae(!1),className:"rounded-full p-2 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-6","aria-label":"Close invite links",children:e.jsx(fe,{size:18})})]}),e.jsx("div",{className:"mt-5 space-y-3",children:["contributor","viewer"].map(u=>{const A=K.links[u],ge=Ct(u),we=ie===u;return e.jsx("div",{"data-testid":`memory-project-${u}-link-card`,className:"rounded-xl border border-grey-1 p-4 dark:border-grey-2",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1","data-testid":`memory-project-${u}-link-details`,children:[e.jsxs("p",{className:"text-sm font-semibold capitalize text-grey-7",children:[u," link"]}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-grey-5",children:u==="contributor"?"Lets people join automatically as Contributors while capture is open.":"Lets people join as read-only Viewers after capture closes."}),A?e.jsx("p",{className:"mt-2 truncate rounded-lg bg-grey-0 px-3 py-2 text-xs text-grey-5 dark:bg-grey-2",children:Bs(A.token)}):ge?null:e.jsx("p",{className:"mt-2 text-xs font-medium text-grey-4",children:St(u)}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2","data-testid":`memory-project-${u}-link-optional-actions`,children:[e.jsxs("button",{type:"button",disabled:!ge||we,onClick:()=>Fe(u),className:"inline-flex items-center gap-1.5 rounded-full border border-grey-2 px-3 py-1.5 text-xs font-medium text-grey-5 transition-colors hover:bg-grey-0 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-50 dark:border-grey-2 dark:hover:bg-grey-2",children:[A?e.jsx(ys,{size:13}):e.jsx(as,{size:13}),we?"Working...":A?"Regenerate":`Create ${u} link`]}),A&&e.jsxs("button",{type:"button",disabled:we,onClick:()=>yt(u),className:"inline-flex items-center gap-1.5 rounded-full border border-red-200 px-3 py-1.5 text-xs font-medium text-red-500 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-50 dark:border-red-500/30 dark:hover:bg-red-500/10",children:[e.jsx(fe,{size:13}),"Revoke"]})]})]}),e.jsx("div",{className:"flex shrink-0 flex-wrap gap-2 sm:justify-end","data-testid":`memory-project-${u}-link-primary-actions`,children:A&&e.jsxs("button",{type:"button",disabled:we,onClick:()=>V(u),className:"inline-flex items-center gap-1.5 rounded-full bg-memory-cta px-4 py-2 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-grey-2 dark:text-grey-7 dark:hover:bg-grey-3",children:[Se===u?e.jsx(vt,{size:13}):e.jsx(ei,{size:13}),Se===u?"Copied":"Copy"]})})]})},u)})})]})})]})}const Ui=200,Gs=ri.map(({label:t,value:r})=>({label:t,value:r})),qs=si.map(({label:t,value:r})=>({label:t,value:r})),Ws={story:["story","stories"],person:["person","people","profile"],place:["place","places"],theme:["theme","themes"],event:["event","events"]};
1function er(t){return"pageType"in t&&"changelog"in t}function ls(t){return t.title}function Li(t){return t.preview??""}function Fi(t){const r=[ls(t),Li(t)];return er(t)&&r.push(t.body,...Ws[t.pageType],t.authorName??"",t.entityId??"",...t.fromSessions,...t.fromFiles??[],...t.relatedEntities,...(t.sourceSessions??[]).flatMap(s=>[s.title,s.date,s.dateShort,s.transcript]),...(t.sourceReferences??[]).flatMap(s=>[s.matchText,s.quote??"",s.sessionTitle??"",s.sourceType??""]),...(t.sourceFiles??[]).flatMap(s=>[s.name]),...(t.relatedPages??[]).flatMap(s=>[s.title,s.preview,s.body,...Ws[s.pageType],s.authorName??""])),r.filter(Boolean).join(" ")}function Vs(t){return er(t)?t.createdAt??(Date.parse(t.updatedAt)||0):Date.parse(t.updatedAt)||0}function Tr(t){return er(t)?t.updatedAtMs??t.createdAt??(Date.parse(t.updatedAt)||0):Date.parse(t.updatedAt)||0}function Oi(t,r){return er(t)?t.pageType:r.find(s=>s.id===t.id)?.pageType??"story"}function Hs(t){return er(t)?t.changelog.length:0}function Oa({groupId:t,slug:r,sharedPages:s,canManageLibrary:a,isOwner:i,isMemoryProject:l=!1,memoryProjectOverview:d}){const{PAGES:m,COLLECTIONS:p}=Kr(),f=!t.startsWith("group-"),j=be(O.groups.listSharedPages,f?{groupId:t,limit:Ui}:"skip"),y=ne(O.groups.sharePage),b=ne(O.groups.unsharePage),g=ne(O.groups.removePageFromGroup),[h,x]=o.useState(!1),[S,k]=o.useState(""),[N,P]=o.useState("all"),[w,U]=o.useState("newest"),q=o.useRef(null);o.useEffect(()=>{function C(L){q.current&&!q.current.contains(L.target)&&x(!1)}if(h)return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[h]);const K=o.useMemo(()=>s.map(C=>m.find(L=>L.id===C.id)??C),[s,m]),E=o.useMemo(()=>j?.map(C=>ja(C)),[j])??K,B=o.useMemo(()=>{const C=S.trim().toLowerCase();return E.filter(H=>N!=="all"&&Oi(H,m)!==N?!1:C?Fi(H).toLowerCase().includes(C):!0).map((H,v)=>({page:H,index:v})).sort((H,v)=>w==="alpha"?ls(H.page).localeCompare(ls(v.page)):w==="most-revised"?Hs(v.page)-Hs(H.page)||Tr(v.page)-Tr(H.page)||H.index-v.index:w==="recent"?Tr(v.page)-Tr(H.page)||H.index-v.index:Vs(v.page)-Vs(H.page)||H.index-v.index).map(({page:H})=>H)},[E,m,N,S,w]),le=l?B:E,$=E.length,X=f?{groupId:t}:void 0,G=new Set(E.map(C=>C.id)),ae=m.filter(C=>!G.has(C.id)),ee=a&&!l,Q=C=>p.filter(L=>L.pageIds.includes(C)).map(L=>({id:L.id,name:L.name})),M=async C=>{try{await y({groupId:t,pageId:C})}catch(L){console.error("Failed to share page:",L)}x(!1)},_=async(C,L)=>{if(!(L?.isGroupCanonicalPage&&!window.confirm("Hide this canonical page from the library? It will be hidden from the group library, removed from collections, and Walter may keep updating it in the background. Restoring later brings it back to the library, but not to collections.")))try{i?await g({groupId:t,pageId:C}):await b({groupId:t,pageId:C})}catch(H){console.error("Failed to unshare page:",H)}},T=l&&e.jsxs("div",{className:"mt-5 rounded-xl border border-grey-1 bg-grey-0/70 p-3 dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ir,{label:"Filter",value:N,defaultValue:"all",onChange:P,options:Gs}),e.jsx(Ir,{label:"Sort",value:w,defaultValue:"newest",onChange:U,options:qs})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx($r,{size:16,"aria-hidden":"true",className:"absolute left-3 top-1/2 -translate-y-1/2 text-grey-3"}),e.jsx("input",{type:"text","aria-label":"Search generated pages",placeholder:"Search generated pages...",value:S,onChange:C=>k(C.target.value),className:"w-full rounded-xl border border-grey-1 bg-white py-2 pl-9 pr-9 text-sm text-grey-6 placeholder:text-grey-3 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20 dark:border-grey-2 dark:bg-grey-1"}),S&&e.jsx("button",{type:"button","aria-label":"Clear generated page search",onClick:()=>k(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-grey-3 hover:text-grey-5",children:e.jsx(fe,{size:14,"aria-hidden":"true"})})]})]}),z=le.length===0?e.jsxs("div",{className:`${l?"mt-5":""} rounded-xl border-2 border-dashed border-grey-2 py-8 text-center`,children:[e.jsx(st,{size:24,className:"mx-auto mb-2 text-grey-3"}),e.jsx("p",{className:"text-sm font-medium text-grey-4",children:l&&$>0?"No generated pages match those filters":l?"No generated pages yet":"No pages shared yet"}),e.jsx("p",{className:"mt-1 text-xs text-grey-3",children:l?$>0?"Adjust the search or filter controls to see more generated pages.":i?"Generated pages and s
1ource-backed updates will appear here as Walter helps collect the project.":a?"Schedule a Walter call so your generated pages can appear here when they are ready.":"Generated pages will appear here as the Memory Project grows.":a?"Add pages from your library to start this group library.":"Pages shared with this group will appear here."})]}):e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:`${l?"mt-5":""} grid gap-3 sm:grid-cols-2`,children:le.map(C=>{const L=er(C)?C:m.find(se=>se.id===C.id),H=i||L?.viewerCanEdit===!0,v=L?.isGroupCanonicalPage===!0,D=v?"Hide from library":"Remove from group";return e.jsxs(F.div,{variants:ar,whileHover:{y:-2,transition:{duration:.15}},className:"group/card relative",children:[L?e.jsx(As,{page:L,slug:r,linkSearch:X,getCollectionsForPage:Q,hideDestinationLabel:l}):e.jsx("div",{className:"rounded-2xl border border-grey-1 bg-white p-5 transition-shadow hover:shadow-md dark:border-grey-2 dark:bg-grey-1",children:e.jsxs(Et,{to:"/$slug/pages/$pageId",params:{slug:r,pageId:C.id},search:X,className:"block",children:[e.jsx("h4",{className:"font-primary text-lg font-bold",children:C.title}),e.jsx("p",{className:"mt-2 line-clamp-3 text-sm leading-relaxed text-grey-4",children:C.preview}),e.jsx("span",{className:"mt-3 inline-block text-xs text-grey-3",children:C.updatedAt})]})}),a&&H&&e.jsx("button",{type:"button",onClick:()=>_(C.id,{isGroupCanonicalPage:v}),className:"absolute top-2 right-2 z-20 flex h-7 w-7 items-center justify-center rounded-full bg-white/90 text-grey-4 opacity-100 shadow-sm transition-opacity hover:bg-red-50 hover:text-red-500 focus-visible:opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 sm:group-focus-within/card:opacity-100 sm:focus-visible:opacity-100 dark:bg-grey-2 dark:hover:bg-red-500/10","aria-label":D,title:D,children:e.jsx(fe,{size:13})})]},C.id)})});return l&&d?e.jsx(F.div,{initial:"hidden",animate:"show",variants:Ue,children:e.jsxs("section",{"data-testid":"memory-project-library-container",className:"rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(st,{size:18,className:"text-primary","aria-hidden":"true"}),e.jsx("span",{className:"text-sm font-bold uppercase text-grey-7",children:"Library"})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h2",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:d.title}),e.jsx("span",{className:"rounded-full bg-grey-1 px-2 py-0.5 text-[11px] font-semibold text-grey-5 dark:bg-grey-2",children:d.summary})]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:d.body})]}),T,z]})}):e.jsxs(F.div,{initial:"hidden",animate:"show",variants:Ue,children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("h3",{className:"flex items-center gap-2 font-primary text-xl font-bold text-grey-7",children:[e.jsx(st,{size:14}),l?"Generated pages":"Pages",e.jsx("span",{className:"rounded-full bg-grey-1 px-2 py-0.5 text-[10px] font-medium text-grey-4 dark:bg-grey-2",children:ti(l?"memoryProject":"group")}),$>0&&e.jsx("span",{className:"rounded-full bg-grey-1 px-2 py-0.5 text-[10px] font-medium text-grey-4 dark:bg-grey-2",children:E.length})]}),ee&&e.jsxs("div",{className:"relative",ref:q,children:[e.jsxs(F.button,{type:"button",whileHover:{scale:1.03},whileTap:{scale:.97},onClick:()=>x(!h),className:"inline-flex items-center gap-1.5 rounded-full bg-primary px-4 py-1.5 text-xs font-medium text-white shadow-sm",children:[e.jsx(at,{size:12}),"Add pages",e.jsx(wr,{size:10,className:`transition-transform ${h?"rotate-180":""}`})]}),e.jsx(lt,{children:h&&e.jsx(F.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:4},transition:{duration:.15},className:"absolute right-0 z-30 mt-2 w-72 rounded-xl border border-grey-1 bg-white py-1 shadow-lg dark:border-transparent dark:bg-grey-1",children:e.jsxs("div",{className:"max-h-72 overflow-y-auto",children:[e.jsx("p",{className:"px-3 py-2 text-[10px] font-semibold uppercase tracking-wider text-grey-3",children:"Pages"}),ae.length===0?e.jsx("p",{className:"px-3 py-3 text-center text-xs text-grey-4",children:"All pages are already shared."}):e.jsx(e.Fragment,{children:ae.map(C=>e.jsxs("button",{type:"button",onClick:()=>M(C.id),className:"flex w-full items-center gap-3 px-3 py-2.5 text-left transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-primary-light",children:e.jsx(st,{size:14,className:"text-primary"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-grey-7",children:C.title}),e.jsxs("p",{className:"truncate text-[11px] text-grey-4",children:[C.preview.slice(0,60),"..."]})]})]},C.id))})]})})})]})]}),l&&e.jsxs("div",{className:"mb-4 rounded-xl border border-grey-1 bg-grey-0/70 p-3 dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ir,{label:"Filter",value:N,defaultValue:"all",onChange:P,options:Gs}),e.jsx(Ir,{label:"Sort",value:w,defaultValue:"newest",onChange:U,options:qs})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx($r,{size:16,"aria-hidden":"true",className:"absolute left-3 top-1/2 -translate-y-1/2 text-grey-3"}),e.jsx("input",{type:"text","aria-label":"Search generated pages",placeholder:"Search generated pages...",value:S,onChange:C=>k(C.target.value),className:"w-full rounded-xl border border-grey-1 bg-white py-2 pl-9 pr-9 text-sm text-grey-6 placeholder:text-grey-3 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20 dark:border-grey-2 dark:bg-grey-1"}),S&&e.jsx("button",{type:"button","aria-label":"Clear generated page search",onClick:()=>k(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-grey-3 hover:text-grey-5",children:e.jsx(fe,{size:14,"aria-hidden":"true"})})]})]}),le.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-grey-2 py-8 text-center",children:[e.jsx(st,{size:24,className:"mx-auto mb-2 text-grey-3"}),e.jsx("p",{className:"text-sm font-medium text-grey-4",children:l&&$>0?"No generated pages match those filters":l?"No generated pages yet":"No pages shared yet"}),e.jsx("p",{className:"mt-1 text-xs text-grey-3",children:l?$>0?"Adjust the search or filter controls to see more generated pages.":i?"Generated pages and s
1ource-backed updates will appear here as Walter helps collect the project.":a?"Schedule a Walter call so your generated pages can appear here when they are ready.":"Generated pages will appear here as the Memory Project grows.":a?"Add pages from your library to start this group library.":"Pages shared with this group will appear here."})]}):e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:"grid gap-3 sm:grid-cols-2",children:le.map(C=>{const L=er(C)?C:m.find(se=>se.id===C.id),H=i||L?.viewerCanEdit===!0,v=L?.isGroupCanonicalPage===!0,D=v?"Hide from library":"Remove from group";return e.jsxs(F.div,{variants:ar,whileHover:{y:-2,transition:{duration:.15}},className:"group/card relative",children:[L?e.jsx(As,{page:L,slug:r,linkSearch:X,getCollectionsForPage:Q,hideDestinationLabel:l}):e.jsx("div",{className:"rounded-2xl border border-grey-1 bg-white p-5 transition-shadow hover:shadow-md dark:border-grey-2 dark:bg-grey-1",children:e.jsxs(Et,{to:"/$slug/pages/$pageId",params:{slug:r,pageId:C.id},search:X,className:"block",children:[e.jsx("h4",{className:"font-primary text-lg font-bold",children:C.title}),e.jsx("p",{className:"mt-2 line-clamp-3 text-sm leading-relaxed text-grey-4",children:C.preview}),e.jsx("span",{className:"mt-3 inline-block text-xs text-grey-3",children:C.updatedAt})]})}),a&&H&&e.jsx("button",{type:"button",onClick:()=>_(C.id,{isGroupCanonicalPage:v}),className:"absolute top-2 right-2 z-20 flex h-7 w-7 items-center justify-center rounded-full bg-white/90 text-grey-4 opacity-100 shadow-sm transition-opacity hover:bg-red-50 hover:text-red-500 focus-visible:opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 sm:group-focus-within/card:opacity-100 sm:focus-visible:opacity-100 dark:bg-grey-2 dark:hover:bg-red-500/10","aria-label":D,title:D,children:e.jsx(fe,{size:13})})]},C.id)})})]})}const Bi={Uploaded:{label:"Queued",icon:Bt,color:"text-amber-500",bg:"bg-amber-50 dark:bg-amber-500/10"},Processing:{label:"Processing",icon:Xe,color:"text-primary",bg:"bg-primary-light dark:bg-primary/10",spin:!0},Ready:{label:"Ready",icon:cr,color:"text-emerald-600 dark:text-emerald-400",bg:"bg-emerald-50 dark:bg-emerald-500/10"},Failed:{label:"Failed",icon:Qo,color:"text-red-500 dark:text-red-400",bg:"bg-red-50 dark:bg-red-500/10"}};function Ki(t){return t.startsWith("image/")?fi:t.startsWith("video/")?ji:t.startsWith("audio/")?Yo:or}function Gi(t){return t<1024*1024?`${(t/1024).toFixed(0)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function qi(t){return Bi[t.processingStatus]??{label:t.processingStatus||"Uploaded",icon:or,color:"text-grey-4",bg:"bg-grey-1 dark:bg-grey-2"}}function ds({groupId:t,slug:r,canManageLibrary:s,memoryProjectId:a,memoryProjectPhase:i,prefetchedFiles:l,prefetchedSourceRequestResult:d,usePrefetchedSourceData:m=!1,memoryProjectOverview:p}){const{user:f}
1=hs(),j=o.useRef(null),[y,b]=o.useState("idle"),[g,h]=o.useState(null),[x,S]=o.useState(!1),[k,N]=o.useState(null),[P,w]=o.useState(new Set),[U,q]=o.useState(new Set),[K,Z]=o.useState(null),[E,B]=o.useState(""),le=be(O.files.listByGroupWithUrls,m?"skip":{groupId:t}),$=(m?l:le)??[],X=be(O.memoryProjectSources.listSourceRequests,m||!a?"skip":{memoryProjectId:a}),G=m?d:X,ae=ne(O.files.generateUploadUrl),ee=ne(O.files.create),Q=ne(O.files.removeFromGroup),M=ne(O.files.reprocess),_=ne(O.memoryProjectSources.reopenSourceRequest),T=o.useMemo(()=>$.find(c=>c._id===g)??null,[$,g]),z=o.useMemo(()=>$.find(c=>c._id===k)??null,[$,k]),C=a!==void 0,L=G?.requests??[],H=L.filter(c=>c.status!=="cancelled"),v=H.filter(c=>c.status==="open"),D=H.filter(c=>c.status==="completed"),se=G!==void 0,de=G?.role==="contributor"?"What the project still needs":"Requested source materials",ze=o.useMemo(()=>new Map(L.map(c=>[c._id,c])),[L]),ke=C&&i!==void 0&&i!=="capture_open",Pe=s&&!ke,Ne=G?.role==="owner";o.useEffect(()=>{E&&(v.some(c=>c._id===E)||B(""))},[v,E]);const ce=o.useCallback(async c=>{if(!f?.id||!Pe)return;b("uploading");let Y=0;for(const ie of Array.from(c))try{const ue=await Po(ie).catch(()=>ie),Se=await ae(),Ee=await fetch(Se,{method:"POST",headers:{"Content-Type":ue.type||"application/octet-stream"},body:ue});if(!Ee.ok)continue;const{storageId:Ke}=await Ee.json();await ee({storageId:Ke,ownerId:f.id,purpose:"Source",originalFilename:ue.name,contentType:ue.type||"application/octet-stream",sizeBytes:ue.size,groupId:t,...a?{memoryProjectId:a}:{},...E?{sourceRequestId:E}:{}}),Y++}catch(ue){console.error("[groups] Group media upload failed:",ue)}b(Y>0?"done":"error"),Y>0&&B(""),setTimeout(()=>b("idle"),2500)},[Pe,ee,ae,t,a,E,f?.id]),oe=o.useCallback(async c=>{w(Y=>new Set(Y).add(c));try{await M({fileId:c})}catch(Y){console.error("[groups] Group media reprocess failed:",Y)}finally{setTimeout(()=>{w(Y=>{const ie=new Set(Y);return ie.delete(c),ie})},1e3)}},[M]),te=o.useCallback(async()=>{if(k)try{await Q({fileId:k,groupId:t})}catch(c){console.error("[groups] Group media remove failed:",c)}finally{N(null),g===k&&(h(null),S(!1))}},[k,t,Q,g]),re=o.useCallback(async c=>{Z(null),q(Y=>new Set(Y).add(c));try{await _({sourceRequestId:c})}catch(Y){console.error("[groups] Source request reopen failed:",Y),Z("We could not reopen that source request. Please try again.")}finally{q(Y=>{const ie=new Set(Y);return ie.delete(c),ie})}},[_]),me=C?"Upload source":"Add media",Ce=C?"No source media uploaded yet":"No media added yet",he=C?ke?"The capture window is closed. Sources already added to the project will appear here.":s?"Upload photos, videos, audio, notes, links, or documents that could help this Memory Project.":"Uploaded photos, videos, audio, notes, links, and documents will appear here.":s?"Add photos, videos, recordings, or documents to this group.":"Media shared with this group will appear here.";return e.jsxs(F.div,{initial:"hidden",animate:"show",variants:Ue,"data-testid":C?"memory-project-sources-layout":void 0,className:C?"grid gap-5 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)] lg:items-start":void 0,children:[e.jsx("input",{ref:j,type:"file",multiple:!0,accept:"image/*,image/heic,image/heif,video/*,audio/*,application/pdf,.doc,.docx,.txt",className:"hidden",onChange:c=>{c.target.files?.length&&ce(c.target.files),c.target.value=""}}),e.jsxs("section",{"data-testid":C?"memory-project-uploaded-sources-container":void 0,className:C?"min-w-0 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1":"",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4",children:[C?e.jsxs("div",{className:"flex items-center gap-2 text-sm font-bold uppercase text-grey-7",children:[e.jsx(br,{size:18,className:"text-primary","aria-hidden":"true"}),"Sources"]}):e.jsxs("h3",{className:"flex items-center gap-2 font-primary text-xl font-bold text-grey-7",children:[e.jsx(br,{size:14,"aria-hidden":"true"}),"Media",$.length>0&&e.jsx("span",{className:"rounded-full bg-grey-1 px-2 py-0.5 text-[10px] font-medium text-grey-4 dark:bg-grey-2",children:$.length})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto
1sm:flex-row sm:items-center",children:[Pe&&C&&v.length>0&&e.jsx("label",{className:"sr-only",htmlFor:"source-request-select",children:"Tag upload to a request"}),Pe&&C&&v.length>0&&e.jsxs("select",{id:"source-request-select",value:E,onChange:c=>B(c.target.value),className:"h-10 w-full rounded-lg border border-grey-1 bg-white px-3 text-xs font-medium text-grey-6 outline-none transition-colors hover:border-grey-2 focus:border-primary dark:border-grey-2 dark:bg-grey-1 sm:w-[220px]",children:[e.jsx("option",{value:"",children:"Optional: tag to request"}),v.map(c=>e.jsx("option",{value:c._id,children:c.title},c._id))]}),Pe&&e.jsxs(F.button,{type:"button",whileHover:{scale:1.03},whileTap:{scale:.97},disabled:y==="uploading",onClick:()=>j.current?.click(),className:C?"inline-flex h-10 w-full items-center justify-center gap-2 whitespace-nowrap rounded-lg bg-memory-cta px-4 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 disabled:opacity-60 sm:w-auto":"inline-flex items-center justify-center gap-1.5 whitespace-nowrap rounded-full bg-primary px-4 py-1.5 text-xs font-medium text-white shadow-sm disabled:opacity-60 sm:w-auto",children:[y==="uploading"?e.jsx(Xe,{size:C?16:12,className:"animate-spin"}):e.jsx(at,{size:C?16:12}),y==="uploading"?"Uploading":me]})]})]}),C&&p&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h2",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:p.title}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:p.body})]}),C&&ke&&e.jsx("div",{className:"mt-5 rounded-xl border border-grey-1 bg-grey-0/70 p-4 text-sm leading-6 text-grey-5 dark:border-grey-2 dark:bg-grey-0",children:"The capture window is closed. Existing source files remain available, but new uploads are disabled."}),C&&e.jsxs("div",{className:"mt-6 flex items-center gap-2 border-t border-grey-1 pt-5 dark:border-grey-2",children:[e.jsx("h3",{className:"text-sm font-bold uppercase text-grey-7",children:"Uploaded sources"}),$.length>0&&e.jsx("span",{className:"rounded-full bg-grey-1 px-2 py-0.5 text-[10px] font-medium text-grey-4 dark:bg-grey-2",children:$.length})]}),$.length===0?e.jsxs("div",{className:`${C?"mt-4":""} rounded-xl border-2 border-dashed border-grey-2 py-8 text-center`,children:[e.jsx(br,{size:24,className:"mx-auto mb-2 text-grey-3"}),e.jsx("p",{className:"text-sm font-medium text-grey-4",children:Ce}),e.jsx("p",{className:"mt-1 text-xs text-grey-3",children:he})]}):e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:C?"mt-4 columns-2 gap-3 space-y-3 sm:columns-3 lg:columns-2 xl:columns-3":"grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:$.map(c=>{const Y=Ki(c.contentType),ie=c.sourceRequestId?ze.get(c.sourceRequestId):void 0,ue=qi(c),Se=ue.icon,Ee=c.derivedPages?.length??0,Ke=c.contentType.startsWith("image/")&&c.url,Me=c.contentType.startsWith("video/")&&c.url;return C?e.jsxs(F.div,{variants:ar,whileHover:{y:-2,transition:{duration:.15}},className:"group/card relative mb-3 break-inside-avoid overflow-hidden rounded-xl bg-grey-1 shadow-sm ring-1 ring-grey-1 transition-shadow hover:shadow-md dark:bg-grey-2 dark:ring-grey-2",children:[e.jsx("button",{type:"button",onClick:()=>h(c._id),className:"block w-full","aria-label":`Open source file ${c.originalFilename??"Untitled file"}`,children:Ke?e.jsx("img",{src:c.url??"",alt:"",className:"h-auto w-full object-cover",loading:"lazy"}):Me?e.jsx("video",{src:c.url??"",className:"aspect-[4/5] w-full object-cover",muted:!0,preload:"metadata"}):e.jsxs("div",{className:"flex aspect-[4/5] w-full flex-col items-center justify-center gap-3 bg-grey-1 px-3 text-center dark:bg-grey-2",children:[e.jsx(Y,{size:28,className:"text-grey-4","aria-hidden":"true"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"line-clamp-2 break-words text-xs font-semibold leading-snug text-grey-6",children:c.originalFilename??"Untitled file"}),e.jsx("p",{className:"mt-1 text-[10px] font-medium uppercase tracking-wide text-grey-4",children:(c.contentType.split("/").pop()??"file").toUpperCase()})]})]})}),c.canRemoveFromGroup&&e.jsx("button",{type:"button",onClick:()=>N(c._id),className:"absolute right-2 top-2 rounded-full bg-black/40 p-1.5 text-white opacity-100 backdrop-blur transition-opacity hover:bg-black/60 focus-visible:opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 sm:group-focus-within/card:opacity-100","aria-label":"Remove from group",title:"Remove from group",children:e.jsx(gt,{size:14})})]},c._id):e.jsxs(F.div,{variants:ar,whileHover:{y:-2,transition:{duration:.15}},className:"group/card relative overflow-hidden rounded-xl border border-grey-1 bg-white transition-shadow hover:shadow-md dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("button",{type:"button",onClick:()=>h(c._id),className:"block w-full text-left",children:[e.jsx("div",{className:"aspect-video bg-grey-1 dark:bg-grey-2",children:c.contentType.startsWith("image/")&&c.url?e.jsx("img",{src:c.url,alt:c.originalFilename??"",className:"h-full w-full object-cover"}):c.contentType.startsWith("video/")&&c.url?e.jsx("video",{src:c.url,className:"h-full w-full object-cover",muted:!0,preload:"metadata"}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(Y,{size:28,className:"text-grey-4"})})}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"truncate text-sm font-medium text-grey-7",children:c.originalFilename??"Untitled file"}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[10px] font-semibold ${ue.bg} ${ue.color}
1`,children:[e.jsx(Se,{size:10,className:"spin"in ue&&ue.spin?"animate-spin":""}),ue.label]}),Ee>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-primary-light px-2 py-0.5 text-[10px] font-semibold text-primary",children:[e.jsx(st,{size:10,"aria-hidden":"true"}),Ee," ",Ee===1?"page":"pages"]})]}),e.jsxs("p",{className:"mt-2 text-xs text-grey-4",children:[Gi(c.sizeBytes)," · ",c.contentType]}),ie&&e.jsx("p",{className:"mt-2 inline-flex max-w-full items-center rounded-full bg-memory-light px-2 py-0.5 text-[10px] font-semibold text-grey-6",children:e.jsxs("span",{className:"truncate",children:["Tagged: ",ie.title]})})]})]}),c.canRemoveFromGroup&&e.jsx("button",{type:"button",onClick:()=>N(c._id),className:"absolute right-2 top-2 rounded-full bg-black/40 p-1.5 text-white opacity-100 backdrop-blur transition-opacity hover:bg-black/60 focus-visible:opacity-100 sm:opacity-0 sm:group-hover/card:opacity-100 sm:group-focus-within/card:opacity-100","aria-label":"Remove from group",title:"Remove from group",children:e.jsx(gt,{size:14})})]},c._id)})}),y==="done"&&e.jsx("p",{className:"mt-3 text-xs font-medium text-emerald-600 dark:text-emerald-400",children:C?"Source uploaded to the project.":"Media added to the group."}),y==="error"&&e.jsx("p",{className:"mt-3 text-xs font-medium text-red-500 dark:text-red-400",children:C?"Source upload failed.":"Media upload failed."})]}),C&&se&&e.jsxs("section",{"data-testid":"memory-project-source-requests-container",className:"min-w-0 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1 lg:sticky lg:top-24",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:de}),e.jsxs("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:[D.length," collected / ",H.length," requested"]})]}),H.length===0?e.jsxs("div",{className:"mt-4 rounded-xl border border-dashed border-grey-2 bg-grey-0/60 px-4 py-5 text-sm leading-relaxed text-grey-5 dark:bg-grey-0",children:[e.jsx("p",{className:"font-medium text-grey-6",children:"No requested source materials yet"}),e.jsx("p",{className:"mt-1",children:"Photos, videos, and files to collect from the guide will appear here when Walter or the Owner adds them."})]}):e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-relaxed text-grey-5",children:"Have one of these sources? Sharing even one can help. Everyone is contributing, so you do not need to complete the whole list yourself."}),K&&e.jsx("p",{className:"mt-3 rounded-lg bg-red-50 px-3 py-2 text-sm font-medium text-red-600 dark:bg-red-950/30 dark:text-red-300",children:K}),H.length>0&&e.jsx("div",{className:"mt-4 grid gap-3",children:H.map(c=>{const Y=c.status==="completed",ie=U.has(c._id);return e.jsxs("div",{className:"flex flex-col gap-3 rounded-xl border border-grey-1 bg-grey-0/60 p-4 dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"flex min-w-0 gap-3",children:[Y?e.jsx(cr,{size:18,className:"mt-0.5 shrink-0 text-memory"}):e.jsx(ai,{size:18,className:"mt-0.5 shrink-0 text-grey-3"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-grey-7",children:c.title}),c.details&&e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-grey-5",children:c.details}),c.attachedFiles&&c.attachedFiles.length>0&&e.jsxs("p",{className:"mt-1 text-xs text-grey-4",children:[c.attachedFiles.length," ",c.attachedFiles.length===1?"source":"sources"," attached"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 pl-8",children:[e.jsx("span",{className:`rounded-full px-2 py-1 text-[10px] font-semibold ${Y?"bg-memory-light text-grey-6":"bg-grey-1 text-grey-5 dark:bg-grey-2"}`,children:Y?"Complete":"Still needed"}),Ne&&c.status==="open"&&e.jsx("span",{className:"min-w-0 flex-1 text-xs leading-snug text-grey-4",children:"Upload and tag a file to complete"}),Ne&&!ke&&c.status==="completed"&&e.jsxs("button",{type:"button",onClick:()=>{re(c._id)},disabled:ie,className:"inline-flex items-center gap-1 rounded-full border border-grey-2 px-3 py-1 text-xs font-medium text-grey-6 transition-colors hover:border-memory hover:text-memory disabled:cursor-not-allowed disabled:opacity-60",children:[ie?e.jsx(Xe,{size:12,className:"animate-spin"}):e.jsx(ys,{size:12}),ie?"Saving":"Reopen"]})]})]},c._id)})})]}),e.jsx(lt,{children:T&&e.jsx(Ho,{viewFile:T,slug:r,viewerFullscreen:x,setVie
1werFullscreen:S,onClose:()=>{h(null),S(!1)},reprocessFile:oe,reprocessingIds:P,setConfirmDeleteId:c=>N(c),canReprocess:T.canReprocess===!0,canDelete:T.canRemoveFromGroup===!0,deleteLabel:"Remove"})}),e.jsx(lt,{children:z&&e.jsx(F.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-[60] flex items-center justify-center bg-black/50 p-4",onClick:()=>N(null),children:e.jsxs(F.div,{initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0},className:"w-full max-w-sm rounded-2xl bg-white p-5 shadow-xl dark:bg-grey-1",onClick:c=>c.stopPropagation(),children:[e.jsx("h4",{className:"font-primary text-lg font-bold text-grey-7",children:C?"Remove source?":"Remove media?"}),e.jsx("p",{className:"mt-2 text-sm text-grey-4",children:"This removes the file from this group. It does not delete another member's original file."}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:()=>N(null),className:"rounded-full border border-grey-2 px-4 py-2 text-sm font-medium text-grey-6 hover:bg-grey-1",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>{te()},className:"rounded-full bg-red-500 px-4 py-2 text-sm font-medium text-white hover:bg-red-600",children:"Remove"})]})]})})})]})}function Wi({currentEmoji:t,currentName:r,isOwner:s,isMemoryProject:a=!1,isMemoryProjectContributor:i=!1,groupName:l,startEditing:d,notificationsOn:m,onToggleNotifications:p,onDeleteGroup:f,onLeaveGroup:j}
1){const[y,b]=o.useState(!1),[g,h]=o.useState(!1),[x,S]=o.useState(null),k=async(N,P)=>{if(!x){S(N);try{await P(),S(null),N==="delete"?h(!1):b(!1)}catch{S(null)}}};return e.jsxs(F.section,{id:"group-settings",tabIndex:-1,"aria-labelledby":"group-settings-heading",initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.18,ease:"easeOut"},children:[e.jsxs("h3",{id:"group-settings-heading",className:"mb-4 flex items-center gap-2 text-sm font-semibold text-grey-6",children:[e.jsx(Ma,{size:14}),"Settings"]}),e.jsxs("div",{className:"rounded-xl border border-grey-1 bg-white dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg",children:t}),e.jsx("span",{className:"text-sm font-medium text-grey-7",children:r})]}),s&&e.jsx("button",{type:"button",onClick:d,className:"text-xs font-medium text-primary transition-colors hover:text-primary/80","aria-label":"Edit group name and icon",children:e.jsx(vr,{size:14})})]}),e.jsx("div",{className:"border-t border-grey-1 dark:border-grey-2"}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ia,{size:16,className:"text-grey-4"}),e.jsx("span",{className:"text-sm font-medium text-grey-7",children:"Notifications"})]}),e.jsx("button",{type:"button",onClick:p,className:`relative h-6 w-10 rounded-full transition-colors ${m?"bg-primary":"bg-grey-2"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 h-5 w-5 rounded-full bg-white shadow transition-transform dark:bg-grey-0 ${m?"translate-x-4":"translate-x-0"}`})})]}),!s&&e.jsx("div",{className:"border-t border-grey-1 px-4 py-3 dark:border-grey-2",children:y?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-grey-5",children:i?`Leave "${l}"? You will lose access to this Memory Project, and stories and sources you added will be removed from the group.`:a?`Leave "${l}"? You will lose access to this Memory Project.`:`Leave "${l}"? You'll lose access to shared pages.`}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k("leave",j),disabled:x==="leave","aria-busy":x==="leave",className:"rounded-full bg-red-500 px-4 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-70",children:x==="leave"?"Leaving...":"Leave"}),e.jsx("button",{type:"button",onClick:()=>b(!1),disabled:x==="leave",className:"rounded-full bg-grey-1 px-4 py-1.5 text-sm font-medium text-grey-5 transition-colors hover:bg-grey-2 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-grey-2 dark:hover:bg-grey-3",children:"Cancel"})]})]}):e.jsxs("button",{type:"button",onClick:()=>b(!0),className:"flex items-center gap-3 text-sm font-medium text-red-500 transition-colors hover:text-red-600",children:[e.jsx(Pa,{size:16}),"Leave group"]})}),s&&e.jsx("div",{className:"border-t border-grey-1 px-4 py-3 dark:border-grey-2",children:g?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm text-grey-5",children:['Move "',l,'" to trash? You can restore it later.']}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>k("delete",f),disabled:x==="delete","aria-busy":x==="delete",className:"rounded-full bg-red-500 px-4 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-600 disabled:cursor-not-allowed disabled:opacity-70",children:x==="delete"?"Moving...":"Move to trash"}),e.jsx("button",{type:"button",onClick:()=>h(!1),disabled:x==="delete",className:"rounded-full bg-grey-1 px-4 py-1.5 text-sm font-medium text-grey-5 transition-colors hover:bg-grey-2 disabled:cursor-not-allowed disabled:opacity-70 dark:bg-grey-2 dark:hover:bg-grey-3",children:"Cancel"})]})]}):e.jsxs("button",{type:"button",onClick:()=>h(!0),className:"flex items-center gap-3 text-sm font-medium text-red-500 transition-colors hover:text-red-600",children:[e.jsx(gt,{size:16}),"Delete group"]})})]})]})}function Ba(t,r){const s=[];for(const[a,i]of t.entries()){const l=Dr(i,a);s.push({collectionId:r,id:l,item:i});const d=Fr(i);d&&i.itemType==="subcollection"&&s.push(...Ba(i.collection?.items??[],d))}return s}function Vi(t){const r=new Map(t.map(a=>[a.id,a])),s=new Map;for(const a of t){const i=s.get(a.collectionId)??[];i.push(a.id),s.set(a.collectionId,i)}return{entryById:r,idsByCollectionId:s}}function Hi(t,r,s,a,i){if(!i||a===i)return{kind:"none"};const l=r.get(a),d=r.get(i);if(!l||!d)return{kind:"none"};const m=Fr(d.item);if(m&&l.collectionId===m)return{kind:"none"};if(m&&l.collectionId!==m&&l.item.itemType!=="subcollection"){const j=s.get(m)??[];return{kind:"reparent",itemId:a,targetCollectionId:m,targetIndex:j.length}}if(l.collectionId===d.collectionId){const j=s.get(l.collectionId)??[],y=j.indexOf(a),b=j.indexOf(i);return y<0||b<0||y===b?{kind:"none"}:{kind:"reorder",targetCollectionId:l.collectionId,itemIds:Ta(j,y,b)}}const p=s.get(d.collectionId)??[],f=Math.max(0,p.indexOf(i));return{kind:"move",itemId:a,targetCollectionId:d.collectionId,targetIndex:f}}function Fr(t){if(t.itemType==="subcollection")return t.childCollectionId?String(t.childCollectionId):t.collection?.collectionId}function Dr(t,r){return"_id"in t&&t._id?String(t._id):t.itemType==="page"&&t.pageId?`story:${String(t.pageId)}`:t.itemType==="source"&&t.fileId?`source:${String(t.fileId)}`:t.itemType==="quote"&&t.quoteId?`quote:${String(t.quoteId)}`:(t.itemType==="quote"||t.itemType==="audio")&&t.callId&&t.transcriptText?`transcript:${String(t.callId)}:${t.itemType}:${t.transcriptStartMs??r}`:t.itemType==="subcollection"&&t.childCollectionId?`subcollection:${String(t.childCollectionId)}`:`organizer-item-${r}`}function Ka(t){return t.itemType==="page"?"Story":t.itemType==="source"?"Source":t.itemType==="quote"?"Quote":t.itemType==="audio"?"Audio":t.itemType==="subcollection"?"Subcollection":"Story"}function Ga(t){return t.itemType==="page"||t.itemType==="source"||t.itemType==="quote"||t.itemType==="audio"}function qa(t){if(t.itemType==="page"){const r=t.page;return r?.overview??r?.title??"Untitled story"}if(t.itemType==="source")return t.file?.originalFilename??"Untitled source";if(t.itemType==="quote"){if("transcriptText"in t&&typeof t.transcriptText=="string")return Ar(t.transcriptText,120);const r=t.quote;return Ar(r?.text??"Saved quote",120)}return t.itemType==="audio"?Ar("transcriptText"in t?t.transcriptText:void 0,120)??"Audio section":t.itemType==="subcollection"?t.collection?.name??"Untitled subcollection":"Collection item"}function Yi(t){if(t.itemType==="page"){const r=t.page;return Ar(r?.preview??r?.summary??r?.content)}if(t.itemType==="source"){const r=t.file;return t.sourceRequest?.title??r?.contentType??cs(r?.sizeBytes)}if(t.itemType==="quote"){if("transcriptStartMs"in t&&typeof t.transcriptStartMs=="number")return`Session transcript at ${jr(t.transcriptStartMs)}`;const r=t.quote;return r?.pageTitle??r?.memberName??r?.entityName}if(t.itemType==="audio")return"transcriptStartMs"in t&&typeof t.transcriptStartMs=="number"?`Audio section from ${jr(t.transcriptStartMs)}`:"Transcript-backed audio section";if(t.itemType==="subcollection")return t.collection?.description}function Ar(t,r=180){const s=t?.trim();if(!s)return;const a=s.replace(/\s+/g," ");return a.length<=r?a:`${a.slice(0,r-3).trimEnd()}...`}function cs(t){if(t)return t<1024?`${t} B`:t<1024*1024?`${Math.round(t/1024)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`}function jr(t){const r=Math.max(0,Math.floor(t/1e3)),s=Math.floor(r/60),a=r%60;return`${s}:${a.toString().padStart(2,"0")}`}const Ys=3;function Qs(t){return{id:t._id,name:t.name,description:t.description??void 0,emoji:t.emoji??"ð",color:t.color??"#6366f1",parentId:t.parentId??void 0,pageIds:(t.pageIds??[]).map(String),quoteIds:(t.quoteIds??[]).map(String),isS
1hared:!1,sharedWith:[]}}function Wa(t){const r=new Map;for(const s of t)r.set(s.id,s);return Array.from(r.values())}function Va(t){return t==="autograph_smart"||t==="keepsake_smart_source"?"Walter generation":"Owner-created"}function Ha(t){return t.kind==="keepsake_smart_source"}function Qi(t){return t.itemCount}function Rr(t,r){return r==="page"?t.storyCount:r==="quote"?t.quoteCount:r==="audio"?"audioCount"in t?t.audioCount:0:t.sourceCount}function Ji({memoryProjectId:t,role:r,canManageCollections:s}){const a=be(O.memoryProjectCollections.listMemoryProjectCollectionSummaries,{memoryProjectId:t}),i=be(O.memoryProjectCollections.getCollectionEligibilitySummary,r==="owner"?{memoryProjectId:t}:"skip"),l=ne(O.memoryProjectCollections.createMemoryProjectCollection),[d,m]=o.useState(!1),[p,f]=o.useState(""),[j,y]=o.useState(""),[b,g]=o.useState(!1),[h,x]=o.useState(null),[S,k]=o.useState(null),N=o.useRef(null),P=be(O.memoryProjectCollections.listMemoryProjectCollections,S?{memoryProjectId:t}:"skip"),w=r==="owner"&&s,U=a===void 0||w&&i===void 0,q=a??[],K=S?q.find(M=>M.collectionId===S)??null:null,Z=S?P?.find(M=>M.collectionId===S)?.items:void 0,E=q.filter(M=>M.kind==="owner_custom"),B=q.filter(M=>M.kind!=="owner_custom"),le=!w&&E.length===0&&B.length>0,$=i?.customCollectionLimit??0,X=Math.max(0,$-E.length),G="memory-project-custom-collections-usage",ae=`${E.length} of ${$} custom collections used`;o.useEffect(()=>{d&&N.current?.focus()},[d]);const ee=async()=>{const M=p.trim();if(!(!w||!M||b||X<=0)){g(!0),x(null);try{await l({memoryProjectId:t,name:M,description:j.trim()||void 0}),f(""),y(""),m(!1)}catch(_){console.error("Failed to create Memory Project collection:",_),x(_ instanceof Error?_.message:"Failed to create collection")}finally{g(!1)}}},Q=M=>e.jsxs("aside",{"data-testid":"memory-project-smart-generations",className:`min-w-0 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1 ${M}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pt,{size:18,className:"text-primary","aria-hidden":"true"}),e.jsx("h2",{className:"text-sm font-bold uppercase text-grey-7",children:"Smart generations"})]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Walter-generated sets that can support review and keepsake creation."}),e.jsx("div",{className:"mt-4 grid gap-3",children:B.map(_=>e.jsx(Js,{collection:_,onOpen:()=>k(_.collectionId)},_.collectionId))})]});return U?e.jsxs("section",{"data-testid":"memory-project-collections-panel",className:"mb-24 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1 sm:mb-0","aria-busy":"true",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-7 w-36 animate-pulse rounded bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"h-4 w-64 max-w-full animate-pulse rounded bg-grey-1/70 dark:bg-grey-2/70"}),w&&e.jsx("div",{className:"h-3 w-32 animate-pulse rounded bg-grey-1/70 dark:bg-grey-2/70"})]}),e.jsxs("div",{className:"mt-5 grid gap-4 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"})]})]}):K?e.jsx(Xi,{collection:K,isOwner:w,items:Z,memoryProjectId:t,onBack:()=>k(null)}):e.jsxs("div",{className:"mb-24 grid gap-5 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)] sm:mb-0",children:[B.length>0&&Q("lg:hidden"),e.jsxs("section",{"data-testid":"memory-project-collections-panel",className:"rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(mr,{size:18,className:"text-primary","aria-hidden":"true"}),e.jsx("h2",{className:"text-sm font-bold uppercase text-grey-7",children:"Collections"})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("p",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:"Organize your content here"}),w&&e.jsx("span",{id:G,className:"rounded-full bg-grey-1 px-2 py-0.5 text-[11px] font-semibold text-grey-5 dark:bg-grey-2",children:ae})]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:w?"Regroup and organize your stories, sources, and saved quotes into collection folders. Share them with contributors or use them to create keepsakes.":"Review the story, source, and quote sets the Owner has shared from this Memory Project."})]})]}),w&&e.jsxs(F.button,{type:"button",whileHover:X>0?{scale:1.02}:void 0,whileTap:X>0?{scale:.98}:void 0,disabled:X<=0,"aria-describedby":X<=0?G:void 0,onClick:()=>{x(null),m(!0)},className:"inline-flex h-10 w-full shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-full bg-memory-cta px-4 text-sm font-semibold text-white shadow-sm transition-opacity hover:bg-memory-cta/90 disabled:cursor-not-allowed disabled:opacity-45 sm:w-auto",children:[e.jsx(at,{size:16,"aria-hidden":"true"}),"New collection"]})]}),h&&e.jsx("div",{role:"alert",className:"mt-5 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-900/10 dark:text-red-300",children:h}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[!w&&q.length===0&&e.jsxs("article",{className:"rounded-2xl border border-dashed border-grey-2 bg-white p-5 transition-shadow hover:shadow-md dark:border-grey-2 dark:bg-grey-0",children:[e.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-lg bg-white text-grey-4 dark:bg-grey-1",children:e.jsx(pt,{size:21,"aria-hidden":"true"})}),e.jsx("h3",{className:"font-primary text-xl text-grey-7",children:"Collections will appear here"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Finished story sets will appear here when they are available."})]}),le&&e.jsxs("article",{className:"rounded-2xl border border-dashed border-primary/20 bg-primary-light/30 p-5 transition-shadow hover:shadow-md dark:border-primary/30 dark:bg-primary/10",children:[e.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-lg bg-primary text-white shadow-sm",children:e.jsx(pt,{size:21,"aria-hidden":"true"})}),e.jsx("h3",{className:"font-primary text-xl text-grey-7",children:"Walter-generated collections are ready"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Open them from Smart generations."})]}),E.map(M=>e.jsx(Js,{collection:M,onOpen:()=>k(M.collectionId)},M.collectionId)),w&&d&&X>0&&e.jsxs("article",{className:"rounded-2xl border border-primary/20 bg-white p-5 transition-shadow hover:shadow-md dark:border-primary/30 dark:bg-grey-0",children:[e.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-lg bg-primary-light text-primary",children:e.jsx(qr,{size:21,"aria-hidden":"true"})}),e.jsx("h3",{className:"font-primary text-xl text-grey-7",children:"New custom collection"}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("input",{ref:N,type:"text",value:p,onChange:M=>f(M.target.value),placeholder:"Collection name","aria-label":"Memory Project collection name",className:"w-full rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm text-grey-7 outline-none focus:border-primary dark:border-grey-3 dark:bg-grey-1"}),e.jsx("textarea",{value:j,onChange:M=>y(M.target.value),placeholder:"Short review purpose","aria-label":"Memory Project collection description",className:"min-h-20 w-full resize-none rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm text-grey-7 outline-none focus:border-primary dark:border-grey-3 dark:bg-grey-1"})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{m(!1),f(""),y("")},className:"rounded-lg border border-grey-2 px-3 py-2 text-sm font-semibold text-grey-5 dark:border-grey-3",children:"Cancel"}),e.jsxs("button",{type:"button",disabled:!p.trim()||b,onClick:ee,className:"inline-flex flex-1 items-center justify-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45",children:[b&&e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}),"Create"]})]})]}),w&&Array.from({length:d?Math.max(0,X-1):X}
1,(M,_)=>e.jsx(mn,{onCreate:()=>{x(null),m(!0)}},`memory-project-collection-slot-${_+1}`))]})]}),B.length>0&&Q("hidden lg:block")]})}function Js({collection:t,onOpen:r}){const s=Qi(t),a=Rr(t,"page"),i=Rr(t,"source"),l=Rr(t,"quote"),d=Rr(t,"audio"),m=t.kind==="autograph_smart"||Ha(t);return e.jsxs(F.button,{type:"button",onClick:r,whileHover:{y:-3,transition:{duration:.2}},className:`flex h-full flex-col rounded-2xl border p-5 text-left transition-shadow hover:shadow-md ${m?"border-primary/25 bg-primary-light/45 dark:border-primary/35 dark:bg-primary/10":"border-grey-1 bg-white dark:border-grey-2 dark:bg-grey-0"}`,children:[e.jsx("div",{className:`mb-4 flex h-11 w-11 items-center justify-center rounded-lg ${m?"bg-primary text-white shadow-sm":"bg-white text-primary dark:bg-grey-1"}`,children:m?e.jsx(pt,{size:21,"aria-hidden":"true"}):e.jsx(mr,{size:21,"aria-hidden":"true"})}),e.jsx("h3",{className:"font-primary text-xl text-grey-7",children:t.name}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:t.description||"A review set for finished story pages and related project media."}),e.jsxs("div",{className:"mt-auto flex items-center justify-between border-t border-grey-1 pt-4 text-sm dark:border-grey-2",children:[e.jsxs("span",{className:"font-semibold text-grey-6",children:[s," ",s===1?"item":"items"]}),e.jsx("span",{className:`rounded-md px-2 py-1 text-xs font-semibold ${m?"bg-cta text-white":"bg-white text-grey-5 dark:bg-grey-1"}`,children:Va(t.kind)})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-xs font-semibold text-grey-4",children:[e.jsxs("span",{className:"rounded-full bg-white px-2 py-1 dark:bg-grey-1",children:[a," ",a===1?"story":"stories"]}),e.jsxs("span",{className:"rounded-full bg-white px-2 py-1 dark:bg-grey-1",children:[i," ",i===1?"source":"sources"]}),e.jsxs("span",{className:"rounded-full bg-white px-2 py-1 dark:bg-grey-1",children:[l," ",l===1?"quote":"quotes"]}),d>0&&e.jsxs("span",{className:"rounded-full bg-white px-2 py-1 dark:bg-grey-1",children:[d," audio"]})]})]})}function Xi({collection:t,isOwner:r,items:s,memoryProjectId:a,onBack:i}){const l=ne(O.memoryProjectCollections.updateMemoryProjectCollection),d=ne(O.memoryProjectCollections.archiveMemoryProjectCollection),m=ne(O.memoryProjectCollections.publishMemoryProjectCollection),p=ne(O.memoryProjectCollections.hideMemoryProjectCollection),f=ne(O.memoryProjectCollections.requestAutographSmartCollectionGeneration),j=ne(O.memoryProjectCollections.resetAutographSmartCollection),y=ne(O.memoryProjectCollections.addMemoryProjectCollectionItem),b=ne(O.memoryProjectCollections.moveMemoryProjectCollectionItem),g=ne(O.memoryProjectCollections.removeMemoryProjectCollectionItem),h=ne(O.memoryProjectCollections.reorderMemoryProjectCollectionItems),x=ne(O.memoryProjectCollections.suppressAutographSmartCollectionItem),S=ne(O.memoryProjectCollections.updateTranscriptCollectionItemKind),k=ne(O.memoryProjectCollections.createMemoryProjectCollection),[N,P]=o.useState(!1),[w,U]=o.useState(t.name),[q,K]=o.useState(t.description??""),[Z,E]=o.useState(!1),[B,le]=o.useState(!1),[$,X]=o.useState(""),[G,ae]=o.useState(!1),[ee,Q]=o.useState(null),[M,_]=o.useState(!1),[T,z]=o.useState(!1),[C,L]=o.useState(!1),[H,v]=o.useState(!1),[D,se]=o.useState(String(t.collectionId)),[de,ze]=o.useState(t.name),[ke,Pe]=o.useState("stories"),[Ne,ce]=o.useState(null),oe=o.useRef(null),te=o.useRef(null),re=o.useRef(null),me=o.useRef(null),Ce=o.useRef(null),he=o.useRef(null),c=o.useRef(null),Y=o.useRef(null),ie=o.useRef(null),ue=be(O.memoryProjectCollections.listMemoryProjectCollectionContentCandidates,r&&H?{collectionId:D}:"skip"),Se=t.kind==="owner_custom",Ee=t.kind==="autograph_smart",Ke=Ha(t),Me=r&&!Ke,Nt=r&&t.status!=="published"&&t.status!=="pending_generation"&&t.status!=="generation_failed"&&!Ke,He=r&&t.status==="published";o.useEffect(()=>{U(t.name),K(t.description??""),P(!1),ce(null),_(!1),z(!1),L(!1),v(!1),se(String(t.collectionId)),ze(t.name),E(!1),le(!1),X(""),Pe("stories")},[t.collectionId]),o.useEffect(()=>{N||(U(t.name),K(t.description??""))},[t.description,t.name,N]),o.useEffect(()=>{M&&Ce.current?.focus()},[M]),o.useEffect(()=>{T&&c.current?.focus()},[T]),o.useEffect(()=>{C&&ie.current?.focus()},[C]),o.useEffect(()=>{Z&&re.current?.focus()},[Z]),o.useEffect(()=>{!B||Z||G||(te.current?.focus(),le(!1))},[Z,B,G]),o.useEffect(()=>{if(!H&&!M&&!T&&!C&&!Z)return;const V=pe=>{pe.key==="Escape"&&(H&&Qe(),M&&Ye(),T&&ot(),C&&Ve(),Z&&Le())};return document.addEventListener("keydown",V),()=>document.removeEventListener("keydown",V)},[H,M,T,C,Z]);const tt=async()=>
1{if(!r||!Se||G)return;const V=w.trim();if(!V){ce("Collection name is required");return}ae(!0),ce(null);try{await l({collectionId:t.collectionId,name:V,description:q.trim()||void 0}),P(!1)}catch(pe){console.error("Failed to update Memory Project collection:",pe),ce(pe instanceof Error?pe.message:"Failed to update collection")}finally{ae(!1)}},Oe=async(V,pe)=>{if(!G){ae(!0),ce(null);try{await V()}catch(ye){console.error(pe,ye),ce(ye instanceof Error?ye.message:pe)}finally{ae(!1)}}},ct=async()=>{if(!G){ae(!0),ce(null);try{await d({collectionId:t.collectionId}),_(!1),i()}catch(V){console.error("Failed to delete collection",V),ce(V instanceof Error?V.message:"Failed to delete collection")}finally{ae(!1)}}},Ye=()=>{_(!1),me.current?.focus()},ot=()=>{z(!1),he.current?.focus()},Ve=()=>{L(!1),Y.current?.focus()},Qe=()=>{v(!1),oe.current?.focus(),oe.current=null},Dt=(V,pe,ye)=>{ce(null),se(V),ze(pe),oe.current=ye,v(!0)},Le=()=>{E(!1),X(""),ce(null),le(!0)},Ze=async()=>{const V=$.trim();if(!(!r||!Se||!V||G)){ae(!0),ce(null);try{await k({memoryProjectId:a,name:V,parentCollectionId:t.collectionId}),Le()}catch(pe){console.error("Failed to create Memory Project subcollection:",pe),ce(pe instanceof Error?pe.message:"Failed to create subcollection")}finally{ae(!1)}}},jt=async()=>{await Oe(()=>f({memoryProjectId:a,force:!0}),"Failed to regenerate smart collection"),ot()},Ct=async()=>{await Oe(()=>j({collectionId:t.collectionId}),"Failed to reset smart collection"),Ve()},St=async(V,pe)=>{await Oe(()=>h({collectionId:V,itemIds:pe}),"Failed to reorder collection items")},De=async(V,pe,ye)=>{await Oe(()=>b({itemId:V,targetCollectionId:pe,targetIndex:ye}),"Failed to move collection item")},rt=async(V,pe)=>{if(!(!r||ee)){Q(`convert:${V}`),ce(null);try{await S({itemId:V,itemType:pe})}catch(ye){console.error("Failed to convert transcript collection item",ye),ce(ye instanceof Error?ye.message:"Failed to convert transcript item")}finally{Q(null)}}},Fe=async V=>{const pe=ms(V),ye=D;if(!ee){Q(pe),ce(null);try{V.itemType==="page"&&await y({collectionId:ye,item:{itemType:"page",pageId:V.pageId}}),V.itemType==="source"&&await y({collectionId:ye,item:{itemType:"source",fileId:V.fileId}}),V.itemType==="quote"&&await y({collectionId:ye,item:{itemType:"quote",quoteId:V.quoteId}})}catch(Ge){console.error("Failed to add Memory Project collection item",Ge),ce(Ge instanceof Error?Ge.message:"Failed to add content")}finally{Q(null)}}},yt=async V=>{const pe=ms(V),ye=D;if(!(!V.itemId||ee)){Q(pe),ce(null);try{t.kind==="autograph_smart"&&V.itemSource==="autograph_generated"&&V.itemType==="page"?await x({collectionId:ye,item:{itemType:"page",pageId:V.pageId},reason:"owner_removed"}):t.kind==="autograph_smart"&&V.itemSource==="autograph_generated"&&V.itemType==="source"?await x({collectionId:ye,item:{itemType:"source",fileId:V.fileId,sourceRequestId:V.sourceRequestId},reason:"owner_removed"}):await g({collectionId:ye,itemId:V.itemId})}catch(Ge){console.error("Failed to remove Memory Project collection item",Ge),ce(Ge instanceof Error?Ge.message:"Failed to remove content")}finally{Q(null)}}};return e.jsxs("section",{"data-testid":"memory-project-collection-detail",className:"mb-24 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1 sm:mb-0",children:[e.jsx("div",{className:"mb-5",children:e.jsxs("button",{type:"button",onClick:i,className:"inline-flex items-center gap-2 text-sm font-semibold text-grey-5 transition-colors hover:text-grey-7",children:[e.jsx(ir,{size:16,"aria-hidden":"true"}),"Collections"]})}),e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg bg-grey-0 text-primary dark:bg-grey-2",children:Ee?e.jsx(pt,{size:21,"aria-hidden":"true"}):Ke?e.jsx(st,{size:21,"aria-hidden":"true"}):e.jsx(mr,{size:21,"aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[N?e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:w,onChange:V=>U(V.target.value),"aria-label":"Collection name",className:"w-full rounded-lg border border-grey-2 bg-white px-3 py-2 font-primary text-2xl font-bold text-grey-7 outline-none focus:border-primary dark:border-grey-3 dark:bg-grey-1"}),e.jsx("textarea",{value:q,onChange:V=>K(V.target.value),"aria-label":"Collection description",className:"min-h-20 w-full resize-none rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm text-grey-6 outline-none focus:border-primary dark:border-grey-3 dark:bg-grey-1"})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:t.name}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm leading-6 text-grey-5",children:t.description||"A review set for finished story pages and related project media."})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-xs font-semibold text-grey-4",children:[e.jsxs("span",{className:"rounded-full bg-grey-0 px-2 py-1 dark:bg-grey-2",children:[t.storyCount," ",t.storyCount===1?"story":"stories"]}),e.jsxs("span",{className:"rounded-full bg-grey-0 px-2 py-1 dark:bg-grey-2",children:[t.sourceCount," ",t.s
1ourceCount===1?"source":"sources"]}),e.jsxs("span",{className:"rounded-full bg-grey-0 px-2 py-1 dark:bg-grey-2",children:[t.quoteCount," ",t.quoteCount===1?"quote":"quotes"]}),e.jsx("span",{className:"rounded-full bg-grey-0 px-2 py-1 dark:bg-grey-2",children:Va(t.kind)})]})]})]})}),r&&e.jsxs("div",{className:"flex w-full flex-wrap items-center gap-1.5 sm:gap-2",children:[Me&&e.jsxs("button",{type:"button",disabled:G,onClick:V=>Dt(String(t.collectionId),t.name,V.currentTarget),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-3 py-1.5 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3 sm:py-2",children:[e.jsx(at,{size:15,"aria-hidden":"true"}),"Add content"]}),Se&&e.jsxs("button",{ref:te,type:"button",disabled:G,onClick:()=>{ce(null),E(!0)},className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-3 py-1.5 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3 sm:py-2",children:[e.jsx(qr,{size:15,"aria-hidden":"true"}),"New Subcollection"]}),Ee&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{ref:he,type:"button",disabled:G,onClick:()=>z(!0),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-3 py-1.5 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3 sm:py-2",children:[e.jsx(ys,{size:15,"aria-hidden":"true"}),"Regenerate"]}),e.jsxs("button",{ref:Y,type:"button",disabled:G,onClick:()=>L(!0),className:"inline-flex items-center gap-2 rounded-full border border-red-200 px-3 py-1.5 text-sm font-semibold text-red-600 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-45 dark:border-red-900/40 dark:text-red-300 dark:hover:bg-red-900/10 sm:py-2",children:[e.jsx(hi,{size:15,"aria-hidden":"true"}),"Reset"]})]}),Se&&!N&&e.jsxs("button",{type:"button",onClick:()=>P(!0),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-3 py-1.5 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:border-grey-3 sm:py-2",children:[e.jsx(vr,{size:15,"aria-hidden":"true"}),"Edit"]}),N&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:G||!w.trim(),onClick:()=>tt().catch(console.error),className:"inline-flex items-center gap-2 rounded-full bg-primary px-3 py-1.5 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45 sm:py-2",children:[G?e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}):e.jsx(vt,{size:15,"aria-hidden":"true"}),"Save"]}),e.jsx("button",{type:"button",disabled:G,onClick:()=>{U(t.name),K(t.description??""),P(!1),ce(null)},className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-grey-2 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3","aria-label":"Cancel collection edit",children:e.jsx(fe,{size:15,"aria-hidden":"true"})})]}),Nt&&e.jsxs("button",{type:"button",disabled:G,onClick:()=>Oe(()=>m({collectionId:t.collectionId}),"Failed to publish collection"),className:"inline-flex items-center gap-2 rounded-full bg-grey-7 px-3 py-1.5 text-sm font-semibold text-white transition-opacity disabled:cursor-not-allowed disabled:opacity-45 dark:bg-grey-0 dark:text-grey-7 sm:py-2",children:[e.jsx(Jo,{size:15,"aria-hidden":"true"}),"Publish"]}),He&&e.jsxs("button",{type:"button",disabled:G,onClick:()=>Oe(()=>p({collectionId:t.collectionId}),"Failed to hide collection"),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-3 py-1.5 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3 sm:py-2",children:[e.jsx(ui,{size:15,"aria-hidden":"true"}),"Hide from viewers"]}),Se&&e.jsxs("button",{ref:me,type:"button",disabled:G,onClick:()=>_(!0),className:"inline-flex items-center gap-2 rounded-full border border-red-200 px-3 py-1.5 text-sm font-semibold text-red-600 transition-colors hover:bg-red-50 disabled:cursor-not-allowed disabled:opacity-45 dark:border-red-900/40 dark:text-red-300 dark:hover:bg-red-900/10 sm:py-2",children:[e.jsx(gt,{size:15,"aria-hidden":"true"}),"Delete collection"]})]})]}),Ne&&e.jsx("div",{role:"alert",className:"mt-5 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-900/10 dark:text-red-300",children:Ne}),Z&&e.jsx("div",{className:"mt-5 rounded-xl border border-primary/20 bg-grey-0/40 p-4 dark:border-primary/30 dark:bg-grey-0",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsx("input",{ref:re,type:"text",value:$,onChange:V=>X(V.target.value),onKeyDown:V=>{V.key==="Enter"&&(V.preventDefault(),Ze().catch(console.error))},placeholder:"Subcollection name","aria-label":"Memory Project subcollection name",className:"min-h-10 flex-1 rounded-lg border border-grey-2 bg-white px-3 text-sm text-grey-7 outline-none transition-colors focus:border-primary dark:border-grey-3 dark:bg-grey-1"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>Ze().catch(console.error),disabled:!$.trim()||G,className:"inline-flex min-h-10 items-center justify-center gap-2 rounded-full bg-primary px-4 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45",children:[G&&e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}),G?"Creating":"Create"]}),e.jsx("button",{type:"button",onClick:Le,disabled:G,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-grey-2 text-grey-4 transition-colors hover:bg-white hover:text-grey-7 disabled:cursor-not-allowed disabled:opacity-45 dark:border-grey-3 dark:hover:bg-grey-1","aria-label":"Cancel Memory Project subcollection creation",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]})]})}),e.jsx(Zi,{collectionId:t.collectionId,isOwner:Me,items:s,onConvertTranscriptItem:(V,pe)=>
1rt(V,pe).catch(console.error),onAddToCollection:Dt,onMove:(V,pe,ye)=>De(V,pe,ye).catch(console.error),onReorder:(V,pe)=>St(V,pe).catch(console.error)}),H&&e.jsx(nn,{candidates:ue,contentActionKey:ee,onAdd:V=>Fe(V).catch(console.error),onClose:Qe,onRemove:V=>yt(V).catch(console.error),onTabChange:Pe,tab:ke,targetCollectionName:de}),M&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("button",{type:"button","aria-label":"Close delete confirmation",onClick:Ye,className:"absolute inset-0 bg-black/30"}),e.jsxs("dialog",{open:!0,"aria-labelledby":"delete-memory-project-collection-title",className:"relative z-10 m-0 w-full max-w-md rounded-2xl border border-grey-1 bg-white p-6 shadow-xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("h3",{id:"delete-memory-project-collection-title",className:"font-primary text-xl font-bold text-grey-7",children:"Delete collection"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"This removes the custom collection from the Memory Project."}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{ref:Ce,type:"button",onClick:Ye,className:"rounded-full border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 dark:border-grey-3",children:"Cancel"}),e.jsxs("button",{type:"button",disabled:G,onClick:()=>ct().catch(console.error),className:"inline-flex items-center gap-2 rounded-full bg-red-600 px-4 py-2 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45",children:[G&&e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}),"Delete collection"]})]})]})]}),T&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("button",{type:"button","aria-label":"Close regenerate confirmation",onClick:ot,className:"absolute inset-0 bg-black/30"}),e.jsxs("dialog",{open:!0,"aria-labelledby":"regenerate-memory-project-collection-title",className:"relative z-10 m-0 w-full max-w-md rounded-2xl border border-grey-1 bg-white p-6 shadow-xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("h3",{id:"regenerate-memory-project-collection-title",className:"font-primary text-xl font-bold text-grey-7",children:"Regenerate smart collection"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Walter will build a fresh suggested collection from the current project material."}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{ref:c,type:"button",onClick:ot,className:"rounded-full border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 dark:border-grey-3",children:"Cancel"}),e.jsxs("button",{type:"button",disabled:G,onClick:()=>jt().catch(console.error),className:"inline-flex items-center gap-2 rounded-full bg-grey-7 px-4 py-2 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45 dark:bg-grey-0 dark:text-grey-7",children:[G&&e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}),"Regenerate"]})]})]})]}),C&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("button",{type:"button","aria-label":"Close reset confirmation",onClick:Ve,className:"absolute inset-0 bg-black/30"}),e.jsxs("dialog",{open:!0,"aria-labelledby":"reset-memory-project-collection-title",className:"relative z-10 m-0 w-full max-w-md rounded-2xl border border-grey-1 bg-white p-6 shadow-xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("h3",{id:"reset-memory-project-collection-title",className:"font-primary text-xl font-bold text-grey-7",children:"Reset smart collection"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"This clears everything in this collection: the generated set, stories, sources, or quotes you added, and your removals. Walter will then start a fresh pass."}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx("button",{ref:ie,type:"button",onClick:Ve,className:"rounded-full border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-5 transition-colors hover:bg-grey-1 dark:border-grey-3",children:"Cancel"}),e.jsxs("button",{type:"button",disabled:G,onClick:()=>Ct().catch(console.error),className:"inline-flex items-center gap-2 rounded-full bg-red-600 px-4 py-2 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-45",children:[G&&e.jsx(Xe,{size:15,className:"animate-spin","aria-hidden":"true"}),"Reset"]})]})]})]})]})}function Zi({collectionId:t,isOwner:r,items:s,onAddToCollection:a,onConvertTranscriptItem:i,onMove:l,onReorder:d}){const m=Ra(Ur(Ua),Ur($a,{coordinateGetter:Aa})),p=o.useMemo(()=>Ba(s??[],t),[t,s]),{entryById:f,idsByCollectionId:j}=o.useMemo(()=>Vi(p),[p]),[y,b]=o.useState(null),g=o.useRef(null),h=(N,P)=>{Ga(N)&&(g.current=P,b(N))},x=o.useCallback(()=>{b(null),window.requestAnimationFrame(()=>g.current?.focus())},[]);o.useEffect(()=>{if(!y)return;const N=P=>{P.key==="Escape"&&x()};return document.addEventListener("keydown",N),()=>document.removeEventListener("keydown",N)},[x,y]);const S=N=>{const P=String(N.active.id),w=N.over?String(N.over.id):null,U=Hi(p,f,j,P,w);switch(U.kind){case"reparent":case"move":l(U.itemId,U.targetCollectionId,U.targetIndex);return;case"reorder":d(U.targetCollectionId,U.itemIds);return;case"none":return}};if(s===void 0)return e.jsxs("div",{"data-testid":"memory-project-collection-organizer","aria-busy":"true",className:"mt-6 space-y-3",children:[e.jsx("div",{className:"h-20 animate-pulse rounded-xl bg-grey-0 dark:bg-grey-2"}),e.jsx("div",{className:"h-20 animate-pulse rounded-xl bg-grey-0/70 dark:bg-grey-2/70"})]});if(s.length===0)return e.jsx("div",{"data-testid":"memory-project-collection-organizer",className:"mt-6 rounded-xl border border-dashed border-grey-2 bg-grey-0/40 p-6 text-sm text-grey-5 dark:border-grey-2 dark:bg-grey-0",children:"No organizer items yet."});const k=e.jsx(Ya,{collectionId:t,isOwner:r,items:s,onAddToCollection:a,onConvertTranscriptItem:i,onOpenPreview:h});return e.jsxs("div",{"data-testid":"memory-project-collection-organizer",className:"mt-6 space-y-3",children:[r?e.jsx(Ea,{sensors:m,collisionDetection:_a,onDragEnd:S,children:k}):k,y&&e.jsx(tn,{item:y,onClose:x})]})}function Ya({collectionId:t,isOwner:r,items:s,onAddToCollection:a,onConvertTranscriptItem:i,onOpenPreview:l}){const d=s.map((p,f)=>Dr(p,f)),m=s.map((p,f)=>e.jsx(en,{collectionId:t,isOwner:r,item:p,onAddToCollection:a,onConvertTranscriptItem:i,onOpenPreview:l,sortableId:Dr(p,f)},Dr(p,f)));return r?e.jsx(za,{items:d,strategy:Da,children:m}):e.jsx(e.Fragment,{children:m})}function en({collectionId:t,isOwner:r,item:s,onAddToCollection:a,onConvertTranscriptItem:i,onOpenPreview:l,sortableId:d}){const m=qa(s)??"Collection item",p=Yi(s),f=Ka(s),j=s.itemType==="subcollection"?s.collection?.items??[]:[],y=j.length>
10,b=Fr(s),[g,h]=o.useState(!0),x=Ga(s),S=(s.itemType==="quote"||s.itemType==="audio")&&!!(s.callId&&s.transcriptText),{attributes:k,isDragging:N,listeners:P,setNodeRef:w,transform:U,transition:q}=ci({id:d,disabled:!r,data:{collectionId:t,itemType:s.itemType,childCollectionId:Fr(s)}}),K={transform:mi.Translate.toString(U),transition:q},Z=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"rounded-full bg-white px-2 py-1 text-xs font-semibold text-grey-5 dark:bg-grey-1",children:f}),e.jsx("h3",{className:"font-primary text-base font-semibold text-grey-7",children:m})]}),p&&e.jsx("p",{className:"mt-2 line-clamp-2 text-sm leading-6 text-grey-5",children:p})]});return e.jsxs("div",{ref:r?w:void 0,style:K,"data-testid":`memory-project-organizer-item-${d}`,className:`rounded-xl border border-grey-1 bg-grey-0/40 p-4 dark:border-grey-2 dark:bg-grey-0 ${N?"opacity-70":""}`,children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[r&&e.jsx("button",{type:"button","aria-label":`Drag ${m}`,"data-testid":`memory-project-organizer-drag-handle-${d}`,onClick:E=>E.stopPropagation(),className:"mt-1 inline-flex h-8 w-8 shrink-0 cursor-grab items-center justify-center rounded-lg text-grey-3 transition-colors hover:bg-white hover:text-grey-6 focus:outline-none focus:ring-2 focus:ring-primary/40 active:cursor-grabbing dark:hover:bg-grey-1",...k,...P,children:e.jsx(La,{size:16,"aria-hidden":"true"})}),s.itemType==="subcollection"&&y&&e.jsx("button",{type:"button","aria-expanded":g,"aria-label":`${g?"Collapse":"Expand"} ${m}`,onClick:E=>{E.stopPropagation(),h(B=>!B)},className:"mt-1 inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-lg text-grey-4 transition-colors hover:bg-white hover:text-grey-7 focus:outline-none focus:ring-2 focus:ring-primary/40 dark:hover:bg-grey-1",children:e.jsx(wr,{size:17,"aria-hidden":"true",className:`transition-transform ${g?"":"-rotate-90"}`})}),x?e.jsx("button",{type:"button","aria-label":`Preview ${m}`,onClick:E=>l(s,E.currentTarget),className:"-m-2 min-w-0 flex-1 rounded-lg p-2 text-left transition-colors hover:bg-white focus:outline-none focus:ring-2 focus:ring-primary/40 dark:hover:bg-grey-1",children:Z}):e.jsx("div",{className:"min-w-0 flex-1",children:Z})]}),s.itemType==="subcollection"&&e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"text-xs font-semibold text-grey-4",children:[j.length," ",j.length===1?"item":"items"]}),r&&b&&e.jsxs("button",{type:"button",onClick:E=>{E.stopPropagation(),a(b,m,E.currentTarget)},className:"inline-flex items-center gap-1.5 rounded-full border border-grey-2 bg-white px-3 py-1.5 text-xs font-semibold text-grey-6 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:border-grey-3 dark:bg-grey-1 dark:hover:bg-grey-2","aria-label":`Add content to ${m}`,children:[e.jsx(at,{size:13,"aria-hidden":"true"}),"Add"]})]}),r&&S&&"_id"in s&&s._id&&e.jsx("button",{type:"button",onClick:()=>i(String(s._id),s.itemType==="audio"?"quote":"audio"),className:"inline-flex shrink-0 items-center gap-1.5 rounded-full border border-grey-2 px-3 py-1.5 text-xs font-semibold text-grey-5 transition-colors hover:bg-white hover:text-grey-7 dark:border-grey-3 dark:hover:bg-grey-1",children:s.itemType==="audio"?"Save as quote":"Save as audio"})]}),y&&g&&e.jsx("div",{className:"mt-4 space-y-3 border-l border-grey-2 pl-3 dark:border-grey-3 sm:pl-4",children:e.jsx(Ya,{collectionId:b??t,isOwner:r,items:j,onAddToCollection:a,onConvertTranscriptItem:i,onOpenPreview:l})})]})}function tn({item:t,onClose:r}){const s=qa(t),a="memory-project-item-preview-title",i=o.useRef(null);return o.useEffect(()=>{i.current?.focus()},[]),e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("button",{type:"button","aria-label":"Close preview overlay",onClick:r,className:"absolute inset-0 bg-black/35"}),e.jsxs("dialog",{open:!0,"aria-labelledby":a,className:"relative z-10 m-0 max-h-[88vh] w-full max-w-3xl overflow-y-auto rounded-2xl border border-grey-1 bg-grey-0 p-0 shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"sticky top-0 z-10 flex items-start justify-between gap-4 border-b border-grey-1 bg-grey-0/95 px-5 py-4 backdrop-blur dark:border-grey-2 dark:bg-grey-1/95 sm:px-6",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:[Ka(t)," preview"]}),e.jsx("h3",{id:a,className:"mt-1 font-primary text-xl font-bold text-grey-7",children:s})]}),e.jsx("button",{ref:i,type:"button","aria-label":"Close preview",onClick:r,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full text-grey-4 transition-colors hover:bg-white hover:text-grey-7 focu
1s:outline-none focus:ring-2 focus:ring-primary/40 dark:hover:bg-grey-2",children:e.jsx(fe,{size:18,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"p-5 sm:p-6",children:[t.itemType==="page"&&e.jsx(rn,{item:t}),t.itemType==="quote"&&e.jsx(sn,{item:t}),t.itemType==="audio"&&e.jsx(an,{item:t}),t.itemType==="source"&&e.jsx(on,{item:t})]})]})]})}function rn({item:t}){const r=t.page,s=r?.overview??r?.title??"Untitled story",i=(r?.content??r?.body??r?.preview??"").split(/\n{2,}/).map(d=>d.trim()).filter(Boolean),l=r?.sourceReferences?.find(d=>d.quote?.trim())?.quote?.trim();return e.jsxs("div",{className:"mx-auto max-w-2xl space-y-5",children:[e.jsx("div",{className:"rounded-2xl bg-white p-5 shadow-sm dark:bg-white/[0.03] sm:p-8",children:e.jsx("h4",{className:"font-primary text-3xl font-bold leading-tight text-grey-7",children:s})}),l&&e.jsx("div",{className:"rounded-2xl bg-complementary/50 px-6 py-5 dark:bg-white/[0.03] sm:px-8 sm:py-6",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(is,{size:16,className:"mt-0.5 shrink-0 text-primary/30 dark:text-primary/20"}),e.jsxs("p",{className:"font-primary text-[15px] italic leading-[1.7] text-grey-6 dark:text-grey-3",children:['"',l.replace(/^["'\u201C\u2018]+|["'\u201D\u2019]+$/g,""),'"']})]})}),e.jsxs("div",{className:"rounded-2xl bg-white p-5 shadow-sm dark:bg-white/[0.03] sm:p-8 lg:p-10",children:[e.jsx(is,{size:28,className:"mb-6 text-grey-2/60 dark:text-white/10"}),e.jsx("div",{className:"space-y-5 text-[16px] leading-[1.8] text-grey-6 dark:text-grey-5",children:i.length>0?i.map((d,m)=>e.jsx("p",{children:d},`${m}-${d.slice(0,24)}`)):e.jsx("p",{children:"No story text is available yet."})})]})]})}function sn({item:t}){const r="transcriptText"in t&&typeof t.transcriptText=="string"?t.transcriptText:void 0,s=t.quote,a=[r&&"callId"in t&&t.callId?{label:"Source",value:"Session transcript"}:null,"transcriptStartMs"in t&&typeof t.transcriptStartMs=="number"?{label:"Starts",value:jr(t.transcriptStartMs)}:null,s?.pageTitle?{label:"Story",value:s.pageTitle}:null,s?.memberName?{label:"Member",value:s.memberName}:null,s?.entityName?{label:"About",value:s.entityName}:null].filter(i=>i!==null);return e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"rounded-2xl bg-white px-6 py-6 shadow-sm dark:bg-white/[0.03] sm:px-8",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(is,{size:18,className:"mt-1 shrink-0 text-primary/40"}),e.jsxs("p",{className:"font-primary text-xl italic leading-8 text-grey-7",children:['"',r??s?.text??"Saved quote",'"']})]})}),a.length>0&&e.jsx("dl",{className:"grid gap-3 sm:grid-cols-3",children:a.map(i=>e.jsxs("div",{className:"rounded-xl bg-white p-4 shadow-sm dark:bg-white/[0.03]",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:i.label}),e.jsx("dd",{className:"mt-1 text-sm font-semibold text-grey-7",children:i.value})]},i.label))})]})}function an({item:t}){const r="transcriptText"in t&&typeof t.transcriptText=="string"?t.transcriptText:"Saved audio selection",s=["transcriptStartMs"in t&&typeof t.transcriptStartMs=="number"?{label:"Starts",value:jr(t.transcriptStartMs)}:null,"transcriptEndMs"in t&&typeof t.transcriptEndMs=="number"?{label:"Ends",value:jr(t.transcriptEndMs)}:null].filter(a=>a!==null);return e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"rounded-2xl bg-white px-6 py-6 shadow-sm dark:bg-white/[0.03] sm:px-8",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(wa,{size:20,className:"mt-1 shrink-0 text-primary/50"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:"Transcript-backed audio section"}),e.jsxs("p",{className:"mt-3 font-primary text-xl italic leading-8 text-grey-7",children:['"',r,'"']}),e.jsx("p",{className:"mt-3 text-sm text-grey-4",children:"Cropped audio can be attached later; this section keeps the session text and timing metadata now."})]})]})}),s.length>0&&e.jsx("dl",{className:"grid gap-3 sm:grid-cols-2",children:s.map(a=>e.jsxs("div",{className:"rounded-xl bg-white p-4 shadow-sm dark:bg-white/[0.03]",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:a.label}),e.jsx("dd",{className:"mt-1 text-sm font-semibold text-grey-7",children:a.value})]},a.label))})]})}function on({item:t}){const r=t.file,s=t.sourceRequest,a=r?.thumbnailUrl??r?.previewUrl,i=r?.originalFilename??"Untitled source",l=[r?.contentType?{label:"Content type",value:r.contentType}:null,cs(r?.sizeBytes)?{label:"Size",value:cs(r?.sizeBytes)??""}:null,s?.title?{label:"Request",value:s.title}:null,s?.completionSource?{label:"Completed via",value:s.completionSource.replace(/_/g," ")}
1:null,s?.completedAt?{label:"Completed",value:new Date(s.completedAt).toLocaleDateString()}:null].filter(d=>d!==null);return e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"overflow-hidden rounded-2xl bg-white shadow-sm dark:bg-white/[0.03]",children:a?e.jsx("img",{src:a,alt:i,className:"max-h-[420px] w-full object-contain bg-grey-1 dark:bg-grey-2"}):e.jsxs("div",{className:"flex min-h-52 flex-col items-center justify-center gap-3 bg-grey-1/60 p-8 text-center dark:bg-grey-2/60",children:[e.jsx(or,{size:36,className:"text-grey-3","aria-hidden":"true"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold text-grey-6",children:"Preview unavailable"}),e.jsx("p",{className:"mt-1 text-xs text-grey-4",children:"Source metadata is available below."})]})]})}),e.jsxs("div",{className:"rounded-2xl bg-white p-5 shadow-sm dark:bg-white/[0.03]",children:[e.jsx("h4",{className:"font-primary text-xl font-bold text-grey-7",children:i}),l.length>0&&e.jsx("dl",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:l.map(d=>e.jsxs("div",{className:"rounded-xl bg-grey-0 p-3 dark:bg-grey-1",children:[e.jsx("dt",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:d.label}),e.jsx("dd",{className:"mt-1 text-sm font-semibold text-grey-7",children:d.value})]},d.label))})]})]})}function nn({candidates:t,contentActionKey:r,onAdd:s,onClose:a,onRemove:i,onTabChange:l,tab:d,targetCollectionName:m}){const p=[{id:"stories",label:"Stories"},{id:"sources",label:"Sources"},{id:"quotes",label:"Saved quotes"}],f=t?.[d]??[],j=t===void 0,y=o.useRef(null),b="memory-project-add-content-target";return o.useEffect(()=>{y.current?.focus()},[]),e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("button",{type:"button","aria-label":"Close add content",onClick:a,className:"absolute inset-0 bg-black/30"}),e.jsxs("dialog",{open:!0,"aria-labelledby":"memory-project-add-content-title","aria-describedby":b,className:"relative z-10 m-0 flex max-h-[86vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-grey-1 bg-white shadow-xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-grey-1 p-5 dark:border-grey-2",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"memory-project-add-content-title",className:"font-primary text-xl font-bold text-grey-7",children:"Add content"}),e.jsxs("p",{id:b,className:"mt-1 text-sm font-semibold text-grey-5",children:["Adding to ",m]})]}),e.jsx("button",{ref:y,type:"button",onClick:a,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-grey-2 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:border-grey-3","aria-label":"Close add content",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]}),e.jsx("div",{className:"border-b border-grey-1 px-5 pt-4 dark:border-grey-2",children:e.jsx("div",{className:"flex flex-wrap gap-2","aria-label":"Content type",children:p.map(g=>e.jsx("button",{type:"button","aria-pressed":d===g.id,onClick:()=>l(g.id),className:`rounded-full px-3 py-1.5 text-sm font-semibold transition-colors ${d===g.id?"bg-grey-7 text-white dark:bg-grey-0 dark:text-grey-7":"border border-grey-2 text-grey-5 hover:bg-grey-1 hover:text-grey-7 dark:border-grey-3"}`,children:g.label},g.id))})}),e.jsx("div",{className:"min-h-60 overflow-y-auto p-5",children:j?e.jsxs("div",{className:"space-y-3","aria-busy":"true",children:[e.jsx("div",{className:"h-14 animate-pulse rounded-xl bg-grey-1/80 dark:bg-grey-2/80"}),e.jsx("div",{className:"h-14 animate-pulse rounded-xl bg-grey-1/60 dark:bg-grey-2/60"}),e.jsx("div",{className:"h-14 animate-pulse rounded-xl bg-grey-1/40 dark:bg-grey-2/40"})]}):f.length===0?e.jsx("div",{className:"rounded-xl border border-dashed border-grey-2 p-5 text-sm text-grey-5 dark:border-grey-3",children:ln(d)}):e.jsx("div",{className:"space-y-2",children:f.map(g=>{const h=ms(g);return e.jsx(cn,{candidate:g,isBusy:r===h,onAdd:s,onRemove:i,targetCollectionName:m},h)})})})]})]})}function ms(t){return t.itemType==="page"?`page:${t.pageId}`:t.itemType==="source"?`source:${t.fileId}`:`quote:${t.quoteId}`}function ln(t){return t==="stories"?"No eligible Memory Project stories are available for this collection.":t==="sources"?"No eligible uploaded Memory Project sources are available. Failed, trashed, or owner-only sources are hidden.":"No saved quotes from Memory Project stories are available yet."}function dn(t){return t.itemType!=="source"?null:t.thumbnailUrl??t.previewUrl??null}function cn({candidate:t,isBusy:r,onAdd:s,onRemove:a,targetCollectionName:i}){const l=t.itemType==="quote"?t.text:t.title,d=t.itemType==="quote"?t.pageTitle:t.itemType==="source"?t.sourceRequestTitle??t.contentType:t.preview,m=dn(t);return e.jsxs("div",{className:"flex min-h-16 items-center justify-between gap-3 rounded-xl border border-grey-1 bg-grey-0/40 px-4 py-3 dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[t.itemType==="source"&&e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-grey-1 bg-white text-grey-4 dark:border-grey-2 dark:bg-grey-1",children:m?e.jsx("img",{src:m,alt:l,className:"h-full w-full object-cover"}):e.jsx(st,{size:17,"aria-hidden":"true"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-semibold text-grey-7",children:l}),d&&e.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs text-grey-4",children:d})]})]}),e.jsxs("button",{type:"button",disabled:r,onClick:()=>t.added?a(t):s(t),"aria-label":`${t.added?"Remove":"Add"} ${l} ${t.added?"from":"to"} ${i}`,className:`inline-flex min-w-20 items-center justify-center gap-2 rounded-full px-3 py-1.5 text-sm font-semibold disabled:cursor-not-allowed disabled:opacity-45 ${t.added?"border border-grey-2 text-grey-5 hover:bg-grey-1 hover:text-grey-7 dark:border-grey-3":"bg-primary text-white"}`,children:[r&&e.jsx(Xe,{size:14,className:"animate-spin","aria-hidden":"true"}),t.added?"Remove":"Add"]})]})}function mn({onCreate:t}){return e.jsxs("article",{className:"flex h-full flex-col rounded-2xl border border-dashed border-grey-2 bg-white p-5 transition-shadow hover:shadow-md dark:border-grey-2 dark:bg-grey-0",children:[e.jsx("div",{className:"mb-4 flex h-11 w-11 items-center justify-center rounded-lg bg-white text-grey-4 dark:bg-grey-1",children:e.jsx(at,{size:21,"aria-hidden":"true"})}),e.jsx("h3",{className:"font-primary text-xl text-grey-7",children:"Available collection"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Create a custom review set for something specific, such as family review, vendor handoff, or a later keepsake draft."}),e.jsxs("div",{className:"mt-auto flex items-center justify-between border-t border-grey-1 pt-4 text-sm dark:border-grey-2",children:[e.jsx("span",{className:"font-semibold text-grey-6",children:"Empty slot"}),e.jsx("span",{className:"rounded-md bg-white px-2 py-1 text-xs font-semibold text-grey-4 dark:bg-grey-1",children:"Owner-created"})]}),e.jsx("button",{type:"button",onClick:t,className:"mt-4 inline-flex w-full items-center justify-center gap-2 rounded-lg border border-grey-2 px-3 py-2 text-sm font-semibold text-grey-6 transition-colors hover:bg-grey-1 dark:border-grey-3 dark:hover:bg-grey-1",children:"Create collection"})]})}function un({groupId:t,slug:r,canManageCollections:s,memoryProjectId:a,memoryProjectRole:i}){return a?e.jsx(Ji,{memoryProjectId:a,role:i??(s?"owner":"viewer"),canManageCollections:s}):e.jsx(xn,{groupId:t,slug:r,canManageCollections:s})}function xn({groupId:t,slug:r,canManageCollections:s}){const a=!t.startsWith("group-"),i=be(O.collections.listForGroup,a?{groupId:t}:"skip"),l=be(O.groups.listSharedPages,a?{groupId:t,limit:200}:"skip"),d=o.useMemo(()=>(i??[]).map(Qs),[i]),m=o.useMemo(()=>(l??[]).map(ja),[l]),p=o.useMemo(()=>d.filter(_=>!_.parentId),[d]),{create:f}
1=fs(),j=o.useRef(null),[y,b]=o.useState(!1),[g,h]=o.useState(""),[x,S]=o.useState(!1),[k,N]=o.useState(null),[P,w]=o.useState(null),[U,q]=o.useState([]),K=P?.id,Z=be(O.collections.listForGroup,a&&K?{groupId:t,parentId:K}:"skip"),E=o.useMemo(()=>(Z??[]).map(Qs),[Z]),B=o.useMemo(()=>[...d,...E].find(_=>_.id===K)??P,[E,d,P,K]),le=a&&i===void 0,$=oi(d),X=$>=Ys;o.useEffect(()=>{y&&j.current?.focus()},[y]);const G=()=>{h(""),b(!1),S(!1),N(null)},ae=async()=>{const _=g.trim();if(!(!_||x||X)){S(!0),N(null);try{await f(_,"â","#6366f1",{groupId:t}),G()}catch(T){console.error("Failed to create group collection:",T),N(T instanceof Error?T.message:"Failed to create collection"),S(!1)}}},ee=()=>{!s||X||b(!0)},Q=(_,T=[])=>{w(_),q([...T,_]),G()},M=()=>{w(null),q([]),G()};return B?e.jsx(pn,{groupId:t,slug:r,collection:B,childCollections:E,groupPages:m,canManageCollections:s,path:U,onBack:M,onOpenChild:_=>Q(_,U)}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Collections"}),e.jsxs("p",{id:"group-collections-usage",className:"mt-1 text-sm text-grey-4",children:[$," of ",Ys," collections used"]})]}),s&&e.jsxs(F.button,{type:"button",whileHover:X?void 0:{scale:1.02},whileTap:X?void 0:{scale:.98},onClick:ee,disabled:X,"aria-describedby":"group-collections-usage",className:"inline-flex items-center justify-center gap-2 rounded-full bg-primary px-4 py-2 text-sm font-medium text-white shadow-sm transition-opacity disabled:cursor-not-allowed disabled:opacity-45",children:[e.jsx(at,{size:16,"aria-hidden":"true"}),"New Collection"]})]}),le?e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-grey-1 bg-white px-4 py-3 text-sm text-grey-4 dark:border-grey-2 dark:bg-grey-1",children:[e.jsx(Xe,{size:16,className:"animate-spin","aria-hidden":"true"}),"Loading collections"]}):e.jsxs(F.div,{initial:"hidden",animate:"show",variants:_t,className:"space-y-3",children:[p.map(_=>e.jsxs(F.button,{type:"button",onClick:()=>
1Q(_),variants:Ue,className:"flex w-full items-center gap-4 rounded-xl border border-grey-1 bg-white p-4 text-left transition-colors hover:bg-grey-0 dark:border-grey-2 dark:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-grey-0 text-xl dark:bg-grey-2",children:_.emoji}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"truncate font-primary text-lg font-bold text-grey-7",children:_.name}),e.jsxs("p",{className:"text-sm text-grey-4",children:[_.pageIds.length," ",_.pageIds.length===1?"page":"pages"]})]})]},_.id)),y&&e.jsxs(F.div,{variants:Ue,className:"rounded-xl border border-primary/20 bg-white p-4 dark:border-primary/40 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsx("input",{ref:j,type:"text",value:g,onChange:_=>h(_.target.value),onKeyDown:_=>{_.key==="Escape"&&G(),_.key==="Enter"&&(_.preventDefault(),ae().catch(console.error))},placeholder:"Collection name","aria-label":"Collection name",className:"min-h-10 flex-1 rounded-lg border border-grey-2 bg-white px-3 text-sm text-grey-7 outline-none transition-colors focus:border-primary dark:bg-grey-1"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>ae().catch(console.error),disabled:!g.trim()||x,className:"inline-flex min-h-10 items-center justify-center rounded-full bg-primary px-4 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-45",children:x?"Creating":"Create"}),e.jsx("button",{type:"button",onClick:G,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-grey-2 text-grey-4 hover:bg-grey-1 hover:text-grey-6","aria-label":"Cancel collection creation",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]})]}),k&&e.jsx("p",{className:"mt-2 text-sm text-red-600",role:"alert",children:k})]}),p.length===0&&!y&&e.jsx(os,{icon:mr,title:"No collections yet",description:"Organize this group's pages into a few focused collections.",action:s?e.jsxs("button",{type:"button",onClick:ee,className:"inline-flex items-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-medium text-white shadow-sm",children:[e.jsx(qr,{size:15,"aria-hidden":"true"}),"New Collection"]}):void 0})]})]})}function pn({groupId:t,slug:r,collection:s,childCollections:a,groupPages:i,canManageCollections:l,path:d,onBack:m,onOpenChild:p}){const{PAGES:f}=Kr(),{user:j}=hs(),y=Mo(),{create:b}=fs(),g=ne(O.collections.update),h=ne(O.collections.reorderPages),[x,S]=o.useState(!1),[k,N]=o.useState(""),[P,w]=o.useState(!1),[U,q]=o.useState(null),[K,Z]=o.useState(!1),[E,B]=o.useState(!1),[le,$]=o.useState(!1),[X,G]=o.useState(""),ae=o.useRef(null),ee=Ra(Ur(Ua,{activationConstraint:{distance:8}}),Ur($a,{coordinateGetter:Aa})),Q=o.useMemo(()=>Wa([...f,...i]),[f,i]),M=o.useMemo(()=>(s.pageIds??[]).map(D=>Q.find(se=>se.id===D)).filter(D=>!!D),[s.pageIds,Q]),_=o.useMemo(()=>new Set(s.quoteIds??[]),[s.quoteIds]),T=o.useMemo(()=>y.filter(D=>_.has(D.id)),[y,_]),z=$s[s.emoji]||s.emoji;o.useEffect(()=>{x&&ae.current?.focus()},[x]);const C=()=>{S(!1),N(""),w(!1),q(null)},L=async()=>{const D=k.trim();if(!(!D||P)){w(!0),q(null);try{await b(D,"ð","#6366f1",{groupId:t,parentId:s.id}),C()}catch(se){console.error("Failed to create group subcollection:",se),q(se instanceof Error?se.message:"Failed to create subcollection"),w(!1)}}},H=()=>{const D=X.trim();g({id:s.id,description:D||void 0}),$(!1)},v=D=>{const{active:se,over:de}=D;if(!de||se.id===de.id)return;const ze=M.findIndex(Ne=>Ne.id===se.id),ke=M.findIndex(Ne=>Ne.id===de.id);if(ze===-1||ke===-1)return;const Pe=Ta(M,ze,ke);h({collectionId:s.id,orderedPageIds:Pe.map(Ne=>Ne.id)})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F.div,{variants:Ue,className:"flex items-center justify-between gap-4",children:[e.jsxs("button",{type:"button",onClick:m,className:"inline-flex items-center gap-2 text-sm font-medium text-grey-5 transition-colors hover:text-grey-7",children:[e.jsx(ir,{size:16,"aria-hidden":"true"}),"Collections"]}),l&&e.jsxs("button",{type:"button",onClick:()=>S(!0),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-4 py-2 text-sm font-medium text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-7",children:[e.jsx(qr,{size:15,"aria-hidden":"true"}),"New Subcollection"]})]}),d.length>1&&e.jsxs("nav",{className:"flex flex-wrap items-center gap-2 text-xs text-grey-4",children:[e.jsx("span",{children:"Collections"}),d.map(D=>e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{children:"/"}),e.jsx("span",{className:D.id===s.id?"font-semibold text-grey-6":"",children:D.name})]},D.id))]}),e.jsxs(F.div,{variants:Ue,children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:z}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h2",{className:"truncate font-primary text-2xl font-bold text-grey-7",children:s.name}),e.jsxs("div",{className:"mt-1 flex items-center gap-3 text-sm text-grey-4",children:[e.jsxs("span",{children:[M.length," ",M.length===1?"page":"pages"]}),M.length>1&&e.jsx("span",{className:"text-xs text-grey-3",children:"drag to reorder"})]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[M.length>0&&e.jsxs("button",{type:"button",onClick:()=>B(!0),className:"inline-flex items-center gap-1.5 rounded-full px-3 py-1.5 text-xs font-medium text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-6",children:[e.jsx(st,{size:14,"aria-hidden":"true"}),"Preview"]}),l&&e.jsxs("button",{type:"button",onClick:()=>Z(!0),className:"inline-flex items-center gap-1.5 rounded-full border border-grey-2 px-3 py-1.5 text-xs font-medium text-grey-5 transition-colors hover:bg-grey-1 hover:text-grey-6",children:[e.jsx(at,{size:14,"aria-hidden":"true"}),"Manage Pages"]})]})]}),le?e.jsx("div",{className:"mt-3 flex items-center gap-2",children:e.jsx("input",{autoFocus:!0,t
1ype:"text",value:X,onChange:D=>G(D.target.value),onKeyDown:D=>{D.key==="Enter"&&H(),D.key==="Escape"&&$(!1)},onBlur:H,placeholder:"Add a short description...",className:"flex-1 rounded-lg border border-grey-2 px-3 py-1.5 text-sm text-grey-6 placeholder:text-grey-3 focus:border-primary/30 focus:outline-none focus:ring-1 focus:ring-primary/20"})}):e.jsx("button",{type:"button",onClick:()=>{l&&(G(s.description??""),$(!0))},className:"mt-3 text-left text-sm text-grey-4 transition-colors hover:text-grey-5",children:s.description||e.jsx("span",{className:"italic text-grey-3",children:"Add a description..."})})]}),x&&e.jsxs(F.div,{variants:Ue,className:"rounded-xl border border-primary/20 bg-white p-4 dark:border-primary/40 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row",children:[e.jsx("input",{ref:ae,type:"text",value:k,onChange:D=>N(D.target.value),onKeyDown:D=>{D.key==="Escape"&&C(),D.key==="Enter"&&(D.preventDefault(),L().catch(console.error))},placeholder:"Subcollection name","aria-label":"Subcollection name",className:"min-h-10 flex-1 rounded-lg border border-grey-2 bg-white px-3 text-sm text-grey-7 outline-none transition-colors focus:border-primary dark:bg-grey-1"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>L().catch(console.error),disabled:!k.trim()||P,className:"inline-flex min-h-10 items-center justify-center rounded-full bg-primary px-4 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-45",children:P?"Creating":"Create"}),e.jsx("button",{type:"button",onClick:C,className:"inline-flex h-10 w-10 items-center justify-center rounded-full border border-grey-2 text-grey-4 hover:bg-grey-1 hover:text-grey-6","aria-label":"Cancel subcollection creation",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]})]}),U&&e.jsx("p",{className:"mt-2 text-sm text-red-600",role:"alert",children:U})]}),a.length>0&&e.jsxs(F.div,{variants:Ue,children:[e.jsx("h3",{className:"mb-3 text-xs font-semibold uppercase tracking-wide text-grey-4",children:"Subcollections"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(D=>e.jsxs("button",{type:"button",onClick:()=>p(D),className:"inline-flex items-center gap-2 rounded-full border border-grey-2 bg-white px-3 py-1.5 text-sm font-medium text-grey-6 transition-shadow hover:shadow-sm dark:bg-grey-1",children:[e.jsx("span",{children:$s[D.emoji]||D.emoji}),D.name,e.jsx("span",{className:"text-xs text-grey-3",children:D.pageIds.length})]},D.id))})]}),M.length>0?e.jsx(Ea,{sensors:ee,collisionDetection:_a,onDragEnd:v,children:e.jsx(za,{items:M.map(D=>D.id),strategy:Da,children:e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:"space-y-3",children:M.map((D,se)=>e.jsx(ii,{page:D,slug:r,index:se},D.id))})})}):e.jsxs(F.div,{variants:Ue,className:"flex flex-col items-center justify-center py-16 text-center",children:[e.jsx(mr,{size:40,className:"mb-3 text-grey-3","aria-hidden":"true"}),e.jsx("h3",{className:"font-primary text-lg font-semibold text-grey-5",children:"Empty collection"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:"Add pages from this group or your library to get started."}),l&&e.jsxs("button",{type:"button",onClick:()=>Z(!0),className:"mt-4 flex items-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-medium text-white shadow-sm hover:bg-primary/90",children:[e.jsx(at,{size:14,"aria-hidden":"true"}),"Manage Pages"]})]}),T.length>0&&e.jsxs(F.div,{variants:Ue,className:"space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:"Saved Quotes"}),e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:"space-y-3",children:T.map(D=>e.jsx(ni,{quote:D,slug:r},D.id))})]}),K&&e.jsx(gn,{collection:s,groupPages:i,libraryPages:f,onClose:()=>Z(!1)}),e.jsx(lt,{children:E&&e.jsx(li,{collection:s,pages:M,emojiChar:z,authorName:j?`${j.firstName} ${j.lastName}`:void 0,onClose:()=>B(!1)})})]})}function gn({collection:t,groupPages:r,libraryPages:s,onClose:a}){const{togglePage:i}
1=fs(),[l,d]=o.useState("group"),[m,p]=o.useState(""),[f,j]=o.useState(()=>new Set(t.pageIds??[])),y=l==="group"?r:s,b=o.useMemo(()=>{const h=m.trim().toLowerCase(),x=Wa(y);return h?x.filter(S=>S.title.toLowerCase().includes(h)||S.pageType.toLowerCase().includes(h)||S.preview?.toLowerCase().includes(h)):x},[y,m]),g=async h=>{const x=!f.has(h);j(S=>{const k=new Set(S);return x?k.add(h):k.delete(h),k});try{await i(t.id,h)}catch(S){console.error("Failed to update collection page:",S),j(k=>{const N=new Set(k);return x?N.delete(h):N.add(h),N})}};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx(F.div,{initial:{opacity:0},animate:{opacity:1},onClick:a,className:"absolute inset-0 bg-black/30"}),e.jsxs(F.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},transition:{duration:.2},className:"relative z-10 flex w-full max-w-lg flex-col rounded-2xl border border-grey-1 bg-white p-6 shadow-xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-lg font-bold text-grey-7",children:"Manage pages"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:t.name})]}),e.jsx("button",{type:"button",onClick:a,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-grey-2 text-grey-4 hover:bg-grey-1 hover:text-grey-6","aria-label":"Close manage pages",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 rounded-full bg-grey-0 p-1 dark:bg-grey-2",children:[e.jsx("button",{type:"button",onClick:()=>d("group"),"aria-pressed":l==="group",className:`rounded-full px-3 py-2 text-sm font-medium transition-colors ${l==="group"?"bg-white text-grey-7 shadow-sm dark:bg-grey-1":"text-grey-4 hover:text-grey-6"}`,children:"Pages in this group"}),e.jsx("button",{type:"button",onClick:()=>d("library"),"aria-pressed":l==="library",className:`rounded-full px-3 py-2 text-sm font-medium transition-colors ${l==="library"?"bg-white text-grey-7 shadow-sm dark:bg-grey-1":"text-grey-4 hover:text-grey-6"}`,children:"Your library"})]}),e.jsxs("div",{className:"relative mt-4",children:[e.jsx($r,{size:14,className:"absolute left-3 top-1/2 -translate-y-1/2 text-grey-3","aria-hidden":"true"}),e.jsx("input",{type:"text",value:m,onChange:h=>p(h.target.value),placeholder:"Search pages...",className:"w-full rounded-lg border border-grey-2 bg-white py-2 pl-9 pr-8 text-sm text-grey-6 placeholder:text-grey-3 focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20 dark:border-grey-3 dark:bg-grey-2 dark:text-grey-7"}),m&&e.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-grey-3 hover:text-grey-5","aria-label":"Clear page search",children:e.jsx(fe,{size:14,"aria-hidden":"true"})})]}),b.length>0?e.jsx("div",{className:"mt-4 max-h-[60vh] space-y-1.5 overflow-y-auto",children:b.map(h=>{const x=f.has(h.id);return e.jsxs("button",{type:"button",onClick:()=>g(h.id).catch(console.error),className:"flex w-full items-start gap-3 rounded-lg border border-grey-2 px-3 py-2.5 text-left transition-colors hover:bg-grey-1 dark:border-grey-3 dark:hover:bg-grey-2",children:[e.jsx("span",{className:`mt-0.5 flex h-6 w-6 shrink-0 items-center justify-center rounded-md border ${x?"border-primary bg-primary text-white":"border-grey-2 text-transparent dark:border-grey-3"}`,children:e.jsx(vt,{size:14,"aria-hidden":"true"})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-medium text-grey-7",children:h.title}),h.preview&&e.jsx("span",{className:"mt-0.5 line-clamp-2 block text-xs leading-relaxed text-grey-4",children:h.preview}),e.jsxs("span",{className:"mt-0.5 block truncate text-[11px] capitalize text-grey-3",children:[h.pageType," · ",h.updatedAt]})]}),e.jsx("span",{className:`mt-1 text-xs font-medium ${x?"text-primary":"text-grey-4"}`,children:x?"Added":"Add"})]},h.id)})}):e.jsxs("div",{className:"flex flex-col items-center py-10 text-center",children:[e.jsx(di,{size:32,className:"mb-3 text-grey-3","aria-hidden":"true"}),e.jsx("p",{className:"text-sm font-medium text-grey-5",children:"No pages found"}),e.jsx("p",{className:"mt-1 text-xs text-grey-4",children:"Try the other source or a different search term."})]}),e.jsx("button",{type:"button",onClick:a,className:"mt-4 w-full rounded-lg border border-grey-2 py-2 text-sm font-medium text-grey-5 dark:border-grey-3",children:"Done"})]})]})}function Xs(t){switch(t){case"owner":return"Owner";case"contributor":return"Contributor";case"viewer":return"Viewer"}}function yn(t,r){return!(t!=="owner"&&t!=="contributor"||r&&r!=="capture_open")}function hn({role:t,scheduledContactId:r,viewerContactId:s}
1){return t==="owner"?!0:t!=="contributor"?!1:!!(r&&s&&r===s)}function bn(t,r,s){return{destination:s?"memoryProject":"group",groupId:t,...s?{memoryProjectId:s}:{},...r?{storytellerId:r}:{}}}function Or(t,r){if(t===void 0)return"Not set";const s=r?.exclusive?t-1:t;return new Date(s).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric",timeZone:"UTC"})}function us(t,r){return t.length<=r?t:`${t.slice(0,r).replace(/\s+\S*$/,"")}...`}function Qa(t){return t?.replace(/^#+\s*(Summary\s*)?/i,"").trim()??""}function Nr(t,r){const s=new Intl.DateTimeFormat("en-US",{timeZone:r,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",hour12:!1}).formatToParts(new Date(t)),a=i=>s.find(l=>l.type===i)?.value??"";return{date:`${a("year")}-${a("month")}-${a("day")}`,time:`${a("hour")}:${a("minute")}`}}function fn(t,r){if(t!==void 0)return Nr(t,r).date}function vn(t,r){if(t!==void 0)return Nr(t-1,r).date}function jn(t,r){if(t!==void 0)return Nr(t,r).time}function wn(t,r){if(t!==void 0)return Nr(t-1,r).time}function Zs(t,r,s){return!(r!==void 0&&t<r||s!==void 0&&t>=s)}function ea(t){const r=Qa(t.summary);return t.title||us(r,80)||"Conversation with Walter"}function Ja(t){return"targetDisplayName"in t&&typeof t.targetDisplayName=="string"?t.targetDisplayName:void 0}function Xa(t){return"scheduledByDisplayName"in t&&typeof t.scheduledByDisplayName=="string"?t.scheduledByDisplayName:void 0}function Za(t){return t?`${t} min target`:void 0}function kn({session:t,isMemoryProject:r,memoryProjectCaptureWindowStartsAt:s,memoryProjectCaptureWindowEndsAt:a,onClose:i}){const l=Nr(t.scheduledAtUtc,t.timezone),[d,m]=o.useState(l.date),[p,f]=o.useState(l.time),[j,y]=o.useState(t.topic??""),[b,g]=o.useState(!1),[h,x]=o.useState(null),S=ne(O.scheduledCalls.reschedule),k=fn(s,t.timezone),N=vn(a,t.timezone),P=d===k?jn(s,t.timezone):void 0,w=d===N?wn(a,t.timezone):void 0,q=[new Date().toISOString().split("T")[0],k].filter(Boolean).sort().at(-1),K=d&&p?Ms(Ts(p),new Date(`${d}T12:00:00`),t.timezone):null,Z=K!==null&&!Zs(K,s,a),E=async()=>{if(!(!d||!p||b)){g(!0),x(null);try{const B=Ms(Ts(p),new Date(`${d}T12:00:00`),t.timezone);if(!Zs(B,s,a)){x("Select a time within the Memory Project capture window."),g(!1);return}await S({scheduledCallId:t._id,scheduledAtUtc:B,timezone:t.timezone,topic:j.trim()||void 0}),i()}catch(B){x(B instanceof Error?B.message:"Failed to reschedule session"),g(!1)}}};return e.jsx(F.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:i,children:e.jsxs(F.div,{initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0},onClick:B=>B.stopPropagation(),className:"w-full max-w-md rounded-xl bg-white p-6 shadow-xl dark:bg-grey-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-primary text-lg font-bold text-grey-7",children:r?"Reschedule Memory Project call":"Edit Session"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:r?"Choose a new appointment time for this scheduled Walter call.":"Update this group Walter call."})]}),e.jsx("button",{type:"button",onClick:i,className:"flex h-8 w-8 items-center justify-center rounded-full text-grey-4 hover:bg-grey-1 hover:text-grey-6","aria-label":"Close edit session",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-xs font-medium text-grey-5",children:"Date"}),e.jsx("input",{type:"date",value:d,onChange:B=>m(B.target.value),min:q,max:N,className:"w-full rounded-xl border border-grey-2 bg-white px-3 py-2.5 text-sm text-grey-7 outline-none focus:border-primary focus:ring-1 focus:ring-primary/20 dark:bg-grey-1"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-xs font-medium text-grey-5",children:"Time"}),e.jsx("input",{type:"time",value:p,onChange:B=>f(B.target.value),min:P,max:w,className:"w-full rounded-xl border border-grey-2 bg-white px-3 py-2.5 text-sm text-grey-7 outline-none focus:border-primary focus:ring-1 focus:ring-primary/20 dark:bg-grey-1"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1.5 block text-xs font-medium text-grey-5",children:r?"Walter focus":"Topic"}),e.jsx("input",{type:"text",value:j,onChange:B=>y(B.target.value),placeholder:r?"What should Walter focus on?":"What should Walter ask about?",className:"w-full rounded-xl border border-grey-2 bg-white px-3 py-2.5 text-sm text-grey-7 outline-none placeholder:text-grey-3 focus:border-primary focus:ring-1 focus:ring-primary/20 dark:bg-grey-1"})]})]}),h&&e.jsx("p",{className:"mt-3 text-sm text-red-600",role:"alert",children:h}),!h&&Z&&e.jsx("p",{className:"mt-3 text-sm text-red-600",role:"alert",children:"Select a time within the Memory Project capture window."}),e.jsxs("div",{className:"mt-6 flex gap-3",children:[e.jsx("button",{type:"button",onClick:E,disabled:!d||!p||b||Z,className:"inline-flex flex-1 items-center justify-center rounded-full bg-primary px-4 py-2.5 text-sm font-medium text-white disabled:cursor-not-allowed disabled:opacity-45",children:b?"Saving":"Save changes"}),e.jsx("button",{type:"button",onClick:i,className:"rounded-full border border-grey-2 px-4 py-2.5 text-sm font-medium text-grey-5 hover:bg-grey-1",children:"Cancel"})]})]})})}function Nn({session:t,canManage:r,isMemoryProject:s,onEdit:a,onCancel:i}){const l=To(t.scheduledAtUtc,t.timezone),d=t.topic||(s?"Scheduled Walter call":"Scheduled session"),m=Ja(t),p=Xa(t),f=Za(t.targetDurationMinutes);return s?e.jsx(F.div,{variants:ar,className:"rounded-xl border border-grey-1 bg-grey-0/60 p-4 dark:border-grey-2 dark:bg-grey-0",children:e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-grey-7",children:d}),e.jsx("span",{className:"rounded-md bg-white px-2 py-1 text-xs font-semibold text-grey-4 dark:bg-grey-1",children:"Walter appointment"})]}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:[m??"Contributor",`${l.date} at ${l.time}`,f].filter(Boolean).join(" - ")}),p&&e.jsxs("p",{className:"mt-2 text-xs font-medium text-grey-4",children:["Scheduled by ",p]}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-grey-5",children:"Scheduled with Walter. Call details stay tied to this Memory Project context."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"inline-flex w-fit items-center gap-1 rounded-md bg-memory-light px-2 py-1 text-xs font-semibold text-memory",children:[e.jsx(Bt,{size:13,"aria-hidden":"true"}),"Scheduled"]}),r&&e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",onClick:a,title:"Edit session",className:"flex h-8 w-8 items-center justify-center rounded-lg border border-grey-2 bg-white text-grey-4 transition-colors hover:border-primary/30 hover:text-primary dark:bg-grey-1",children:e.jsx(vr,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:i,title:"Cancel session",className:"flex h-8 w-8 items-center justify-center rounded-lg border border-grey-2 bg-white text-grey-4 transition-colors hover:border-red-200 hover:text-red-500 dark:bg-grey-1",children:e.jsx(fe,{size:13,"aria-hidden":"true"})})]})]})]})}):e.jsxs(F.div,{variants:ar,className:"relative overflow-hidden rounded-2xl border border-primary/15 bg-gradient-to-r from-primary-light to-white p-4 dark:to-grey-0 sm:p-5",children:[e.jsx("div",{className:"absolute bottom-0 left-0 top-0 w-1 bg-primary"}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-bold uppercase text-primary",children:"Scheduled"}),e.jsx("h3",{className:"mt-1.5 font-primary text-base font-bold text-grey-7",children:d}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-grey-4",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Jt,{size:13,"aria-hidden":"true"}),l.date]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Bt,{size:13,"aria-hidden":"true"}),l.time]}),t.targetDurationMinutes&&e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.targetDurationMinutes," min target"]})]}),t.topic&&e.jsxs("p",{className:"mt-2 flex items-center gap-1.5 text-xs text-grey-4",children:[e.jsx(ka,{size:11,"aria-hidden":"true"}),t.topic]})]}),r&&e.jsxs("div",{className:"flex shrink-0 gap-1.5",children:[e.jsx("button",{type:"button",onClick:a,title:"Edit session",className:"flex h-8 w-8 items-center justify-center rounded-full border border-grey-2 bg-white text-grey-4 transition-colors hover:border-primary/30 hover:text-primary dark:bg-grey-1",children:e.jsx(vr,{size:13,"aria-hidden":"true"})}),e.jsx("button",{type:"button",onClick:i,title:"Cancel session",className:"flex h-8 w-8 items-center justify-center rounded-full border border-grey-2 bg-white text-grey-4 transition-colors hover:border-red-200 hover:text-red-500 dark:bg-grey-1",children:e.jsx(fe,{size:13,"aria-hidden":"true"})})]})]})]})}function Cn({call:t,index:r,total:s,isMemoryProject:a}){const i=t.status==="Active"&&!!t.callDurationSecs&&t.callDurationSecs>0,l=t.processingStatus&&t.processingStatus!=="done"&&t.processingStatus!=="failed",d=Qa(t.summary),m=Ja(t),p=Xa(t),f=Za(t.targetDurationMinutes)??Rs(t.callDurationSecs);
1return a?e.jsx(Et,{to:i?"/sessions/live/$sessionId":"/sessions/$sessionId",params:{sessionId:t._id},className:"block",children:e.jsxs(F.div,{variants:Ue,whileHover:{y:-1,transition:{duration:.15}},className:"rounded-xl border border-grey-1 bg-grey-0/60 p-4 transition-colors hover:bg-white dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-semibold text-grey-7",children:ea(t)}),e.jsx("span",{className:"rounded-md bg-white px-2 py-1 text-xs font-semibold text-grey-4 dark:bg-grey-1",children:"Story contribution"})]}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:[m??"Contributor",Es(new Date(t.date).getTime()),f].filter(Boolean).join(" - ")}),p&&e.jsxs("p",{className:"mt-2 text-xs font-medium text-grey-4",children:["Scheduled by ",p]})]}),e.jsxs("span",{className:"inline-flex w-fit items-center gap-1 rounded-md bg-memory-light px-2 py-1 text-xs font-semibold text-memory",children:[l?e.jsx(Xe,{size:13,className:"animate-spin","aria-hidden":"true"}):e.jsx(cr,{size:13,"aria-hidden":"true"}),l?"Processing":"Completed"]})]}),d&&e.jsx("p",{className:"mt-3 text-sm leading-6 text-grey-5",children:us(d,150)})]})}):e.jsx(Et,{to:i?"/sessions/live/$sessionId":"/sessions/$sessionId",params:{sessionId:t._id},className:"block",children:e.jsxs(F.div,{variants:Ue,whileHover:{y:-2,boxShadow:"0 4px 24px rgba(0,0,0,0.06)",transition:{duration:.15}},className:`relative flex gap-5 rounded-2xl bg-white px-5 py-4 transition-colors hover:bg-white dark:bg-grey-1 sm:px-6 sm:py-5 ${i?"ring-1 ring-primary/20":""}`,children:[e.jsx("div",{className:"absolute bottom-4 left-0 top-4 w-[3px] rounded-full bg-gradient-to-b from-primary to-primary/40"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[i?e.jsx("span",{className:"absolute right-5 top-4 rounded-full bg-red-500 px-2.5 py-1 text-xs font-bold text-white",children:"LIVE"}):l?e.jsxs("span",{className:"absolute right-5 top-4 inline-flex items-center gap-1.5 rounded-full bg-amber-50 px-2.5 py-1 text-xs font-medium text-amber-700 ring-1 ring-amber-200",children:[e.jsx(Xe,{size:11,className:"animate-spin","aria-hidden":"true"}),"Processing"]}):e.jsxs("span",{className:"absolute right-5 top-4 font-primary text-xs font-bold text-grey-3",children:["#",s-r]}),e.jsx("h3",{className:"pr-20 font-primary text-base font-bold text-grey-7 sm:text-lg",children:ea(t)}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-4 gap-y-1 text-sm text-grey-4",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Jt,{size:13,"aria-hidden":"true"}),Es(t.date)]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Bt,{size:13,"aria-hidden":"true"}),Rs(t.callDurationSecs)]})]}),d&&e.jsx("p",{className:"mt-2 line-clamp-2 text-sm text-grey-4",children:us(d,150)})]})]})})}function ta({sessions:t,role:r,viewerContactId:s,isMemoryProject:a,className:i,onEdit:l,onCancel:d}){return e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:i,children:t.map(m=>{const p=hn({role:r,scheduledContactId:m.contactId,viewerContactId:s});return e.jsx(Nn,{session:m,canManage:p,isMemoryProject:a,onEdit:()=>l(m),onCancel:()=>d(m)},m._id)})})}function ra({calls:t,isMemoryProject:r,className:s}){return e.jsx(F.div,{initial:"hidden",animate:"show",variants:_t,className:s,children:t.map((a,i)=>e.jsx(Cn,{call:a,index:i,total:t.length,isMemoryProject:r},a._id))})}function Sn({memoryProjectPhase:t,memoryProjectCaptureWindowStartsAt:r,memoryProjectCaptureWindowEndsAt:s,scheduledCount:a,completedCount:i}){const d=t!==void 0&&t!=="capture_open"?Oo:Bo,m=Or(s,{exclusive:!0}),p=Or(r);return e.jsxs("section",{"data-testid":"memory-project-sessions-timeline",className:"rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:"Project timeline"}),e.jsx("span",{className:"mt-3 inline-flex rounded-md bg-grey-0 px-2 py-1 text-xs font-semibold text-grey-4 dark:bg-grey-2",children:d})]}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-grey-5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Jt,{size:15,className:"text-primary","aria-hidden":"true"}),"Capture started ",p]}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Bt,{size:15,className:"text-primary","aria-hidden":"true"}),"Capture deadline ",m]})]}),e.jsxs("div",{className:"mt-5",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-semibold text-grey-6",children:"Call progress"}),e.jsxs("span",{className:"text-grey-4",children:[a," scheduled"]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-grey-1 dark:bg-grey-2",children:e.jsx("div",{className:"h-full rounded-full bg-memory",style:{width:`${i>0?100:a>0?45:8}%`}})}),e.jsxs("p",{className:"mt-2 text-xs font-medium text-grey-4",children:[i," completed"]})]})]})}function In({groupId:t,role:r,memoryProjectId:s,memoryProjectPhase:a,memoryProjectCaptureWindowStartsAt
1:i,memoryProjectCaptureWindowEndsAt:l}){const d=!t.startsWith("group-"),m=be(O.members.me),p=be(s?O.scheduledCalls.listByMemoryProject:O.scheduledCalls.listByGroup,d?s?{memoryProjectId:s}:{groupId:t}:"skip"),f=be(s?O.calls.listByMemoryProject:O.calls.listByGroup,d?s?{memoryProjectId:s}:{groupId:t}:"skip"),j=ne(O.scheduledCalls.cancel),[y,b]=o.useState(null),[g,h]=o.useState(null),[x,S]=o.useState(null),k=p??[],N=f??[],P=!!s,w=yn(r,a),U=d&&(p===void 0||f===void 0),q=k.length>0||N.length>0,K=m?.contact?._id,Z=bn(t,r==="contributor"?K:void 0,s),E=P&&a!==void 0&&a!=="capture_open",B=P?"Memory Project sessions":"Sessions",le=P?"Walter calls for this Memory Project are scheduled appointments. Review scheduled contributor calls and completed story calls here.":"Scheduled Walter calls and Call Records for this group.",$=P?"Schedule a call":"Schedule",X=P?E?"Capture is closed":r==="viewer"?"Sessions are read-only":"No Memory Project calls scheduled yet":"No sessions yet",G=P?E?"Capture is closed for this Memory Project. New contributor calls can no longer be scheduled.":r==="viewer"?"Viewers can review scheduled and completed Walter calls here after capture.":r==="contributor"?"Schedule your Walter call during capture. Walter will call at the appointment time you choose.":"Schedule Walter to call you or a contributor during capture. Calls are appointment-only for this Memory Project.":"Group Walter calls and Call Records will appear here.",ae=P?"Upcoming Walter calls":"Upcoming",ee=P?"Completed Walter calls":"Call Records",Q=E?"Capture closed":"Read-only access",M=async()=>{if(g){S(null);try{await j({scheduledCallId:g._id}),h(null)}catch(_){S(_ instanceof Error?_.message:"Failed to cancel session")}}};return e.jsxs("div",{className:"space-y-6",children:[!P&&e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:B}),e.jsx("span",{className:"rounded-full bg-grey-1 px-2.5 py-1 text-xs font-semibold text-grey-5 dark:bg-grey-2",children:Xs(r)})]}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:le})]}),w&&e.jsx(Et,{to:"/sessions/schedule",search:Z,children:e.jsxs(F.span,{whileHover:{scale:1.03},whileTap:{scale:.97},className:"inline-flex items-center justify-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-medium text-white shadow-md transition-shadow hover:shadow-lg",children:[e.jsx(Jt,{size:16,"aria-hidden":"true"}),$]})})]}),x&&e.jsxs("div",{className:"flex items-center justify-between rounded-xl bg-red-50 px-4 py-3 text-sm text-red-600 dark:bg-red-900/10 dark:text-red-400",children:[e.jsx("span",{children:x}),e.jsx("button",{type:"button",onClick:()=>S(null),className:"ml-3 text-red-400 hover:text-red-600",children:e.jsx(fe,{size:14,"aria-hidden":"true"})})]}),P&&e.jsxs("div",{"data-testid":"memory-project-sessions-layout",className:"grid gap-5 lg:grid-cols-[minmax(0,2fr)_minmax(280px,1fr)] lg:items-start",children:[e.jsxs("section",{"data-testid":"memory-project-sessions-calls-container",className:"rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{"data-testid":"memory-project-sessions-heading-icon",size:18,className:"text-primary","aria-hidden":"true"}),e.jsx("span",{"data-testid":"memory-project-sessions-eyebrow",className:"text-sm font-bold uppercase text-grey-7",children:"Sessions"})]}),w&&e.jsx(Et,{to:"/sessions/schedule",search:Z,className:"shrink-0",children:e.jsxs(F.span,{whileHover:{scale:1.02},whileTap:{scale:.98},className:"inline-flex items-center justify-center gap-2 rounded-lg bg-memory-cta px-4 py-2.5 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 dark:bg-grey-3 dark:hover:bg-grey-4",children:[e.jsx(Jt,{size:16,"aria-hidden":"true"}),$]})}),!w&&e.jsxs("span",{className:"inline-flex shrink-0 items-center justify-center gap-2 rounded-lg bg-grey-2 px-4 py-2.5 text-sm font-semibold text-grey-4",children:[e.jsx(Jt,{size:16,"aria-hidden":"true"}),Q]})]}),e.jsxs("div",{className:"mt-4 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"font-primary text-xl font-bold text-grey-7",children:B}),e.jsx("span",{className:"rounded-full bg-grey-1 px-2.5 py-1 text-xs font-semibold text-grey-5 dark:bg-grey-2",children:Xs(r)})]}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:le})]})]}),U&&e.jsxs("div",{className:"mt-5 flex items-center gap-2 rounded-xl border border-grey-1 bg-grey-0 px-4 py-3 text-sm text-grey-4 dark:border-transparent dark:bg-grey-2",children:[e.jsx(Xe,{size:16,className:"animate-spin","aria-hidden":"true"}),"Loading sessions"]}),!U&&!q&&e.jsx("div",{className:"mt-5 rounded-xl border border-dashed border-grey-2 px-4 py-6",children:e.jsx(os,{icon:Ps,title:X,description:G})}),!U&&q&&e.jsxs("div",{className:"mt-6",children:[k.length>0&&e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-grey-5",children:ae}),e.jsx(ta,{sessions:k,role:r,viewerContactId:K,isMemoryProject:P,className:"mt-3 space-y-3",onEdit:_=>{S(null),b(_)},onCancel:_=>{S(null),h(_)}})]}),N.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-grey-5",children:ee}),e.jsx(ra,{calls:N,isMemoryProject:P,className:"mt-3 space-y-3"})]})]})]}),e.jsx(Sn,{memoryProjectPhase:a,memoryProjectCaptureWindowStartsAt
1:i,memoryProjectCaptureWindowEndsAt:l,scheduledCount:k.length,completedCount:N.length})]}),!P&&U&&e.jsxs("div",{className:"flex items-center gap-2 rounded-xl border border-grey-1 bg-white px-4 py-3 text-sm text-grey-4 dark:border-grey-2 dark:bg-grey-1",children:[e.jsx(Xe,{size:16,className:"animate-spin","aria-hidden":"true"}),"Loading sessions"]}),!P&&!U&&!q&&e.jsx(os,{icon:Ps,title:X,description:G,action:w&&!P?e.jsx(Et,{to:"/sessions/schedule",search:Z,children:e.jsxs("span",{className:"inline-flex items-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-medium text-white shadow-sm",children:[e.jsx(Jt,{size:15,"aria-hidden":"true"}),$]})}):void 0}),!P&&k.length>0&&e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zt,{size:15,className:"text-primary","aria-hidden":"true"}),e.jsx("h3",{className:"text-sm font-semibold text-grey-6",children:ae}),e.jsx("span",{className:"rounded-full bg-primary-light px-2 py-0.5 text-[10px] font-bold text-primary",children:k.length})]}),e.jsx(ta,{sessions:k,role:r,viewerContactId:K,isMemoryProject:P,className:"space-y-3",onEdit:_=>{S(null),b(_)},onCancel:_=>{S(null),h(_)}})]}),!P&&N.length>0&&e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-grey-5",children:ee}),e.jsx(ra,{calls:N,isMemoryProject:!1,className:"space-y-3"})]}),e.jsx(lt,{children:y&&e.jsx(kn,{session:y,isMemoryProject:P,memoryProjectCaptureWindowStartsAt:i,memoryProjectCaptureWindowEndsAt:l,onClose:()=>b(null)})}),e.jsx(lt,{children:g&&e.jsx(F.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",onClick:()=>h(null),children:e.jsxs(F.div,{initial:{scale:.96,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.96,opacity:0},onClick:_=>_.stopPropagation(),className:"w-full max-w-sm rounded-xl bg-white p-6 shadow-xl dark:bg-grey-0",children:[e.jsx("h3",{className:"font-primary text-lg font-bold text-grey-7",children:P?"Cancel Memory Project call?":"Cancel session?"}),e.jsx("p",{className:"mt-2 text-sm text-grey-4",children:P?"Walter will not call at this appointment time. You can schedule another call during the capture window.":"This scheduled Walter call will be removed from the group Sessions tab."}),e.jsxs("div",{className:"mt-6 flex gap-3",children:[e.jsx("button",{type:"button",onClick:M,className:"inline-flex flex-1 items-center justify-center rounded-full bg-red-500 px-4 py-2.5 text-sm font-medium text-white hover:bg-red-600",children:"Cancel session"}),e.jsx("button",{type:"button",onClick:()=>h(null),className:"rounded-full border border-grey-2 px-4 py-2.5 text-sm font-medium text-grey-5 hover:bg-grey-1",children:"Keep"})]})]})})})]})}const vs=[{sectionKey:"project_overview",ownerTitle:"Project description",memberTitle:"Project description",ownerDescription:"A short explanation of what this Memory Project is collecting and why.",memberDescription:"Start here to understand what this Memory Project is about and why your contribution matters.",visibility:"project_visible",order:1},{sectionKey:"event_or_memory_goal",ownerTitle:"What should this project capture?",memberTitle:"What should this project capture?",ownerDescription:"The main event, memory, or emotional goal Walter should keep in mind.",memberDescription:"The main memory or event the project is trying to preserve.",visibility:"project_visible",order:2},{sectionKey:"important_people",ownerTitle:"People Walter should know",memberTitle:"People Walter should know",ownerDescription:"Key family members, contributors, and sensitive relationship context.",memberDescription:"People who matter to the project and may come up in stories.",visibility:"owner_only",order:3},{sectionKey:"key_dates_and_timeline",ownerTitle:"Important dates",memberTitle:"Important dates",ownerDescription:"Dates from the plan plus any dates that help Walter understand the story.",memberDescription:"Dates that help you understand the capture window and the story timeline.",visibility:"project_visible",order:4},{sectionKey:"source_material_to_collect",ownerTitle:"Photos, videos, and files to collect",memberTitle:"Photos, videos, and files to collect",ownerDescription:"Photos, videos, audio clips, documents, notes, links, or other files contributors can upload.",memberDescription:"Photos, videos, audio clips, documents, notes, links, or files you may be able to share.",visibility:"project_visible",order:5},{sectionKey:"suggested_topics_or_asks",ownerTitle:"Story topics to ask about",memberTitle:"Story topics to talk about",ownerDescription:"Topics you would love contributors to talk about when they speak with Walter.",memberDescription:"Ideas to help you remember what you might want to talk about with Walter.",visibility:"project_visible",order:6},{sectionKey:"contributor_asks",ownerTitle:"Assigned contributor topics",memberTitle:"Assigned contributor topics",ownerDescription:"Specific topics you want to assign to specific collaborators.",memberDescription:"Topics assigned by the Owner to help guide specific contributor calls.",visibility:"project_visible",order:7},{sectionKey:"open_questions_or_missing_context",ownerTitle:"Questions to resolve",memberTitle:"Questions to resolve",ownerDescription:"Missing details the Owner should confirm before Walter asks others.",memberDescription:"Open details Walter may still be trying to understand.",visibility:"owner_only",order:8},{sectionKey:"important_places",ownerTitle:"Places Walter should know",memberTitle:"Places Walter should know",ownerDescription:"Locations, venues, homes, or places that shape the memory.",memberDescription:"Places that may help you remember the story more clearly.",visibility:"owner_only",order:9},{sectionKey:"themes_and_emotional_goals",ownerTitle:"Themes and emotional goals",memberTitle:"Themes and emotional goals",ownerDescription:"The tone, themes, and feelings the final keepsake should preserve.",memberDescription:"The tone and feelings this project is trying to preserve.",visibility:"owner_only",order:10},{sectionKey:"keepsakes_handoff_notes",ownerTitle:"Keepsake notes",memberTitle:"Keepsake notes",ownerDescription:"Owner-only notes for the later keepsake handoff.",memberDescription:"Notes for the later keepsake handoff.",visibility:"owner_only",order:11}],eo=vs.map(t=>t.sectionKey),to=Object.fromEntries(vs.map(t=>[t.sectionKey,t])),Pn=Object.fromEntries(vs.map(t=>[t.sectionKey,t.visibility]));function Mn(t){return Pn[t]??"owner_only"}const Tn=new Set(eo);function Er(t,r){const s=to[t.sectionKey];return s?{title:r==="owner"?s.ownerTitle:s.memberTitle,description:r==="owner"?s.ownerDescription:s.memberDescription}
1:{title:t.title,description:r==="owner"?"Context Walter should keep in mind.":"Helpful context for this project."}}function Rn(t,r){const s=to[t];return{_id:`default-${t}`,sectionKey:t,title:s?.ownerTitle??t,visibility:Mn(t),order:r}}function sa(t,r){return r==="owner"||t.visibility==="project_visible"}function En(t,r){const s=new Map(t.map(l=>[l.sectionKey,l])),a=eo.map((l,d)=>s.get(l)??Rn(l,d+1)).filter(l=>sa(l,r)),i=t.filter(l=>!Tn.has(l.sectionKey)&&sa(l,r));return[...a,...i]}function _r(t){return t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,80)||`topic-${Date.now()}`}function aa(t){return t?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric"}).format(new Date(t)):null}function _n(t,r){const s=r?" Use Edit context to add it.":"";switch(t){case"source_material_to_collect":return`No upload guidance added yet.${s}`;case"suggested_topics_or_asks":return`No story topics added yet.${s}`;case"contributor_asks":return"No contributor topics assigned yet.";default:return`No details added yet.${s}`}}function zn({memoryProjectId:t,groupName:r,role:s,openEditorRequestKey:a=0,isSetupGuidanceDismissed:i=!1,onDismissSetupGuidance:l}){const d=be(O.memoryProjectGuides.listProjectGuide,{memoryProjectId:t}),m=ne(O.memoryProjectGuides.saveProjectGuide),[p,f]=o.useState(!1),[j,y]=o.useState(null),[b,g]=o.useState({}),[h,x]=o.useState([]),[S,k]=o.useState(""),[N,P]=o.useState(!1),[w,U]=o.useState(null),q=d?.topics??[],K=d?.contributorAsks??[],Z=d?.role??s,E=Z==="owner",B=o.useMemo(()=>En(d?.sections??[],Z),[Z,d?.sections]),le=B.find(z=>z.sectionKey===j)??B[0],$=o.useCallback(()=>{g(Object.fromEntries(B.map(z=>[z.sectionKey,z.body??""]))),x(q),k(""),y(z=>z??B[0]?.sectionKey??null)},[B,q]);o.useEffect(()=>{B.length&&(p||$())},[p,B.length,$]);const X=o.useMemo(()=>h.filter(z=>z.title.trim()),[h]),G=o.useCallback(()=>{$(),U(null),f(!0)},[$]);if(o.useEffect(()=>{!a||!E||!B.length||G()},[a,E,G,B.length]),d===void 0)return e.jsxs("section",{className:"rounded-2xl border border-grey-1 bg-white p-6 dark:border-transparent dark:bg-grey-1",children:[e.jsx("div",{className:"h-5 w-48 animate-pulse rounded bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"mt-4 h-24 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2"})]});if(!d)return null;const ae=E?"What to set up before inviting contributors":"What this project is collecting",ee=E?"Use this guide to tell Walter what the project is about, who matters, what sources are missing, and what contributors should be invited to share.":`A friendly guide to the memories, topics, and materials ${r} is collecting.`,Q=()=>{const z=S.trim();if(!z)return;const C=_r(z);if(h.some(L=>(L.key??_r(L.title))===C)){k("");return}x(L=>[...L,{_id:`draft-${C}`,key:C,title:z,visibility:"project_visible"}]),k("")},M=z=>{x(C=>C.filter(L=>L._id!==z._id))},_=()=>{$(),U(null),f(!1)},T=async()=>{if(E){P(!0),U(null);try{const z=B.flatMap(v=>{const D=b[v.sectionKey]??"";return D===(v.body??"")?[]:[{sectionKey:v.sectionKey,title:v.title,body:D,visibility:v.visibility,order:v.order,source:"owner_manual"}]}),C=new Set(h.filter(v=>!v._id.startsWith("draft-")).map(v=>v._id)),L=q.flatMap(v=>C.has(v._id)?[]:[{topicId:v._id,...v.key!==void 0?{key:v.key}:{},title:v.title,prompt:v.prompt,visibility:v.visibility,source:"owner_manual",archivedAt:Date.now()}]),H=h.flatMap(v=>{const D=q.find(de=>de._id===v._id),se=v.key??_r(v.title);return D&&se===(D.key??_r(D.title))&&v.title===D.title&&(v.prompt??"")===(D.prompt??"")&&v.visibility===D.visibility?[]:[{...v._id.startsWith("draft-")?{}:{topicId:v._id},key:se,title:v.title,prompt:v.prompt,visibility:v.visibility,source:"owner_manual"}]});await m({memoryProjectId:t,sections:z,topics:[...L,...H]}),f(!1)}catch(z){console.error(z),U("Could not save project guide. Please try again.")}finally{P(!1)}}};return e.jsxs("section",{className:"rounded-lg border border-grey-2 bg-white p-5 shadow-sm dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"mb-5 flex flex-col items-start justify-between gap-3 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(or,{size:18,className:"text-primary"}),e.jsx("h2",{className:"text-sm font-bold uppercase text-grey-7",children:"Memory Project guide"})]}),E&&e.jsxs("button",{type:"button",onClick:G,className:"inline-flex items-center gap-2 rounded-lg bg-memory-cta px-4 py-2 text-sm font-semibold text-white transition-colors hover:bg-memory-cta/90 dark:bg-grey-2 dark:text-grey-7 dark:hover:bg-grey-3",children:[e.jsx(Ii,{size:16,"aria-hidden":"true"}),"Edit",e.jsx("span",{className:"hidden sm:inline",children:" context"})]})]}),(!E||!i)&&e.jsx("div",{className:"mb-5 rounded-lg border border-primary/15 bg-primary-light/40 p-4 dark:border-primary/20 dark:bg-primary/10",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-bold text-grey-7 dark:text-grey-7",children:ae}),e.jsx("p",{className:"mt-2 text-sm leading-relaxed text-grey-6 dar
1k:text-grey-5",children:ee})]}),E&&l&&e.jsx("button",{type:"button",onClick:l,"aria-label":"Dismiss setup guidance",className:"-mr-1 -mt-1 shrink-0 rounded-full p-1.5 text-grey-4 transition-colors hover:bg-white/80 hover:text-grey-7 dark:hover:bg-grey-2",children:e.jsx(fe,{size:16,"aria-hidden":"true"})})]})}),e.jsx("div",{className:"divide-y divide-grey-1 dark:divide-grey-2",children:B.map(z=>{const C=Er(z,Z),L=!!z.body?.trim(),H=z.sectionKey==="suggested_topics_or_asks"&&q.length>0,v=z.sectionKey==="contributor_asks"&&K.length>0,D=L||H||v;return e.jsxs("details",{open:!0,className:"group py-3 first:pt-0",children:[e.jsxs("summary",{className:"flex cursor-pointer list-none items-start justify-between gap-4",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"font-semibold text-grey-7",children:C.title})}),e.jsx(wr,{size:18,className:"mt-1 shrink-0 text-grey-4 transition-transform group-open:rotate-180"})]}),e.jsx("div",{className:"mt-3 text-sm text-grey-5",children:C.description}),E&&e.jsx("div",{className:"mt-2 inline-flex rounded-md bg-grey-0 px-2 py-1 text-xs font-semibold text-grey-4 dark:bg-grey-0",children:z.visibility==="owner_only"?"Only visible to owner":"Visible to project members"}),L&&e.jsx("p",{className:"mt-4 text-sm leading-relaxed text-grey-6",children:z.body}),z.sectionKey==="suggested_topics_or_asks"&&q.length>0&&e.jsx("div",{className:"mt-4 grid gap-2 sm:grid-cols-2",children:q.map(se=>e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-grey-1 px-3 py-2 text-sm text-grey-6 dark:border-grey-2",children:[e.jsx(cr,{size:16,className:"mt-0.5 shrink-0 text-memory"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-semibold text-grey-7",children:se.title}),se.prompt&&e.jsx("p",{className:"mt-1 leading-relaxed",children:se.prompt})]})]},se._id))}),z.sectionKey==="contributor_asks"&&K.length>0&&e.jsx("div",{className:"mt-4 grid gap-2 sm:grid-cols-2",children:K.map(se=>e.jsxs("div",{className:"rounded-lg border border-grey-1 px-3 py-2 text-sm text-grey-6 dark:border-grey-2",children:[e.jsx("div",{className:"font-semibold text-grey-7",children:se.title}),se.prompt&&e.jsx("p",{className:"mt-1 leading-relaxed",children:se.prompt}),aa(se.dueAt)&&e.jsxs("div",{className:"mt-2 text-xs font-semibold text-grey-4",children:["Due ",aa(se.dueAt)]})]},se._id))}),!D&&e.jsx("div",{className:"mt-4 rounded-lg border border-dashed border-grey-2 bg-grey-0/70 px-4 py-3 text-sm text-grey-4 dark:border-transparent dark:bg-grey-0",children:_n(z.sectionKey,E)})]},z._id)})}),p&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4 backdrop-blur-sm",children:e.jsxs("section",{className:"flex max-h-[88vh] w-full max-w-5xl flex-col overflow-hidden rounded-2xl bg-white shadow-2xl dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 border-b border-grey-1 p-5 dark:border-grey-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(or,{size:18,className:"text-primary"}),e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Edit context"})]}),e.jsx("p",{className:"mt-1 text-sm text-grey-5",children:"Review each section, adjust the summary, and add or remove suggested topics before saving."})]}),e.jsx("button",{type:"button",onClick:_,className:"rounded-full p-2 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:hover:bg-grey-2","aria-label":"Close",children:e.jsx(fe,{size:20})})]}),e.jsxs("div",{className:"grid min-h-0 flex-1 md:grid-cols-[280px_minmax(0,1fr)]",children:[e.jsx("nav",{className:"min-h-0 overflow-y-auto border-b border-grey-1 p-3 md:border-b-0 md:border-r dark:border-grey-2",children:B.map(z=>{const C=Er(z,"owner");return e.jsxs("button",{type:"button",onClick:()=>y(z.sectionKey),className:`w-full rounded-xl border border-transparent px-3 py-3 text-left transition-colors ${le?.sectionKey===z.sectionKey?"bg-primary-light text-primary dark:border-primary/25 dark:bg-primary/15 dark:text-grey-7":"text-grey-6 hover:bg-grey-1 dark:text-grey-3 dark:hover:bg-grey-2"}`,children:[e.jsx("div",{className:"text-sm font-semibold",children:C.title}),e.jsx("div",{className:"mt-1 text-xs opacity-80",children:z.visibility==="owner_only"?"Only visible to owner":"
1Visible to project members"})]},z._id)})}),e.jsx("div",{className:"min-h-0 overflow-y-auto p-5",children:le&&e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:le.visibility==="owner_only"?"Only visible to owner":"Visible to project members"}),e.jsx("h3",{className:"mt-1 font-primary text-2xl font-bold text-grey-7",children:Er(le,"owner").title}),e.jsx("p",{className:"mt-1 text-sm text-grey-5",children:Er(le,"owner").description})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-grey-4",children:"Short description"}),e.jsx("textarea",{value:b[le.sectionKey]??"",onChange:z=>g(C=>({...C,[le.sectionKey]:z.target.value})),rows:12,className:"mt-2 min-h-[18rem] w-full resize-y rounded-xl border border-grey-2 bg-white px-4 py-3 text-sm leading-relaxed text-grey-7 outline-none focus:border-primary focus:ring-2 focus:ring-primary/10 dark:bg-grey-1"})]}),le.sectionKey==="suggested_topics_or_asks"&&e.jsxs("div",{className:"rounded-xl border border-grey-1 p-4 dark:border-grey-2",children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsx(pt,{size:16,className:"text-primary"}),e.jsx("h4",{className:"text-sm font-bold text-grey-7",children:"Suggested topics"})]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:X.map(z=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-grey-1 px-3 py-2 text-sm text-grey-6",children:[e.jsx("span",{children:z.title}),e.jsx("button",{type:"button",onClick:()=>M(z),className:"rounded-full p-1 text-grey-4 hover:bg-grey-1 hover:text-grey-7","aria-label":`Remove ${z.title}`,children:e.jsx(gt,{size:14})})]},z._id))}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("input",{value:S,onChange:z=>k(z.target.value),onKeyDown:z=>{z.key==="Enter"&&(z.preventDefault(),Q())},placeholder:"Add a topic...",className:"min-w-0 flex-1 rounded-full border border-grey-2 px-4 py-2 text-sm outline-none focus:border-primary focus:ring-2 focus:ring-primary/10"}),e.jsxs("button",{type:"button",onClick:Q,className:"inline-flex items-center gap-2 rounded-full border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 hover:bg-grey-1",children:[e.jsx(at,{size:16}),"Add"]})]})]})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3 border-t border-grey-1 p-5 dark:border-grey-2",children:[w&&e.jsx("p",{className:"mr-auto self-center text-sm font-semibold text-red-600",role:"alert",children:w}),e.jsx("button",{type:"button",onClick:_,className:"rounded-full border border-grey-2 px-5 py-2 text-sm font-semibold text-grey-6 hover:bg-grey-1",children:"Cancel"}),e.jsx("button",{type:"button",onClick:T,disabled:N,className:"rounded-full bg-primary px-5 py-2 text-sm font-semibold text-white disabled:cursor-not-allowed disabled:opacity-60",children:N?"Saving...":"Done"})]})]})})]})}function Dn({captureWindowEndsAtLabel:t,onStartCall:r,onScheduleCall:s}){return e.jsx("section",{className:"rounded-2xl border border-primary/20 bg-primary-light p-5 dark:border-transparent dark:bg-grey-1 sm:p-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-white/75 px-3 py-1 text-xs font-semibold text-primary dark:bg-grey-2",children:[e.jsx(Zt,{size:14,"aria-hidden":"true"}),"Your Memory Project contribution"]}),e.jsx("h2",{className:"mt-3 font-primary text-xl font-bold text-grey-7",children:"Talk with Walter"}),e.jsxs("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-grey-5",children:["Start now or choose an appointment while capture is open. Walter will use the Project Guide, contributor asks, and source requests to help you prepare.",t?` Capture closes ${t}.`:""]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row lg:flex-col",children:[e.jsxs("button",{type:"button",onClick:r,className:"inline-flex items-center justify-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-primary/90",children:[e.jsx(kr,{size:16,"aria-hidden":"true"}),"Talk now"]}),e.jsxs("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center gap-2 rounded-full border border-primary/25 bg-white px-5 py-2.5 text-sm font-semibold text-primary shadow-sm transition-colors hover:bg-primary-light dark:bg-grey-1",children:[e.jsx(Zt,{size:16,"aria-hidden":"true"}),"Schedule your Walter call"]})]})]})})}function An({groupName:t,onClose:r,onStartCall:s,onScheduleCall:a}){const i=o.useRef(null),l=o.useRef(null);return o.useEffect(()=>{const d=i.current;if(d)return d.open||d.showModal(),l.current?.focus({preventScroll:!0}),()=>{d.open&&d.close()}},[]),e.jsx(F.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"pointer-events-none fixed inset-0 z-50",children:e.jsx("dialog",{ref:i,className:"pointer-events-auto fixed inset-0 z-50 m-0 flex h-full w-full max-w-none items-center justify-center border-0 bg-transparent p-4 backdrop:bg-black/40 backdrop:backdrop-blur-sm","aria-labelledby":"memory-project-contributor-welcome-title","aria-modal":"true",onCancel:d=>{d.preventDefault(),r()},children:e.jsxs("section",{className:"w-full max-w-2xl overflow-hidden rounded-3xl bg-white shadow-2xl dark:bg-grey-1",children:[e.jsxs("div",{className:"p-6 sm:p-8",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-primary/20 bg-primary-light px-3 py-1 text-sm font-semibold text-primary",children:[e.jsx(pt,{size:16,"aria-hidden":"true"}),"Contributor invite accepted"]}),e.jsxs("h2",{id:"memory-project-contributor-welcome-title",className:"mt-4 font-primary text-3xl font-bold leading-tight text-grey-7",children:["Welcome to ",t]}),e.jsx("p",{className:"mt-4 text-base leading-relaxed text-grey-5",children:"Walter will help turn your memories, photos, and source material into stories for this Memory Project. Start with a scheduled call, then add anything that helps the Owner preserve the full picture."}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-3",children:["Read the Project Guide","Schedule your Walter call","Share photos or files"].map(d=>e.jsxs("div",{className:"rounded-2xl border border-grey-1 p-4 text-sm font-semibold text-grey-7 dark:border-grey-2",children:[e.jsx(vt,{size:17,className:"mb-3 text-primary","aria-hidden":"true"}),d]},d))})]}),e.jsxs("div",{className:"flex flex-col-reverse justify-end gap-3 border-t border-grey-1 p-6 dark:border-grey-2 sm:flex-row sm:p-8",children:[e.jsx("button",{type:"button",onClick:r,className:"inline-flex items-center justify-center rounded-full border border-grey-2 px-5 py-3 text-sm font-semibold text-grey-7 transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:"Not now"}),e.jsxs("button",{ref:l,type:"button",onClick:s,className:"inline-flex items-center justify-center gap-2 rounded-full bg-primary px-5 py-3 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-primary/90",children:[e.jsx(kr,{size:18,"aria-hidden":"true"}),"Talk now"]}),e.jsxs("button",{type:"button",onClick:a,className:"inline-flex items-center justify-center gap-2 rounded-full border border-grey-2 px-5 py-3 text-sm font-semibold text-grey-7 transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx(Zt,{size:18,"aria-hidden":"true"}),"Schedule for later"]})]})]})})})}const oa={owner:{title:"Generated pages",body:"Walter-created stories, people, places, themes, and events appear here after contribution calls or source-backed updates."},contributor:{title:"Your pages can grow here",body:"After you talk with Walter, the memories you share can become generated pages in this Library."},viewer:{title:"Finished project pages",body:"Published Memory Project pages shared with you appear here as read-only reference material."}},$n=200;function Un(t,r,s=`${r}s`){return`${t} ${t===1?r:s}`}function Ln({groupId:t,slug:r,sharedPages:s,canManageLibrary:a,isOwner:i,memoryProjectRole:l}){const d=oa[l]??oa.viewer,m=!t.startsWith("group-"),f=be(O.groups.listSharedPages,m?{groupId:t,limit:$n}:"skip")?.length??s.length,j=f===0?"No generated pages yet":Un(f,"generated page");return e.jsx(Oa,{groupId:t,slug:r,sharedPages:s,canManageLibrary:a,isOwner:i,isMemoryProject:!0,memoryProjectOverview:{title:d.title,body:d.body,summary:j}})}const ia={owner:{title:"Source files for this project",body:"Photos, video stills, audio, notes, scans, and documents collect here before Walter uses them in generated pages or collections."},contributor:{title:"Share files Walter should know about",body:"Upload photos, videos, audio, notes, links, or documents that could help the project. Open source requests are listed below."},viewer:{title:"Project source files",body:"Source files shared for this Memory Project are available here as read-only reference material."}};function Fn({groupId:t,slug:r,canManageLibrary:s,memoryProjectId:a,memoryProjectPhase:i,memoryProjectRole:l}){const d=!t.startsWith("group-"),m=be(O.files.listByGroupWithUrls,d?{groupId:t}:"skip")??[],p=be(O.memoryProjectSources.listSourceRequests,a?{memoryProjectId:a}:"skip"),f=ia[l]??ia.viewer;return e.jsx("div",{children:e.jsx(ds,{groupId:t,slug:r,canManageLibrary:s,memoryProjectId:a,memoryProjectPhase:i,prefetchedFiles:m,prefetchedSourceRequestResult:p,usePrefetchedSourceData:!0,memoryProjectOverview:{title:f.title,body:f.body}})})}function Br(t){return Number.isFinite(t)?Math.min(100,Math.max(0,t)):50}function Rt(t){return{xPercent:50,yPercent:Br(t),scale:1,rotationDegrees:0}}function lr(t){return Br(t?.yPercent??50)}function On(t,r,s,a){return t||r||s?Rt(a):void 0}function ro(t){if(t)return{xPercent:Br(t.xPercent??50),yPercent:Br(t.yPercent??50),scale:Number.isFinite(t.scale)?Math.min(4,Math.max(.1,t.scale??1)):1,rotationDegrees:Number.isFinite(t.rotationDegrees)?Math.min(360,Math.max(-360,t.rotationDegrees??0)):0}}function Bn(t){return Xt(t.coverFileId)||Xt(t.coverImageStorageId)?t.type==="memoryAlbum"?t.contentItems.some(Kn)&&t.contentItems.some(Gn):t.contentItems.some(qn)&&t.contentItems.some(Wn):!1}function Kn(t){return t.itemType==="page"||t.itemType==="text"&&xs(t)}function Gn(t){return t.itemType==="quote"||t.itemType==="source"||t.itemType==="media"}function qn(t){return(t.itemType==="media"||t.itemType==="source")&&Xt(t.fileId)}function Wn(t){return(t.itemType==="text"||t.itemType==="page"||t.itemType==="quote")&&xs(t)?!0:(t.itemType==="media"||t.itemType==="source")&&Xt(t.fileId)&&t.timeline?.track==="audio"?xs(t)||t.timeline.transcriptStartSeconds!==void 0||t.timeline.transcriptEndSeconds!==void 0:!1}function xs(t){return Xt(t.title)||Xt(t.summary)||Xt(t.body)}function Xt(t){return t!==void 0&&t.trim().length>0}function rr(t,r,s){const a=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.min(s,Math.max(r,a))}function Vn(t){if(!t)return;const r={};(t.track==="visual"||t.track==="audio")&&(r.track=t.track);const s=typeof t.sourceDurationSeconds=="number"&&t.sourceDurationSeconds>
10?rr(t.sourceDurationSeconds,1,86400):void 0,a=typeof t.trimStartSeconds=="number"?rr(t.trimStartSeconds,0,s??86400):void 0,i=typeof t.trimEndSeconds=="number"?rr(t.trimEndSeconds,a!==void 0?a+1:1,s??86400):void 0,l=typeof t.transcriptStartSeconds=="number"?rr(t.transcriptStartSeconds,0,s??86400):void 0,d=typeof t.transcriptEndSeconds=="number"?rr(t.transcriptEndSeconds,l!==void 0?l+1:1,s??86400):void 0,m=typeof t.durationSeconds=="number"&&t.durationSeconds>0?rr(t.durationSeconds,1,86400):a!==void 0&&i!==void 0?Math.max(1,i-a):void 0;return s!==void 0&&(r.sourceDurationSeconds=s),a!==void 0&&(r.trimStartSeconds=a),i!==void 0&&(r.trimEndSeconds=i),l!==void 0&&(r.transcriptStartSeconds=l),d!==void 0&&(r.transcriptEndSeconds=d),m!==void 0&&(r.durationSeconds=m),Object.keys(r).length>0?r:void 0}function so(t){return Vn(t)}function Hn(t){return t.itemType==="media"||t.itemType==="source"}function ao(t){return(Hn(t)||!!(t.mediaUrl||t.fileId))&&t.itemType!=="quote"&&t.timeline?.track!=="audio"}function Yn(t,r){return{...t,order:r,timeline:so(t.timeline),...ao(t)?{imageCrop:ro(t.imageCrop)??Rt(50)}:{imageCrop:void 0}}}function hr(t){return t.filter(r=>r.itemType).map(r=>({itemType:r.itemType,pageId:r.pageId,quoteId:r.quoteId,fileId:r.fileId,title:r.title,summary:r.summary,body:r.body,mediaUrl:r.fileId?r.mediaUrl:void 0,mediaRemoved:r.itemType==="page"&&r.mediaRemoved?!0:void 0,imageCrop:ao(r)?ro(r.imageCrop):void 0,timeline:so(r.timeline),order:r.order}))}function Qn(t){return Bn({...t,contentItems:hr(t.contentItems)})}function Jn(t){const r=[];for(let s=0;s<t.length;s+=2)r.push([t[s],t[s+1]??null]);return r}function zr({children:t,view:r}){return e.jsx(F.div,{"data-keepsakes-view":r,initial:"hidden",animate:"show",variants:Ue,children:t},r)}const oo=72,io=140,na=420,Xn=594,Zn=720,el=520,tl=1120;function rl(t){const r=t.trim().length;return r>60?"text-2xl leading-tight":r>44?"text-3xl leading-tight":r>30?"text-4xl leading-tight":"text-5xl leading-tight"}function sl(t){const r=(t??"").trim().length;return r>110?"text-sm leading-5":r>70?"text-base leading-snug":"text-lg leading-snug"}const Wr=[{type:"memoryAlbum",label:"Memory Album",description:"A polished story-led keepsake built from the project library.",icon:st},{type:"memoryReel",label:"Memory Reel",description:"A short, cinematic highlight assembled from media and captured moments.",icon:nr}],al="Add a public title before publishing.",no="Add a public description before publishing.",lo="Add the final landscape video URL before publishing.",co="Add the final portrait video URL before publishing.",ol="The automatic album export is not ready in this environment yet. Save the draft and try publishing again after the export finishes.";function dt(t){return Wr.find(r=>r.type===t)?.label??"Keepsake"}function mo(t){return t.eligible===!0||t.readinessStatus==="ready"}function il(t){const r=new Map;for(const s of t)for(const a of s.criteria??[]){const i=a.key??a.label;!i||r.has(i)||r.set(i,a)}return Array.from(r.values())}function nl(t){return typeof t.currentCount!="number"||typeof t.requiredCount!="number"?null:`${t.currentCount}/${t.requiredCount}`}function ll({memoryProjectId:t,memoryProjectRole:r,groupName:s,onComingSoon:a}){const[i,l]=o.useState(!0),[d,m]=o.useState("hub"),[p,f]=o.useState("memoryAlbum"),[j,y]=o.useState(null),[b,g]=o.useState(null),[h,x]=o.useState(!1),S=r==="owner",k=be(O.memoryProjectKeepsakes.getKeepsakesHubState,{memoryProjectId:t}),N=be(O.memoryProjectKeepsakes.getWalterSmartGenerationEligibility,S?{memoryProjectId:t}:"skip"),P=be(O.memoryProjectKeepsakes.getStudioState,S?{memoryProjectId:t}:"skip"),w=be(O.memoryProjectCollections.listMemoryProjectCollectionSummaries,S?{memoryProjectId:t}:"skip"),U=be(O.memoryProjectCollections.getCollectionEligibility,S&&d==="studio"?{memoryProjectId:t}:"skip"),q=be(O.memoryProjectKeepsakes.getCollectionStudioSeed,j?.kind==="collection"?{memoryProjectId:t,type:j.type,collectionId:j.collectionId}:"skip"),K=be(O.memoryProjectKeepsakes.getWalterSmartStudioSeed,S?{memoryProjectId:t,type:"memoryAlbum"}:"skip"),Z=be(O.memoryProjectKeepsakes.getWalterSmartStudioSeed,S?{memoryProjectId:t,type:"memoryReel"}:"skip"),E=ne(O.memoryProjectKeepsakes.createKeepsakeIntent),B=ne(O.memoryProjectKeepsakes.createDraftSnapshot),le=ne(O.memoryProjectKeepsakes.deleteDraft),$=ne(O.memoryProjectKeepsakes.publishKeepsake),X=ne(O.memoryProjectKeepsakes.publishWalterSmartPreview),G=ne(O.memoryProjectKeepsakes.saveWalterSmartDraft),ae=ne(O.memoryProjectKeepsakes.unpublishKeepsake),ee=ne(O.memoryProjectKeepsakes.updateDraftSnapshot),Q=k?.publishedKeepsake
1s??[],M=Q.length>0,_=o.useMemo(()=>N?.deliverables??[],[N?.deliverables]),T=_.some(mo),z=o.useMemo(()=>({memoryAlbum:K,memoryReel:Z}),[K,Z]),C=z[p],L=o.useMemo(()=>({memoryAlbum:z.memoryAlbum?.type==="memoryAlbum"&&z.memoryAlbum.ready===!0,memoryReel:z.memoryReel?.type==="memoryReel"&&z.memoryReel.ready===!0}),[z]),H=o.useMemo(()=>il(_),[_]),v=o.useMemo(()=>(P?.keepsakes??[]).filter(c=>c.type===p&&c.currentDraftSnapshot&&c.status!=="published").sort((c,Y)=>(Y.updatedAt??0)-(c.updatedAt??0)),[p,P?.keepsakes]),D=o.useMemo(()=>(w??[]).filter(c=>c.collectionId&&c.kind!=="keepsake_smart_source"&&c.status!=="archived"&&(c.itemCount??0)>0).slice(0,4),[w]),se=c=>{f(c),y(null),m("start")},de=c=>{if(c.kind==="walter"&&!L[c.type]){a();return}f(c.type),y(c),m("studio")},ze=()=>{y(null),m("hub")},ke=()=>{y(null),m("start")},Pe=async c=>{const Y=Pl(c.trim()||`${s} ${dt(p)}`,v.map(Il));x(!0);try{const ie=await E({memoryProjectId:t,type:p,sourceType:"blankDraft",title:Y});await B({keepsakeId:ie.keepsakeId,title:Y,contentItems:[]}),g({keepsakeId:ie.keepsakeId,title:Y,type:p,contentItems:[]}),de({kind:"draft",keepsakeId:ie.keepsakeId,fallbackTitle:Y,type:p})}finally{x(!1)}},Ne=async c=>{await le({keepsakeId:c})},ce=c=>{c&&window.open(c,"_blank","noopener,noreferrer")},oe=c=>({title:c.title,heroTitle:c.heroTitle,heroDescription:c.heroDescription,coverFileId:c.coverFileId,coverImageCrop:c.coverImageCrop,coverImageStorageId:c.coverImageStorageId,albumPdfUrl:c.albumPdfUrl,horizontalVideoUrl:c.horizontalVideoUrl,verticalVideoUrl:c.verticalVideoUrl,contentItems:hr(c.contentItems)}),te=async c=>{if(!j)return null;if(j.kind==="walter"&&!L[j.type])throw new Error("Walter smart preview is not ready to publish.");x(!0);try{let Y=null;if(j.kind==="walter")Y=await X({memoryProjectId:t,type:j.type,...oe(c)});else if(j.kind==="collection"){const ie=await E({memoryProjectId:t,type:j.type,sourceType:"collection",sourceCollectionId:j.collectionId,title:c.title});Y=await $({keepsakeId:ie.keepsakeId,...oe(c)})}else Y=await $({keepsakeId:j.keepsakeId,...oe(c)});return ce(Y?.urlPath),ze(),Y}finally{x(!1)}},re=async c=>{c.keepsakeId&&await ae({keepsakeId:c.keepsakeId})},me=async c=>{if(j?.kind!=="collection"||!q)return;const Y=c?.title??q.title??j.label,ie=c?.contentItems??q.contentItems??[];x(!0);try{const ue=await E({memoryProjectId:t,type:j.type,sourceType:"collection",sourceCollectionId:j.collectionId,title:Y});await B({keepsakeId:ue.keepsakeId,title:Y,coverFileId:c?.coverFileId,coverImageCrop:c?.coverImageCrop,coverImageStorageId:c?.coverImageStorageId,coverImageUrl:c?.coverImageUrl,heroDescription:c?.heroDescription,contentItems:hr(ie)}),g({keepsakeId:ue.keepsakeId,title:Y,coverFileId:c?.coverFileId,coverImageCrop:c?.coverImageCrop,coverImageStorageId:c?.coverImageStorageId,coverImageUrl:c?.coverImageUrl,heroDescription:c?.heroDescription,contentItems:ie,type:j.type}),de({kind:"draft",keepsakeId:ue.keepsakeId,fallbackTitle:Y,type:j.type})}finally{x(!1)}},Ce=async c=>{const Y=j?.kind==="walter"?j.type:p,ie=z[Y];if(!L[Y]){a();return}x(!0);try{const ue=await G({memoryProjectId:t,type:Y}),Se=c?.title??ie?.title??`${s} ${dt(Y)}`,Ee=c?.contentItems??ie?.contentItems??[];c&&await ee({keepsakeId:ue.keepsakeId,title:Se,coverFileId:c.coverFileId,coverImageCrop:c.coverImageCrop,coverImageStorageId:c.coverImageStorageId,coverImageUrl:c.coverImageUrl,heroDescription:c.heroDescription,contentItems:hr(Ee)}),g({keepsakeId:ue.keepsakeId,title:Se,coverFileId:c?c.coverFileId:ie?.coverFileId,coverImageCrop:c?c.coverImageCrop:ie?.coverImageCrop,coverImageStorageId:c?c.coverImageStorageId:ie?.coverImageStorageId,coverImageUrl:c?c.coverImageUrl:ie?.coverImageUrl,heroDescription:c?c.heroDescription:ie?.heroDescription,contentItems:Ee,type:Y}),de({kind:"draft",keepsakeId:ue.keepsakeId,fallbackTitle:Se,type:Y})}finally{x(!1)}},he=async c=>{x(!0);try{await ee({keepsakeId:c.keepsakeId,title:c.title,coverFileId:c.coverFileId,coverImageCrop:c.coverImageCrop,coverImageStorageId:c.coverImageStorageId,coverImageUrl:c.coverImageUrl,heroDescription:c.heroDescription,contentItems:hr(c.contentItems)}),g({keepsakeId:c.keepsakeId,title:c.title,type:p,coverFileId:c.coverFileId,coverImageCrop:c.coverImageCrop,coverImageStorageId:c.coverImageStorageId,coverImageUrl:c.coverImageUrl,heroDescription:c.heroDescription,contentItems:c.contentItems})}finally{x(!1)}};return k?S?d==="start"?e.jsx(zr,{view:`start-${p}`,children:e.jsx(dl,{collections:D,drafts:v,groupName:s,isSaving:h,onBack:ze,onCreateBlankDraft:Pe,onDeleteDraft:Ne,onOpenCollection:c=>{c.collectionId&&de({kind:"collection",collectionId:c.collectionId,label:c.name??`${dt(p)} collection`,type:p})},onOpenDraft:c=>{c.keepsakeId&&de({kind:"draft",keepsakeId:c.keepsakeId,fallbackTitle:c.title??void 0,type:p})},onOpenWalter:()=>de({kind:"walter",type:p}),type:p,walterSeed:C}
1)}):d==="studio"&&j?e.jsx(zr,{view:`studio-${j.kind}-${j.type}`,children:e.jsx(pl,{collectionEligibility:U,collectionSeed:q,draft:v.find(c=>j.kind==="draft"&&c.keepsakeId===j.keepsakeId),groupName:s,isSaving:h,localDraftContent:b,onBack:ke,onPublish:te,onSaveCollectionDraft:me,onSaveWalterDraft:Ce,onUpdateDraft:he,session:j,walterSeed:C})}):e.jsx(zr,{view:"hub",children:e.jsxs("div",{className:"grid min-w-0 gap-5 overflow-hidden lg:grid-cols-[minmax(0,1.85fr)_minmax(300px,1fr)] lg:items-start",children:[e.jsxs("div",{className:"min-w-0 space-y-5",children:[M&&e.jsxs("section",{className:"min-w-0 overflow-hidden rounded-2xl border border-grey-1 bg-white shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("button",{type:"button",onClick:()=>l(c=>!c),className:"flex w-full items-center justify-between gap-4 px-5 py-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-inset","aria-expanded":i,children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-xl font-bold text-grey-7",children:"Published Keepsakes"}),e.jsx("p",{className:"mt-1 text-sm text-grey-5",children:"Finished keepsakes currently visible to members."})]}),i?e.jsx(Fa,{size:18,className:"shrink-0 text-grey-4","aria-hidden":"true"}):e.jsx(wr,{size:18,className:"shrink-0 text-grey-4","aria-hidden":"true"})]}),i&&e.jsx("div",{className:"border-t border-grey-1 p-5 dark:border-grey-2",children:e.jsx(ha,{keepsakes:Ll(Q),canManage:!0,onUnpublish:re,onView:ce})})]}),e.jsxs("section",{className:"min-w-0 overflow-hidden rounded-2xl border border-grey-1 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-primary-light px-3 py-1 text-xs font-semibold text-primary",children:[e.jsx(pt,{size:14,"aria-hidden":"true"}),"Walter's Smart Generation"]}),N===void 0?e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:[e.jsx("div",{className:"h-36 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsx("div",{className:"h-36 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"})]}):T?e.jsx(Bl,{groupName:s,deliverables:_,onComingSoon:a,onOpenDeliverable:c=>de({kind:"walter",type:c}),seedReadyByType:L}):e.jsx(Kl,{criteria:H})]}),e.jsxs("section",{className:"min-w-0 overflow-hidden rounded-2xl border border-grey-1 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsx(ya,{title:"Start from scratch",description:"Begin with a blank keepsake and choose the stories, images, and copy yourself."}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:Wr.map(c=>{const Y=c.icon;return e.jsxs("button",{type:"button",onClick:()=>se(c.type),className:"group flex min-h-[132px] flex-col justify-between rounded-xl border border-grey-1 bg-grey-0 p-4 text-left transition hover:border-primary/30 hover:bg-primary-light/40 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsxs("span",{className:"flex items-start justify-between gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-white text-primary shadow-sm dark:bg-grey-1",children:e.jsx(Y,{size:18,"aria-hidden":"true"})}),e.jsx(zt,{size:17,className:"mt-1 text-grey-3 transition group-hover:translate-x-0.5 group-hover:text-primary","aria-hidden":"true"})]}),e.jsxs("span",{children:[e.jsx("span",{className:"block font-primary text-base font-bold text-grey-7",children:c.label}),e.jsx("span",{className:"mt-1 block text-sm leading-5 text-grey-5",children:c.description})]})]},c.type)})})]})]}),e.jsxs("aside",{className:"min-w-0 space-y-4",children:[e.jsx(ba,{icon:pt,title:"Keepsakes",body:"Albums and reels are the project deliverables members can view after publication."}),e.jsx(ba,{icon:bs,title:"Publishing tip",body:"Smart generation unlocks after the project has goals and usable source material. Draft and publication controls stay owner-only."})]})]})}):e.jsx(zr,{view:"member",children:e.jsxs("section",{className:"min-w-0 space-y-5 overflow-hidden","aria-label":"Published Keepsakes",children:[e.jsx(ya,{title:"Published Keepsakes",description:"Finished keepsakes shared by the project owner."}),M?e.jsx(ha,{keepsakes:Fl(Q),canManage:!1,onUnpublish:re,onView:ce}):e.jsxs("div",{className:"min-w-0 rounded-2xl border border-dashed border-grey-2 bg-white p-8 text-center shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-2xl bg-grey-1 text-grey-5 dark:bg-grey-2",children:e.jsx(pt,{size:20,"aria-hidden":"true"})}),e.jsx("h2",{className:"mt-4 font-primary text-xl font-bold text-grey-7",children:"No keepsakes shared yet"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-sm leading-6 text-grey-5",children:"Published albums and reels will appear here when the owner shares them with members."})]})]})}):e.jsx(Gl,{isOwner:S})}function dl({collections:t,drafts:r,groupName:s,isSaving:a,onBack:i,onCreateBlankDraft:l,onDeleteDraft:d,onOpenCollection:m,onOpenDraft:p,onOpenWalter:f,type:j,walterSeed:y}){const[b,g]=o.useState(!1),h=dt(j),x=`${s} ${h}`;return e.jsxs("div",{className:"grid min-w-0 max-w-full gap-5 overflow-hidden lg:grid-cols-[minmax(0,1.85fr)_minmax(300px,1fr)] lg:items-start",children:[e.jsxs("section",{className:"min-w-0 max-w-full space-y-6 overflow-hidden rounded-2xl border border-grey-2 bg-white p-4 shadow-sm dark:border-grey-2 dark:bg-grey-1 sm:p-5",children:[e.jsxs("header",{className:"flex min-w-0 items-start gap-3",children:[e.jsx(fr,{label:"Back to Keepsakes",onClick:i,icon:ir}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("h2",{className:"break-words font-primary text-2xl font-bold text-grey-7 [overflow-wrap:anywhere]",children:["Start a ",h]}),e.jsxs("p",{className:"mt-1 max-w-2xl break-words text-sm leading-6 text-grey-5 [overflow-wrap:anywhere]",children:["Choose how to begin the ",h,"."]})]})]}),t.length>0&&e.jsxs("section",{className:"min-w-0 max-w-full space-y-3 overflow-hidden","aria-labelledby":"memory-album-collections-title",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-grey-4",children:"COLLECTIONS"}),e.jsx("h3",{id:"memory-album-collections-title",className:"mt-1 break-words font-primary text-xl font-bold text-grey-7 [overflow-wrap:anywhere]",children:"Your collections"})]}),e.jsx("div",{className:"grid min-w-0 max-w-full gap-4 md:grid-cols-2",children:t.map((S,k)=>e.jsx(cl,{collection:S,onOpen:()=>m(S)},S.collectionId??k))})]}),e.jsx(ml,{drafts:r,isExpanded:b,isSaving:a,onCancel:()=>g(!1),onCreate:async S=>{await l(S),g(!1)},onDeleteDraft:d,onOpenDraft:p,onOpenNew:()=>g(!0),suggestedDraftName:x,type:j})]}),e.jsx(xl,{groupName:s,onOpen:f,type:j,walterSeed:y})]})}function cl({collection:t,onOpen:r}){const s=t.itemCount??0,a=t.storyCount??0,i=t.sourceCount??0,l=t.quoteCount??0;return e.jsxs("article",{className:"group min-w-0 max-w-full overflow-hidden rounded-2xl border border-grey-2 bg-white text-left shadow-sm transition hover:border-primary/30 dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("div",{className:"flex h-32 items-end bg-grey-0 p-4 dark:bg-grey-2/40",children:e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.12em] text-grey-4",children:"Collection cover"})}),e.jsxs("div",{className:"min-w-0 p-4",children:[e.jsxs("p",{className:"text-xs font-bold uppercase text-grey-4",children:[s," ",s===1?"item":"items"]}),e.jsx("h4",{className:"mt-2 break-words font-primary text-lg font-bold text-grey-7 [overflow-wrap:anywhere]",children:t.name??"Untitled collection"}),e.jsx("p",{className:"mt-2 line-clamp-2 break-words text-sm leading-5 text-grey-5 [overflow-wrap:anywhere]",children:t.description||El(a,i,l)}),e.jsxs("button",{type:"button",onClick:r,className:"mt-4 inline-flex items-center gap-2 text-sm font-semibold text-primary",children:["Start from this collection",e.jsx(zt,{size:15,"aria-hidden":"true"})]})]})]})}function ml({drafts:t,isExpanded:r,isSaving:s,onCancel:a,onCreate:i,onDeleteDraft:l,onOpenDraft:d,onOpenNew:m,suggestedDraftName:p,type:f}){const[j,y]=o.useState(p),b=f==="memoryReel"?"memoryReelDraftName":"memoryAlbumDraftName";return e.jsxs("section",{className:"min-w-0 max-w-full space-y-3 overflow-hidden","aria-labelledby":"memory-album-drafts-title",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-grey-4",children:"YOUR DRAFTS"}),e.jsx("h3",{id:"memory-album-drafts-title",className:"mt-1 break-words font-primary text-xl font-bold text-grey-7 [overflow-wrap:anywhere]",children:t.length>0?"Drafts in progress":"No drafts yet"})]}),t.length>0?e.jsx("div",{className:"min-w-0 space-y-3",children:t.map(g=>e.jsx(ul,{draft:g,onDeleteDraft:l,onOpenDraft:d},g.keepsakeId))}):e.jsx("article",{className:"min-w-0 rounded-2xl border border-dashed border-grey-2 bg-white/75 p-5 text-left dark:border-grey-2 dark:bg-grey-1",children:e.jsxs("p",{className:"break-words text-sm leading-6 text-grey-5 [overflow-wrap:anywhere]",children:["Start a blank draft to build your ",f==="memoryReel"?"reel":"album"," manually."]})}),r?e.jsxs("div",{className:"min-w-0 rounded-lg border border-primary/20 bg-primary-light/35 p-4",children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-primary",htmlFor:"memory-album-draft-name",children:"Draft name"}),e.jsx("input",{id:"memory-album-draft-name",name:b,value:j,onChange:g=>y(g.currentTarget.value),className:"mt-2 w-full rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary"}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{i(j)},disabled:s,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["Create draft",e.jsx(zt,{size:14,"aria-hidden":"true"})]}),e.jsx("button",{type:"button",onClick:a,className:"inline-flex rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary",children:"Cancel"})]})]}):e.jsxs("button",{type:"button",onClick:m,className:"inline-flex items-center gap-2 rounded-lg border border-grey-2 bg-white px-4 py-2 text-sm font-semibold text-primary shadow-sm transition hover:border-primary/30 dark:border-grey-2 dark:bg-grey-1",children:[e.jsx(at,{size:15,"aria-hidden":"true"}),"New blank draft"]})]})}function ul({draft:t,onDeleteDraft:r,onOpenDraft:s}){const[a,i]=o.useState(!1),l=t.currentDraftSnapshot?.title??t.title??"Untitled Memory Album";return e.jsx("article",{className:"min-w-0 max-w-full overflow-hidden rounded-2xl border border-grey-2 bg-white p-4 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"break-words font-primary text-lg font-bold text-grey-7 [overflow-wrap:anywhere]",children:l}),e.jsxs("p",{className:"mt-1 text-xs font-semibold text-grey-4",children:["Last edited ",Ul(t.updatedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>s(t),className:"inline-flex items-center gap-2 rounded-lg bg-primary px-3 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-primary/90",children:["Open",e.jsx(zt,{size:14,"aria-hidden":"true"})]}),a?e.jsx("button",{type:"button",onClick:()=>t.keepsakeId&&void r(t.keepsakeId),className:"inline-flex rounded-lg border border-red-200 px-3 py-2 text-xs font-bold text-red-600 transition hover:bg-red-50",children:"Confirm"}):e.jsx("button",{type:"button",onClick:()=>i(!0),"aria-label":`Delete ${l}`,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg border border-grey-2 text-grey-5 transition hover:border-red-200 hover:text-red-600",children:e.jsx(gt,{size:15,"aria-hidden":"true"})})]})]})})}function xl({groupName:t,onOpen:r,type:s,walterSeed:a}){const i=a?.ready===!0,l=a?.contentItems?.length??0,d=dt(s),m=s==="memoryReel"?"visuals, audio picks, and real media already in the Memory Project":"stories, source quotes, and real media already in the Memory Project";return e.jsxs("aside",{className:"min-w-0 max-w-full overflow-hidden rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-primary-light px-3 py-1 text-xs font-semibold text-primary",children:[e.jsx(pt,{size:14,"aria-hidden":"true"}),"Walter's Smart Generation"]}),e.jsx("h3",{className:"mt-4 break-words font-primary text-xl font-bold text-grey-7 [overflow-wrap:anywhere]",children:a?.title??`${t} ${d}`}),e.jsx("p",{className:"mt-2 break-words text-sm leading-6 text-grey-5 [overflow-wrap:anywhere]",children:i?`Walter Smart ${d} uses ${l} selected ${l===1?"item":"items"} from ${m}.`:`Walter Smart ${d} will appear here when the generated preview is ready.`}),e.jsxs("button",{type:"button",onClick:r,disabled:!i,className:"mt-5 inline-flex w-full items-center justify-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["View generated ",d,e.jsx(zt,{size:14,"aria-hidden":"true"})]})]})}function pl({collectionEligibility:t,collectionSeed:r,draft:s,groupName:a,isSaving:i,localDraftContent:l,onBack:d,onPublish:m,onSaveCollectionDraft:p,onSaveWalterDraft:f,onUpdateDraft:j,session:y,walterSeed:b}){const g=y.type==="memoryReel",h=dt(y.type),x=s?.currentDraftSnapshot,S=y.kind==="draft"&&l?.keepsakeId===y.keepsakeId,
1k=o.useMemo(()=>{if(y.kind==="collection")return{title:r?.title??y.label,coverFileId:r?.coverFileId??void 0,coverImageStorageId:r?.coverImageStorageId??void 0,coverImageUrl:r?.coverImageUrl??void 0,coverImageCrop:r?.coverImageCrop??void 0,albumPdfUrl:r?.albumPdfUrl??void 0,horizontalVideoUrl:r?.horizontalVideoUrl??void 0,verticalVideoUrl:r?.verticalVideoUrl??void 0,heroDescription:void 0,contentItems:r?.contentItems??[]};if(y.kind==="walter")return{title:b?.title??`${a} ${dt(y.type)}`,coverFileId:b?.coverFileId??void 0,coverImageStorageId:b?.coverImageStorageId??void 0,coverImageUrl:b?.coverImageUrl??void 0,coverImageCrop:b?.coverImageCrop??void 0,albumPdfUrl:b?.albumPdfUrl??void 0,horizontalVideoUrl:b?.horizontalVideoUrl??void 0,verticalVideoUrl:b?.verticalVideoUrl??void 0,heroDescription:b?.heroDescription,contentItems:b?.contentItems??[]};const n=S?l:null;return{title:n?.title??x?.title??y.fallbackTitle??`Untitled ${dt(y.type)}`,coverFileId:n?n.coverFileId:x?.coverFileId??void 0,coverImageStorageId:n?n.coverImageStorageId:x?.coverImageStorageId??void 0,coverImageUrl:n?n.coverImageUrl:x?.coverImageUrl??void 0,coverImageCrop:n?n.coverImageCrop:x?.coverImageCrop??void 0,albumPdfUrl:x?.albumPdfUrl??void 0,horizontalVideoUrl:x?.horizontalVideoUrl??void 0,verticalVideoUrl:x?.verticalVideoUrl??void 0,heroDescription:n?n.heroDescription:x?.heroDescription,contentItems:n?n.contentItems:x?.contentItems??[]}},[r?.coverImageCrop,r?.albumPdfUrl,r?.coverFileId,r?.coverImageStorageId,r?.coverImageUrl,r?.contentItems,r?.horizontalVideoUrl,r?.title,r?.verticalVideoUrl,x?.albumPdfUrl,x?.coverImageCrop,x?.coverFileId,x?.coverImageStorageId,x?.coverImageUrl,x?.contentItems,x?.heroDescription,x?.horizontalVideoUrl,x?.title,x?.verticalVideoUrl,a,S,l?.coverFileId,l?.coverImageCrop,l?.coverImageStorageId,l?.coverImageUrl,l?.contentItems,l?.heroDescription,l?.title,y,b?.albumPdfUrl,b?.coverImageCrop,b?.coverFileId,b?.coverImageStorageId,b?.coverImageUrl,b?.contentItems,b?.heroDescription,b?.horizontalVideoUrl,b?.title,b?.verticalVideoUrl]),N=y.kind==="collection"?"COLLECTION START":y.kind==="walter"?"WALTER SMART GENERATION":`${h.toUpperCase()} DRAFT`,P=y.kind==="collection"||y.kind==="walter",w=y.kind==="walter"?f:p,U=y.kind==="draft"?s?.keepsakeId??l?.keepsakeId??y.keepsakeId:void 0,[q,K]=o.useState(k.title),[Z,E]=o.useState(k.coverFileId),[B,le]=o.useState(k.coverImageStorageId),[$,X]=o.useState(k.coverImageUrl),[G,ae]=o.useState(lr(k.coverImageCrop)),[ee,Q]=o.useState(k.heroDescription??""),[M,_]=o.useState(k.contentItems),[T,z]=o.useState(null),[C,L]=o.useState(!1),[H,v]=o.useState(null),[D,se]=o.useState(!1),[de,ze]=o.useState([]),[ke,Pe]=o.useState(null),[Ne,ce]=o.useState(0),[oe,te]=o.useState(null),[re,me]=o.useState(!1),[Ce,he]=o.useState(!1),[c,Y]=o.useState(""),[ie,ue]=o.useState(""),[Se,Ee]=o.useState(""),[Ke,Me]=o.useState(""),[Nt,He]=o.useState(null),[tt,Oe]=o.useState(!1),[ct,Ye]=o.useState(!1),[ot,Ve]=o.useState(null),Qe=gi({shouldBlockFn:()=>tt,disabled:!tt,enableBeforeUnload:tt,withResolver:!0}),Dt=Qn({type:y.type,coverFileId:Z,coverImageStorageId:B,contentItems:M}),[Le,Ze]=o.useState(null),jt=o.useRef({});o.useEffect(()=>{K(k.title),E(k.coverFileId),le(k.coverImageStorageId),X(k.coverImageUrl),ae(lr(k.coverImageCrop)),Q(k.heroDescription??""),_(k.contentItems),ce(0),L(!1),se(!1),ze([]),Pe(null),z(null),v(null),te(null),me(!1),he(!1),Y(""),ue(""),Ee(""),Me(""),Ze(null),Oe(!1),Ye(!1),Ve(null)},[k]);const Ct=o.useMemo(()=>M.map((n,I)=>Yn(n,I)),[M]),St=o.useMemo(()=>({title:q.trim()||`${a} ${h}`,coverFileId:Z,coverImageCrop:On(Z,B,$,G),coverImageStorageId:B,coverImageUrl:$,heroDescription:ee.trim()||void 0,contentItems:Ct}),[q,Z,G,B,$,ee,h,a,Ct]),De=o.useCallback(()=>{Oe(!0),te(null)},[]),rt=n=>n._id??n.pageId,Fe=n=>n.title?.trim()||n.overview?.trim()||"Untitled story",yt=o.useMemo(()=>{const n=new Map,I=new Map;for(const J of t?.candidates?.pages??[]){const W=rt(J);W&&n.set(W,J);const $e=ma(Fe(J));$e&&I.set($e,J)}return{byPageId:n,byTitle:I}},[t?.candidates?.pages]);o.useEffect(()=>{yt.byPageId.size===0&&yt.byTitle.size===0||_(n=>{let I=!1;const J=n.map(W=>{if(W.itemType!=="page")return W;const $e=(W.pageId?yt.byPageId.get(W.pageId):void 0)??yt.byTitle.get(ma(W.title)??"");if(!$e)return W;const Ft=rt($e),Ot=W.mediaUrl===void 0?es($e):W.mediaUrl,Re={...W,pageId:W.pageId??Ft,title:W.title??Fe($e),summary:W.summary??$e.overview??$e.content,body:W.body??$e.content,...Ot?{mediaUrl:Ot}:{},imageCrop:Ot&&!W.imageCrop?Rt(50):W.imageCrop};return I=I||Re.pageId!==W.pageId||Re.title!==W.title||Re.summary!==W.summary||Re.body!==W.body||Re.mediaUrl!==W.mediaUrl||Re.imageCrop!==W.imageCrop,Re});return I?J:n})},[yt]);const V=(t?.candidates?.pages??[]).filter(n=>{const I=rt(n);return I&&!M.some(J=>J.itemType==="page"&&J.pageId===I)}),pe=(t?.candidates?.quotes??[]).filter(n=>n._id&&!M.some(I=>I.quoteId===n._id)),ye=(t?.candidates?.sources??[]).filter(n=>(n.contentType??"").startsWith("image/")),Ge=(t?.candidates?.sources??[]).filter(n=>n._id&&(n.contentType??"").startsWith("image/")&&!M.some(I=>I.fileId===n._id)),ht=(t?.candidates?.sources??[]).filter(n=>n._id&&!M.some(I=>I.fileId===n._id)),je=ht.filter(n=>(n.contentType??"").startsWith("image/")||(n.contentType??"").startsWith("video/")),ve=ht.filter(n=>(n.contentType??"").startsWith("audio/")),At=n=>{n._id&&(E(n._id),le(void 0),X(n.previewUrl??n.thumbnailUrl),ae(50),L(!1),De())},qt=(n,I)=>{I._id&&(Je(n,{fileId:I._id,mediaUrl:I.previewUrl??I.thumbnailUrl,mediaRemoved:void 0,imageCrop:Rt(50)}),v(null))},qe=n=>{ze(I=>I.includes(n)?I.filter(J=>J!==n):[...I,n])},mt=()=>{se(!1),z(null),ze([])},et=n=>{if(n.length===0)return;const I=M.length+2;_(J=>[...J,...n]),ce(I),mt(),De()},$t=n=>{const I=rt(n);return I?{itemType:"page",pageId:I,title:Fe(n),summary:n.overview??n.content,body:n.content,mediaUrl:es(n),imageCrop:es(n)?Rt(50):void 0}:null},Wt=n=>n._id?{itemType:"media",fileId:n._id,title:Tt(n.originalFilename),mediaUrl:n.previewUrl??n.thumbnailUrl,imageCrop:Rt(50)}:null,Ut=n=>{if(!n._id)return null;const I=n.body??n.quote??"";return{itemType:"quote",quoteId:n._id,title:n.title??n.sourceTitle??"Selected quote",body:I,summary:I}},ur=()=>{const n=V.filter(W=>de.includes(`story:${rt(W)}`)).map($t),I=Ge.filter(W=>de.includes(`image:${W._id}`)).map(Wt),J=pe.filter(W=>de.includes(`quote:${W._id}`)).map(Ut);et([...n,...I,...J].filter(W=>!!W))},xr=n=>{const I=$t(n);I&&et([I])},bt=n=>{const I=Wt(n);I&&et([I])},It=n=>{const I=Ut(n);I&&et([I])},We=n=>{n._id&&(_(I=>[...I,{itemType:"media",fileId:n._id,title:Tt(n.originalFilename),mediaUrl:n.previewUrl??n.thumbnailUrl,imageCrop:Rt(50),timeline:ua(n,"visual")}]),z(null),De())},pr=n=>{n._id&&(_(I=>[...I,{itemType:"media",fileId:n._id,title:Tt(n.originalFilename),mediaUrl:n.previewUrl??n.thumbnailUrl,timeline:ua(n,"audio")}]),z(null),De())},Je=(n,I)=>{_(J=>J.map((W,$e)=>$e===n?{...W,...I}:W)),De()},Pt=(n,I)=>{const J=n+I;J<0||J>=M.length||(_(W=>{const $e=[...W],[Ft]=$e.splice(n,1);return $e.splice(J,0,Ft),$e}),ce(J+2),De())},gr=(n,I)=>{n===I||n<0||I<0||n>=M.length||I>=M.length||(_(J=>{const W=[...J],[$e]=W.splice(n,1);return W.splice(I,0,$e),W}),ce(I+2),De())},Vt=n=>
1{_(I=>I.filter((J,W)=>W!==n)),ce(I=>Math.max(0,Math.min(I,M.length))),Ze(null),De()},Ht=o.useCallback(n=>{const I=M[n],J=po(window.getSelection?.()?.toString());if(!I||!J){Ze(W=>W?.itemIndex===n?null:W);return}Ze({itemIndex:n,text:J,title:I.title||`Page ${n+1}`})},[M]),Lt=o.useCallback(n=>{const I=M[n],J=Rl(I?.body??I?.summary);!I||!J||Ze({itemIndex:n,text:J,title:I.title||`Page ${n+1}`})},[M]),wt=o.useCallback(()=>{if(!Le)return;const n=M[Le.itemIndex],I={itemType:"quote",pageId:n?.pageId,quoteId:n?.quoteId,title:Le.title,body:Le.text,summary:Le.text};_(J=>{const W=[...J];return W.splice(Le.itemIndex+1,0,I),W}),ce(Le.itemIndex+3),Ze(null),De()},[M,De,Le]),tr=(n,I)=>{ce(n),jt.current[I]?.scrollIntoView?.({behavior:"smooth",block:"center"})},ut=()=>St,u=o.useMemo(()=>xo({albumTitle:q||"Untitled Memory Album",coverImagePosition:G,coverImageUrl:$,dedication:ee,editControls:{coverImageCandidates:ye,coverPickerOpen:C,onCoverPositionChange:n=>{ae(n),De()},onDedicationChange:n=>{Q(n.slice(0,io)),De()},onMediaImagePositionChange:(n,I)=>Je(n,{imageCrop:Rt(I)}),onMediaTitleChange:(n,I)=>Je(n,{title:I}),onRemoveStoryImage:n=>Je(n,{fileId:void 0,imageCrop:void 0,mediaRemoved:!0,mediaUrl:void 0}),onRemoveCoverImage:()=>{E(void 0),le(void 0),X(void 0),ae(50),De()},onSelectCoverImage:At,onStoryImagePositionChange:(n,I)=>Je(n,{imageCrop:Rt(I)}),onTitleChange:n=>{K(n.slice(0,oo)),De()},onToggleCoverPicker:()=>L(n=>!n),onToggleStoryImagePicker:n=>v(n),onUndoQuote:Vt},fallbackStoryImageUrl:go(M)??$,items:M,onCreateQuoteFromStory:Lt,onCreateQuoteFromSelection:wt,onQuoteSelection:Ht,quoteSelection:Le}),[q,Ht,ye,G,$,C,Lt,wt,ee,M,Le]),A=o.useMemo(()=>{const n=Math.max(0,Ne-1),I=Math.min(u.length,Ne+2);return u.slice(n,I).map((J,W)=>({index:n+W,page:J}))},[Ne,u]);o.useEffect(()=>{const n=u[Ne];if(!n)return;const I=window.requestAnimationFrame(()=>{jt.current[n.id]?.scrollIntoView?.({behavior:"smooth",block:"center"})});return()=>window.cancelAnimationFrame(I)},[Ne,u]);const ge=T?e.jsxs("div",{className:"rounded-lg border border-grey-1 bg-grey-0 p-3 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:T==="stories"?"Library stories":T==="audio"?"Source audio":T==="quotes"?"Selected quotes":"Source images"}),e.jsx("div",{className:"mt-3 space-y-2",children:T==="stories"?V.length>0?V.map(n=>{const I=rt(n),J=`story:${I}`,W=de.includes(J);return e.jsxs("button",{type:"button","aria-pressed":W,onClick:()=>D?qe(J):xr(n),className:`flex w-full items-center justify-between gap-3 rounded-lg bg-white px-3 py-2 text-left text-sm font-semibold shadow-sm transition hover:text-primary dark:bg-grey-1 ${W?"text-primary ring-2 ring-primary/20":"text-grey-7"}`,children:[e.jsx("span",{className:"min-w-0 truncate",children:Fe(n)}),e.jsx("span",{className:"shrink-0 text-xs text-grey-4",children:W?"Selected":D?"Select":"Add"})]},I)}):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No more eligible stories are available."}):T==="quotes"?pe.length>0?pe.map(n=>{const I=`quote:${n._id}`,J=de.includes(I);return e.jsxs("button",{type:"button","aria-pressed":J,onClick:()=>D?qe(I):It(n),className:`flex w-full items-center justify-between gap-3 rounded-lg bg-white px-3 py-2 text-left text-sm font-semibold shadow-sm transition hover:text-primary dark:bg-grey-1 ${J?"text-primary ring-2 ring-primary/20":"text-grey-7"}`,children:[e.jsx("span",{className:"min-w-0 truncate",children:n.title??n.sourceTitle??"Selected quote"}),e.jsx("span",{className:"shrink-0 text-xs text-grey-4",children:J?"Selected":D?"Select":"Add"})]},n._id)}):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No eligible quotes are available."}):T==="audio"?ve.length>0?ve.map(n=>e.jsxs("button",{type:"button",onClick:()=>pr(n),className:"w-full rounded-lg bg-white px-3 py-2 text-left text-sm font-semibold text-grey-7 shadow-sm transition hover:text-primary dark:bg-grey-1",children:["Add ",Tt(n.originalFilename)]},n._id)):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No eligible source audio is available."}):T==="visuals"?je.length>0?je.map(n=>e.jsxs("button",{type:"button",onClick:()=>We(n),className:"w-full rounded-lg bg-white px-3 py-2 text-left text-sm font-semibold text-grey-7 shadow-sm transition hover:text-primary dark:bg-grey-1",children:["Add ",Tt(n.originalFilename)]},n._id)):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No eligible source visual
1s are available."}):Ge.length>0?Ge.map(n=>e.jsxs("button",{type:"button","aria-pressed":de.includes(`image:${n._id}`),onClick:()=>D?qe(`image:${n._id}`):bt(n),className:`flex w-full items-center gap-3 rounded-lg bg-white p-2 text-left text-sm font-semibold shadow-sm transition hover:text-primary dark:bg-grey-1 ${de.includes(`image:${n._id}`)?"text-primary ring-2 ring-primary/20":"text-grey-7"}`,children:[e.jsx("span",{className:"h-16 w-16 shrink-0 overflow-hidden rounded-md bg-grey-1 dark:bg-grey-2","aria-hidden":"true",children:n.previewUrl||n.thumbnailUrl?e.jsx("img",{src:n.previewUrl??n.thumbnailUrl,alt:"",className:"h-full w-full object-cover"}):e.jsx("span",{className:"flex h-full w-full items-center justify-center text-grey-4",children:e.jsx(ft,{size:20,"aria-hidden":"true"})})}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:Tt(n.originalFilename)}),e.jsx("span",{className:"shrink-0 text-xs text-grey-4",children:de.includes(`image:${n._id}`)?"Selected":D?"Select":"Add"})]},n._id)):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No eligible source media is available."})})]}):null,we=async()=>{await w(ut()),Oe(!1),te("Saved")},xe=()=>{if(!tt){d();return}Ve(null),Ye(!0)},Te=()=>{Qe.status==="blocked"?Qe.reset():Ye(!1)},Ae=()=>{if(Oe(!1),Ye(!1),Qe.status==="blocked"){Qe.proceed();return}d()},it=async()=>{Ve(null);try{if(U?await j({keepsakeId:U,...ut()}):await w(ut()),Oe(!1),Ye(!1),Qe.status==="blocked"){Qe.proceed();return}d()}catch(n){Ve(ks(n,"Could not save changes. Please try again."))}},_e=()=>{const n=q.trim()||`${a} ${h}`;Y(n),ue(ee.trim()),Ee(k.horizontalVideoUrl??""),Me(k.verticalVideoUrl??""),He(null),he(!0)},Yt=async()=>{const n=ut(),I=Se.trim(),J=Ke.trim();if(He(null),!c.trim()){He(al);return}if(!ie.trim()){He(no);return}if(y.type==="memoryReel"&&!I){He(lo);return}if(y.type==="memoryReel"&&!J){He(co);return}try{await m({...n,albumPdfUrl:void 0,heroTitle:c.trim()||n.title,heroDescription:ie.trim()||void 0,horizontalVideoUrl:y.type==="memoryReel"?I:void 0,verticalVideoUrl:y.type==="memoryReel"?J:void 0}),he(!1),te("Published")}catch(W){He($l(W))}},Hr=g?"space-y-5 pb-8":"space-y-5 pb-56 md:pb-36",Yr=g?"grid gap-5 xl:grid-cols-[minmax(300px,340px)_minmax(0,1fr)] 2xl:grid-cols-[340px_minmax(720px,1fr)]":"grid gap-5";return e.jsxs("div",{className:Hr,children:[e.jsxs("section",{className:"flex flex-col gap-4 roun
1ded-2xl border border-grey-2 bg-white p-4 shadow-sm dark:border-grey-2 dark:bg-grey-1 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(fr,{label:`Back to ${h} start`,onClick:xe,icon:ir}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:N}),e.jsxs("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:[h," Studio"]}),e.jsxs("p",{className:"mt-1 text-sm leading-6 text-grey-5",children:[g?"Timeline editor":"Document editor"," for ",a,"."]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[P&&e.jsx("button",{type:"button",onClick:()=>{we()},disabled:i,className:"inline-flex items-center gap-2 rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-4",children:"Save as draft"}),e.jsxs("button",{type:"button",onClick:()=>me(!0),className:"inline-flex items-center gap-2 rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary",children:[e.jsx(ns,{size:15,"aria-hidden":"true"}),"Preview"]}),e.jsxs("button",{type:"button",onClick:_e,disabled:!Dt||i,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-5 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["Publish",e.jsx(zt,{size:15,"aria-hidden":"true"})]}),oe&&e.jsx("span",{className:"self-center text-sm font-semibold text-green-700",children:oe})]})]}),D&&!g&&e.jsx(Kt,{className:"fixed inset-0 z-[85] m-0 flex h-screen w-screen max-h-none max-w-none items-end justify-center border-0 bg-black/35 p-4 backdrop-blur-sm sm:items-center",onClose:mt,titleId:"memory-album-add-title",children:e.jsxs("section",{"aria-labelledby":"memory-album-add-title",className:"w-full max-w-lg rounded-2xl border border-grey-2 bg-white p-5 shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Add page"}),e.jsx("h3",{id:"memory-album-add-title",className:"font-primary text-xl font-bold text-grey-7",children:"Add to Memory Album"})]}),e.jsx("button",{type:"button","aria-label":"Close add page picker",onClick:mt,className:"inline-flex h-9 w-9 items-center justify-center rounded-lg text-grey-5 transition hover:bg-grey-0 hover:text-grey-7",children:e.jsx(fe,{size:18,"aria-hidden":"true"})})]}),e.jsx("div",{className:"mt-5 grid grid-cols-3 gap-2 rounded-lg bg-grey-0 p-1 dark:bg-grey-2/40",role:"group","aria-label":"Add page type",children:["stories","images","quotes"].map(n=>e.jsx("button",{type:"button","aria-pressed":T===n,onClick:()=>z(n),className:`rounded-md px-3 py-2 text-sm font-semibold capitalize transition ${T===n?"bg-white text-grey-7 shadow-sm dark:bg-grey-1":"text-grey-5 hover:text-grey-7"}`,children:n==="stories"?"Stories":n==="images"?"Images":"Quotes"},n))}),e.jsx("div",{className:"mt-4 max-h-[46vh] overflow-y-auto",children:ge}),e.jsxs("div",{className:"mt-5 flex items-center justify-between gap-3 border-t border-grey-1 pt-4 dark:border-grey-2",children:[e.jsxs("p",{className:"text-sm font-semibold text-grey-5",children:[de.length," selected"]}),e.jsxs("button",{type:"button",onClick:ur,disabled:de.length===0,className:"inline-flex items-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["Add selected",e.jsx(at,{size:15,"aria-hidden":"true"})]})]})]})}),C&&!g&&e.jsx(Kt,{className:"fixed inset-0 z-[85] m-0 flex h-screen w-screen max-h-none max-w-none items-end justify-center border-0 bg-black/35 p-4 backdrop-blur-sm sm:items-center",onClose:()=>L(!1),titleId:"memory-album-cover-picker-title",children:e.jsxs("section",{"aria-labelledby":"memory-album-cover-picker-title",className:"w-full max-w-2xl rounded-2xl border border-grey-2 bg-white p-5 shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Cover image"}),e.jsx("h3",{id:"memory-album-cover-picker-title",className:"font-primary text-xl font-bold text-grey-7",children:"Choose a cover image"})]}),e.jsx("button",{type:"button","aria-label":"Close cover image picker",onClick:()=>L(!1),className:"inline-flex h-9 w-9 items-center justify-center rounded-lg text-grey-5 transition hover:bg-grey-0 hover:text-grey-7",children:e.jsx(fe,{size:18,"aria-hidden":"true"})})]}),ye.length>
10?e.jsx("div",{className:"mt-5 grid max-h-[58vh] gap-3 overflow-y-auto pr-1 sm:grid-cols-2",children:ye.map(n=>{const I=n.previewUrl??n.thumbnailUrl,J=n._id===Z,W=Tt(n.originalFilename);return e.jsxs("button",{type:"button","aria-label":`Use ${W} as cover`,onClick:()=>At(n),className:`group overflow-hidden rounded-xl border bg-white text-left shadow-sm transition hover:border-primary/40 hover:shadow-md dark:bg-grey-0 ${J?"border-primary ring-2 ring-primary/20":"border-grey-2"}`,children:[e.jsx("div",{className:"aspect-[4/3] overflow-hidden bg-grey-1 dark:bg-grey-2",children:I?e.jsx("img",{src:I,alt:"",className:"h-full w-full object-cover transition duration-200 group-hover:scale-[1.02]"}):e.jsx("div",{className:"flex h-full items-center justify-center text-grey-4",children:e.jsx(ft,{size:28,"aria-hidden":"true"})})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-3",children:[e.jsx("span",{className:"min-w-0 truncate text-sm font-semibold text-grey-7",children:W}),e.jsx("span",{className:`shrink-0 rounded-full px-2 py-1 text-[10px] font-bold uppercase tracking-[0.12em] ${J?"bg-primary-light text-primary":"bg-grey-0 text-grey-4"}`,children:J?"Selected":"Use"})]})]},n._id)})}):e.jsxs("div",{className:"mt-5 flex min-h-48 flex-col items-center justify-center rounded-xl border border-dashed border-grey-2 bg-grey-0 px-6 text-center dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsx(ft,{size:32,className:"text-grey-4","aria-hidden":"true"}),e.jsx("p",{className:"mt-3 text-sm font-semibold text-grey-7",children:"No cover images are available yet."})]})]})}),H!==null&&M[H]&&!g&&e.jsx(Kt,{className:"fixed inset-0 z-[85] m-0 flex h-screen w-screen max-h-none max-w-none items-end justify-center border-0 bg-black/35 p-4 backdrop-blur-sm sm:items-center",onClose:()=>v(null),titleId:"memory-album-story-image-picker-title",children:e.jsxs("section",{"aria-labelledby":"memory-album-story-image-picker-title",className:"w-full max-w-2xl rounded-2xl border border-grey-2 bg-white p-5 shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Story image"}),e.jsxs("h3",{id:"memory-album-story-image-picker-title",className:"font-primary text-xl font-bold text-grey-7",children:["Choose image for ",M[H].title||"story"]})]}),e.jsx("button",{type:"button","aria-label":"Close story image picker",onClick:()=>v(null),className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg text-grey-5 transition hover:bg-grey-0 hover:text-grey-7",children:e.jsx(fe,{size:18,"aria-hidden":"true"})})]}),ye.length>0?e.jsx("div",{className:"mt-5 grid max-h-[58vh] gap-3 overflow-y-auto pr-1 sm:grid-cols-2",children:ye.map(n=>{const I=n.previewUrl??n.thumbnailUrl,J=Tt(n.originalFilename),W=n._id===M[H].fileId&&!!M[H].mediaUrl;return e.jsxs("button",{type:"button","aria-label":`Use ${J} for ${M[H].title||"story"}`,onClick:()=>qt(H,n),className:`group overflow-hidden rounded-xl border bg-white text-left shadow-sm transition hover:border-primary/40 hover:shadow-md dark:bg-grey-0 ${W?"border-primary ring-2 ring-primary/20":"border-grey-2"}`,children:[e.jsx("div",{className:"aspect-[4/3] overflow-hidden bg-grey-1 dark:bg-grey-2",children:I?e.jsx("img",{src:I,alt:"",className:"h-full w-full object-cover transition duration-200 group-hover:scale-[1.02]"}):e.jsx("div",{className:"flex h-full items-center justify-center text-grey-4",children:e.jsx(ft,{size:28,"aria-hidden":"true"})})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-3",children:[e.jsx("span",{className:"min-w-0 truncate text-sm font-semibold text-grey-7",children:J}),e.jsx("span",{className:`shrink-0 rounded-full px-2 py-1 text-[10px] font-bold uppercase tracking-[0.12em] ${W?"bg-primary-light text-primary":"bg-grey-0 text-grey-4"}`,children:W?"Selected":"Use"})]})]},n._id)})}):e.jsxs("div",{className:"mt-5 flex min-h-48 flex-col items-center justify-center rounded-xl border border-dashed border-grey-2 bg-grey-0 px-6 text-center dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsx(ft,{size:32,className:"text-grey-4","aria-hidden":"true"}),e.jsx("p",{className:"mt-3 text-sm font-semibold text-grey-7",children:"No story images are available yet."})]})]})}),e.jsxs("div",{className:Yr,children:[g&&e.jsxs("aside",{className:"min-w-0 self-start space-y-4 rounded-2xl border border-grey-2 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"memory-album-title",children:g?"Reel title":"Album title"}),e.jsx("input",{id:"memory-album-title",name:"memoryAlbumTitle",value:q,onChange:n=>{K(n.target.value),te(null),De()},className:"mt-2 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"memory-album-dedication",children:g?"Intro copy":"Dedication"}),e.jsx("textarea",{id:"memory-album-dedication",name:"memoryAlbumDedication",value:ee,onChange:n=>{Q(n.target.value),te(null),De()},rows:6,className:"mt-2 min-h-[148px] w-full resize-y rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm leading-5 text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50",placeholder:g?"Add a short intro for this reel":"Add a short project line or dedication"})]}),!g&&e.jsxs("div",{className:"rounded-lg border border-grey-1 bg-grey-0 p-4 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:"Cover image"}),$&&e.jsx("button",{type:"button",onClick:()=>{E(void 0),le(void 0),X(void 0),ae(50),te(null)},className:"text-xs font-semibold text-grey-5 transition hover:text-badge-text",children:"Remove"})]}),e.jsx("div",{className:"mt-3 overflow-hidden rounded-lg bg-grey-1 dark:bg-grey-2",children:$?e.jsx("img",{src:$,alt:"",className:"aspect-[4/3] w-full object-cover",style:{objectPosition:`50% ${G}%`}}):e.jsx("div",{className:"flex aspect-[4/3] items-center justify-center text-grey-4",children:e.jsx(ft,{size:32,"aria-hidden":"true"})})}),e.jsx("div",{className:"mt-3 flex gap-2",children:e.jsxs("button",{type:"button",onClick:()=>L(n=>!n),className:"inline-flex flex-1 items-center justify-center gap-2 rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary dark:bg-grey-1",children:[e.jsx(Lr,{size:15,"aria-hidden":"true"}),"Choose cover"]})}),$&&e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"mt-4 block text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"memory-album-cover-position",children:"Cover vertical position"}),e.jsx("input",{id:"memory-album-cover-position",name:"memoryAlbumCoverPosition",type:"range",min:0,max:100,value:G,onChange:n=>{ae(Number(n.target.value)),te(null)},className:"mt-2 w-full"})]}),C&&e.jsx("div",{className:"mt-3 space-y-2",children:ye.length>0?ye.map(n=>e.jsxs("button",{type:"button",onClick:()=>At(n),className:"w-full rounded-lg bg-white px-3 py-2 text-left text-sm font-semibold text-grey-7 shadow-sm transition hover:text-primary dark:bg-grey-1",children:["Use ",Tt(n.originalFilename)," as cover"]},n._id)):e.jsx("p",{className:"text-sm leading-5 text-grey-5",children:"No eligible cover images are available."})})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>z(n=>n===(g?"visuals":"stories")?null:g?"visuals":"stories"),className:"inline-flex min-h-12 items-center justify-center gap-2 whitespace-nowrap rounded-lg bg-primary px-4 py-3 text-sm font-semibold text-white transition hover:bg-primary/90",children:[g?e.jsx(nr,{size:15,"aria-hidden":"true"}):e.jsx(st,{size:15,"aria-hidden":"true"}),g?"Add visual":"Add story"]}),e.jsxs("button",{type:"button",onClick:()=>z(n=>n===(g?"audio":"images")?null:g?"audio":"images"),className:"inline-flex min-h-12 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-grey-2 px-4 py-3 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary",children:[e.jsx(Lr,{size:15,"aria-hidden":"true"}),g?"Add audio":"Add image"]})]}),ge]}),e.jsx("section",{className:`${g?"":"order-1"} min-h-[680px] min-w-0 rounded-2xl border border-grey-2 bg-grey-1/50 p-4 shadow-sm dark:border-transparent dark:bg-black/20`,children:g?e.jsx(uo,{groupName:a,introCopy:ee,
1items:M,onAddAudio:()=>z(n=>n==="audio"?null:"audio"),onAddVisual:()=>z(n=>n==="visuals"?null:"visuals"),onMoveDown:n=>Pt(n,1),onMoveUp:n=>Pt(n,-1),onRemove:Vt,onTimelineChange:(n,I)=>Je(n,{timeline:I}),onTitleChange:(n,I)=>Je(n,{title:I}),title:q||`Untitled ${h}`}):e.jsx("div",{className:"space-y-5",children:e.jsxs("section",{className:"overflow-hidden rounded-2xl border border-grey-2 bg-[#f7f7f6] shadow-sm dark:border-transparent dark:bg-black/20","aria-label":"Album canvas",children:[e.jsx("span",{className:"sr-only",children:"Album canvas"}),e.jsx("div",{className:"px-4 pb-32 pt-8 sm:px-8 lg:px-12",children:e.jsx("div",{className:"mx-auto flex max-w-3xl flex-col items-center gap-10",children:A.map(({page:n,index:I})=>e.jsxs("div",{ref:J=>{jt.current[n.id]=J},className:"w-full max-w-[430px]",children:[e.jsx("p",{className:"mb-3 text-center text-[10px] font-bold uppercase tracking-[0.16em] text-grey-4",children:n.label==="Cover"?"Cover":n.label}),e.jsx("article",{"aria-current":Ne===I?"page":void 0,onClick:()=>tr(I,n.id),className:`block aspect-[210/297] w-full overflow-hidden rounded-sm bg-white text-left shadow-[0_22px_60px_rgba(49,43,38,0.14)] transition ${Ne===I?"ring-2 ring-primary":"ring-1 ring-grey-2 hover:ring-primary/40"}`,children:e.jsx(ps,{children:n.content})})]},`album-canvas-stack-${n.id}`))})}),e.jsx("nav",{className:"fixed inset-x-0 bottom-[calc(54px+env(safe-area-inset-bottom))] z-40 max-w-full border-t border-grey-2 bg-white/95 px-3 py-2 shadow-[0_-18px_46px_rgba(49,43,38,0.14)] backdrop-blur sm:px-4 sm:py-3 lg:bottom-0 lg:left-64 lg:z-50 dark:border-grey-2 dark:bg-grey-1/95","aria-label":"Pages",children:e.jsxs("div",{className:"mx-auto max-w-6xl min-w-0",children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center justify-end gap-2 text-sm font-semibold text-grey-5 sm:mb-3 sm:gap-3",children:[e.jsxs("span",{children:[Math.min(Ne+1,u.length)," / ",u.length]}),e.jsx("button",{type:"button",onClick:()=>me(!0),"aria-label":"Open full screen album preview",className:"inline-flex h-7 w-7 items-center justify-center rounded-lg text-grey-5 transition hover:bg-grey-0 hover:text-grey-7 sm:h-9 sm:w-9",children:e.jsx(ns,{size:17,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"flex max-w-full items-end gap-2 overflow-x-auto pb-1 sm:gap-3 sm:pb-2",children:[u.map((n,I)=>{const J=n.itemIndex!==void 0,W=n.title??n.label,$e=J&&(n.itemIndex??0)>0,Ft=J&&(n.itemIndex??0)<M.length-1,Ot=Re=>{Re.preventDefault();const Qr=ke??-1,Cr=Number(Re.dataTransfer.getData("text/plain")||Qr);Number.isFinite(Cr)&&J&&n.itemIndex!==void 0&&gr(Cr,n.itemIndex),Pe(null)};return e.jsx("div",{draggable:J,onDragStart:Re=>{if(!J){Re.preventDefault();return}Pe(n.itemIndex??null),Re.dataTransfer.effectAllowed="move",Re.dataTransfer.setData("text/plain",String(n.itemIndex))},onDragOver:Re=>{J&&ke!==null&&(Re.preventDefault(),Re.dataTransfer.dropEffect="move")},onDrop:Ot,onDragEnd:()=>Pe(null),className:`shrink-0 rounded-2xl ${J?"cursor-grab active:cursor-grabbing":""} ${n.itemIndex!==void 0&&ke===n.itemIndex?"opacity-50":""}`,children:e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button","aria-label":`Go to page ${I+1}: ${W}`,onClick:()=>tr(I,n.id),className:`flex h-[68px] w-[82px] items-center justify-center rounded-xl border bg-grey-0 p-1.5 text-center text-[9px] font-semibold leading-tight transition sm:h-[92px] sm:w-[112px] sm:rounded-2xl sm:p-2 sm:text-[10px] dark:bg-grey-2 ${Ne===I?"border-grey-7 text-grey-7 shadow-sm dark:border-white dark:text-white":"border-grey-2 text-grey-5 hover:border-primary/30 hover:text-primary dark:border-grey-3 dark:text-white/70 dark:hover:border-primary/60 dark:hover:text-white"}`,children:e.jsx("span",{className:"line-clamp-3 max-w-[54px] rounded bg-white/80 px-1.5 py-2 shadow-sm sm:max-w-[70px] sm:px-2 sm:py-3 dark:bg-grey-1/90",children:W})}),J&&e.jsxs("div",{className:"absolute -right-2 -top-2 flex items-center gap-1 rounded-full border border-grey-2 bg-white p-1 shadow-sm dark:border-grey-3 dark:bg-grey-1",children:[e.jsx("span",{"aria-label":`Drag page ${I+1} to reorder`,className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-grey-4",children:e.jsx(La,{size:14,"aria-hidden":"true"})}),e.jsx("button",{type:"button","aria-label":`Move page ${I+1}: ${W} left`,disabled:!$e,onClick:Re=>{Re.stopPropagation(),n.itemIndex!==void 0&&Pt(n.itemIndex,-1)},className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-grey-5 transition hover:bg-grey-0 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-3",children:e.jsx(ir,{size:12,"aria-hidden":"true"})}),e.jsx("button",{type:"button","aria-label":`Move page ${I+1}: ${W} right`,disabled:!Ft,onClick:Re=>{Re.stopPropagation(),n.itemIndex!==void 0&&Pt(n.itemIndex,1)},className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-grey-5 transition hover:bg-grey-0 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-3",children:e.jsx(zt,{size:12,"aria-hidden":"true"})}),e.jsx("button",{type:"button","aria-label":`Delete page ${I+1}: ${W}`,onClick:Re=>{Re.stopPropagation(),n.itemIndex!==void 0&&Vt(n.itemIndex)},className:"inline-flex h-8 w-8 items-center justify-center rounded-full text-grey-5 transition hover:bg-red-50 hover:text-red-600",children:e.jsx(gt,{size:13,"aria-hidden":"true"})})]})]})},`album-toolbar-page-${n.id}`)}),e.jsx("div",{className:"flex h-[68px] w-[82px] shrink-0 items-center justify-center rounded-xl border border-dashed border-grey-2 bg-grey-0 text-grey-7 sm:h-[92px] sm:w-[112px] sm:rou
1nded-2xl",children:e.jsxs("button",{type:"button","aria-label":"Add album page",onClick:()=>{z("stories"),ze([]),se(!0)},className:"inline-flex h-10 w-10 items-center justify-center rounded-full bg-white text-grey-7 shadow-sm transition hover:bg-primary-light hover:text-primary sm:h-12 sm:w-12",children:[e.jsx(at,{size:24,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Add album page"})]})})]})]})})]})})})]}),re&&(g?e.jsx(vl,{groupName:a,introCopy:ee,items:M,onClose:()=>me(!1),title:q||`Untitled ${h}`}):e.jsx(jl,{albumTitle:q||"Untitled Memory Album",coverImagePosition:G,coverImageUrl:$,dedication:ee,items:M,onClose:()=>me(!1)})),Ce&&e.jsx(hl,{coverImageUrl:$,heroDescription:ie,heroTitle:c,horizontalVideoUrl:Se,isPublishing:i,itemCount:M.length,onClose:()=>he(!1),onConfirm:Yt,onHeroDescriptionChange:ue,onHeroTitleChange:Y,onHorizontalVideoUrlChange:Ee,onVerticalVideoUrlChange:Me,publishError:Nt,type:y.type,verticalVideoUrl:Ke}),(ct||Qe.status==="blocked")&&e.jsx(gl,{error:ot,isSaving:i,onCancel:Te,onDiscard:Ae,onSave:it,saveLabel:U?"Save changes":"Save as draft",type:y.type})]})}function gl({error:t,isSaving:r,onCancel:s,onDiscard:a,onSave:i,saveLabel:l,type:d}){const m=dt(d);return e.jsx(Kt,{className:"fixed inset-0 z-[90] m-0 h-screen w-screen max-h-none max-w-none border-0 bg-grey-7/60 p-4 backdrop-blur-sm",onClose:s,titleId:"keepsake-exit-prompt-title",children:e.jsxs("section",{className:"mx-auto mt-24 max-w-md overflow-hidden rounded-2xl border border-grey-2 bg-white shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("header",{className:"border-b border-grey-1 px-5 py-4 dark:border-grey-2",children:[e.jsxs("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:[m," Studio"]}),e.jsx("h3",{id:"keepsake-exit-prompt-title",className:"mt-1 font-primary text-2xl font-bold text-grey-7",children:"Save before leaving?"}),e.jsxs("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:["You have unsaved changes in this ",m,". Save them before going back, or leave without saving."]})]}),e.jsxs("div",{className:"space-y-4 px-5 py-5",children:[t&&e.jsx("div",{className:"rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm font-semibold text-red-700 dark:border-red-900/40 dark:bg-red-900/20 dark:text-red-400",children:t}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:s,disabled:r,className:"rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-4",children:"Cancel"}),e.jsx("button",{type:"button",onClick:a,disabled:r,className:"rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-red-300 hover:text-red-600 disabled:cursor-not-allowed disabled:text-grey-4",children:"Leave without saving"}),e.jsx("button",{type:"button",onClick:()=>{i()},disabled:r,className:"rounded-lg bg-primary px-4 py-2 text-sm font-semibold text-white transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:r?"Saving...":l})]})]})]})})}const yl=["a[href]","button:not([disabled])","textarea:not([disabled])","input:not([disabled])","select:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(", ");function la(t){return Array.from(t.querySelectorAll(yl)).filter(r=>!r.hasAttribute("aria-hidden"))}function Kt({children:t,className:r,onClose:s,titleId:a}){const i=o.useRef(null),l=o.useRef(null),d=o.useRef(s);return d.current=s,o.useEffect(()=>{const m=i.current;l.current=document.activeElement instanceof HTMLElement?document.activeElement:null,m&&(typeof m.showModal=="function"&&!m.open?m.showModal():m.open||m.setAttribute("open",""),(la(m)[0]??m).focus());function p(f){const j=i.current;if(!j)return;if(f.key==="Escape"){f.preventDefault(),d.current();return}if(f.key!=="Tab")return;const y=la(j);if(y.length===0){f.preventDefault(),j.focus();return}const b=y[0],g=y[y.length-1];f.shiftKey&&document.activeElement===b?(f.preventDefault(),g.focu
1s()):!f.shiftKey&&document.activeElement===g&&(f.preventDefault(),b.focus())}return window.addEventListener("keydown",p,!0),()=>{window.removeEventListener("keydown",p,!0),m?.open&&(typeof m.close=="function"?m.close():m.removeAttribute("open")),l.current&&document.contains(l.current)&&l.current.focus()}},[]),e.jsx("dialog",{ref:i,"aria-modal":"true","aria-labelledby":a,className:r,tabIndex:-1,onCancel:m=>{m.preventDefault(),s()},children:t})}function hl({coverImageUrl:t,heroDescription:r,heroTitle:s,horizontalVideoUrl:a,isPublishing:i,itemCount:l,onClose:d,onConfirm:m,onHeroDescriptionChange:p,onHeroTitleChange:f,onHorizontalVideoUrlChange:j,onVerticalVideoUrlChange:y,publishError:b,type:g,verticalVideoUrl:h}){const x=dt(g),S=g==="memoryAlbum"?!0:a.trim().length>0&&h.trim().length>0,k=s.trim().length>0&&r.trim().length>0&&S;return e.jsx(Kt,{className:"fixed inset-0 z-[90] m-0 h-screen w-screen max-h-none max-w-none border-0 bg-grey-7/60 p-4 backdrop-blur-sm",onClose:d,titleId:"keepsake-publish-settings-title",children:e.jsxs("section",{className:"mx-auto mt-10 max-w-xl overflow-hidden rounded-2xl border border-grey-2 bg-white shadow-2xl dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("header",{className:"flex items-start justify-between gap-4 border-b border-grey-1 px-5 py-4 dark:border-grey-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Publish settings"}),e.jsxs("h3",{id:"keepsake-publish-settings-title",className:"mt-1 font-primary text-2xl font-bold text-grey-7",children:["Publish ",x]})]}),e.jsx("button",{type:"button","aria-label":"Close publish settings",onClick:d,className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-grey-2 text-grey-5 transition hover:border-primary/30 hover:text-grey-7",children:e.jsx(fe,{size:17,"aria-hidden":"true"})})]}),e.jsxs("div",{className:"space-y-5 px-5 py-5",children:[b&&e.jsx("div",{className:"rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm font-semibold text-red-700 dark:border-red-900/40 dark:bg-red-900/20 dark:text-red-400",children:b}),e.jsxs("div",{className:"flex gap-4 rounded-xl bg-grey-0 p-3 dark:bg-grey-2/40",children:[e.jsx("div",{className:"h-24 w-28 shrink-0 overflow-hidden rounded-lg bg-primary-light text-primary",children:t?e.jsx("img",{src:t,alt:"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsx(ft,{size:24,"aria-hidden":"true"})})}),e.jsxs("div",{className:"min-w-0 py-1",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-grey-4",children:x}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-grey-5",children:"Publishing locks the current Studio state as the member-visible public page."}),e.jsxs("p",{className:"mt-2 text-xs font-semibold text-grey-4",children:[l," ",l===1?"item":"items"," included"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"keepsake-publish-hero-title",children:"Public title"}),e.jsx("input",{id:"keepsake-publish-hero-title",name:"keepsakePublishHeroTitle",value:s,onChange:N=>f(N.target.value),className:"mt-2 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"keepsake-publish-hero-description",children:"Public description"}),e.jsx("textarea",{id:"keepsake-publish-hero-description",name:"keepsakePublishHeroDescription",value:r,onChange:N=>p(N.target.value),rows:4,className:"mt-2 min-h-28 w-full resize-y rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm leading-5 text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"}),r.trim().length===0&&e.jsx("p",{className:"mt-2 text-xs font-semibold text-red-600 dark:text-red-400",children:no})]}),g==="memoryReel"?e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"keepsake-publish-horizontal-video-url",children:"Landscape video URL"}),e.jsx("input",{id:"keepsake-publish-horizontal-video-url",name:"keepsakePublishHorizontalVideoUrl",value:a,onChange:N=>j(N.target.value),placeholder:"https://assets.autograph.ai/exports/reel-landscape.mp4",className:"mt-2 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"}),a.trim().length===0&&e.jsx("p",{className:"mt-2 text-xs font-semibold text-red-600 dark:text-red-400",children:lo})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",htmlFor:"keepsake-publish-vertical-video-url",children:"Portrait video URL"}),e.jsx("input",{id:"keepsake-publish-vertical-video-url",name:"keepsakePublishVerticalVideoUrl",value:h,onChange:N=>y(N.target.value),placeholder:"https://assets.autograph.ai/exports/reel-portrait.mp4",className:"mt-2 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"}),h.trim().length===0&&e.jsx("p",{className:"mt-2 text-xs font-semibold text-red-600 dark:text-red-400",children:co})]})]}):null]}),e.jsxs("footer",{className:"flex flex-wrap items-center justify-end gap-2 border-t border-grey-1 px-5 py-4 dark:border-grey-2",children:[e.jsx("button",{type:"button",onClick:d,disabled:i,className:"inline-flex items-center justify-center rounded-lg border border-grey-2 px-4 py-2 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-4",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:m,disabled:i||!k,className:"inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-5 py-2 text-sm font-semibold text-white shadow-sm transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["Confirm publish",e.jsx(zt,{size:15,"aria-hidden":"true"})]})]})]})})}function uo({groupName:t,introCopy:r,isPreviewOnly:s=!1,items:a,onAddAudio:i,onAddVisual:l,onMoveDown:d,onMoveUp:m,onRemove:p,onTimelineChange:f,onTitleChange:j,title:y}
1){const[b,g]=o.useState("16:9"),[h,x]=o.useState(!1),[S,k]=o.useState(!1),[N,P]=o.useState(0),[w,U]=o.useState(0),q=o.useRef(null),K=o.useRef(0),Z=pa(a,"visual"),E=pa(a,"audio"),B=zl(Z,E),le=Z.length>0||E.length>0,$=le?Math.max(B,1):0,X=$>0?Math.max(0,Math.min(N,$)):0,G=ga(Z,X),ae=ga(E,X),ee=G?.item,Q=ae?.item,M=Q?.mediaUrl,_=ae?(ae.item.timeline?.trimStartSeconds??0)+Math.max(0,X-ae.startSeconds):0,T=$>0?Math.min(100,X/$*100):0;o.useEffect(()=>{if(!h||$<=0)return;const v=window.setInterval(()=>{P(D=>{const se=Math.min($,D+.25);return se>=$&&window.setTimeout(()=>x(!1),0),se})},250);return()=>window.clearInterval(v)},[h,$]),o.useEffect(()=>{P(v=>Math.min(v,$)),$<=0&&x(!1)},[$]),o.useEffect(()=>{U(v=>a.length>0?Math.min(v,a.length-1):0)},[a.length]),o.useEffect(()=>{K.current=_},[_]),o.useEffect(()=>{const v=q.current;!v||!M||ts(v,_)},[_,M]),o.useEffect(()=>{const v=q.current;!v||!M||(h?(ts(v,K.current),v.play().catch(()=>{x(!1)})):v.paused||v.pause())},[M,h]);const z=()=>{$<=0||(!h&&X>=$&&P(0),x(v=>!v))},C={aspectRatio:b==="16:9"?"16 / 9":"9 / 16"},L=b==="16:9"?"w-full":"w-full max-w-[410px]",H=(v=!1)=>e.jsx("div",{className:`relative mx-auto flex ${L} overflow-hidden rounded-lg bg-grey-7 text-white shadow-xl ring-1 ring-white/10 ${v?"max-h-[78vh]":""}`,style:C,children:le?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"absolute inset-0",children:[ee?.mediaUrl?e.jsx("img",{src:ee.mediaUrl,alt:"",className:`h-full w-full object-cover transition duration-700 ${h?"scale-[1.03]":"scale-100"}`,style:{objectPosition:`50% ${lr(ee.imageCrop)}%`}},`${ee.fileId??ee.title??"visual"}-${G?.startSeconds??0}`):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-grey-6",children:e.jsx(nr,{size:54,"aria-hidden":"true"})}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/85 via-black/40 to-black/10"})]}),e.jsxs("div",{className:"relative z-10 flex min-h-[360px] w-full flex-col justify-between p-5 sm:p-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.18em] text-white/65",children:"Memory Reel"}),e.jsx("h3",{className:"mt-2 max-w-3xl font-primary text-3xl font-bold leading-tight sm:text-4xl",children:y}),r&&e.jsx("p",{className:"mt-3 max-w-2xl text-sm leading-6 text-white/75",children:r})]}),e.jsxs("div",{children:[Q&&e.jsx("p",{className:"mb-5 max-w-2xl rounded-lg bg-black/40 p-4 font-primary text-xl leading-8 text-white shadow-lg backdrop-blur-sm",children:Q.body||Q.summary||Q.title}),e.jsx("div",{className:"h-1.5 overflow-hidden rounded-full bg-white/25",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${T}%`}})}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("button",{type:"button","aria-label":h?"Pause Memory Reel":"Play Memory Reel",onClick:z,className:"inline-flex h-11 w-11 items-center justify-center rounded-full bg-white text-grey-7 shadow-sm transition hover:bg-primary-light disabled:cursor-not-allowed disabled:opacity-50",disabled:$<=0,children:h?e.jsx(Na,{size:20,fill:"currentColor","aria-hidden":"true"}):e.jsx(Ca,{size:20,fill:"currentColor","aria-hidden":"true"})}),e.jsxs("div",{className:"flex items-center gap-2 rounded-full bg-black/40 px-3 py-2 backdrop-blur-sm",children:[e.jsx("button",{type:"button","aria-label":"Memory Reel volume",className:"inline-flex h-7 w-7 items-center justify-center rounded-full text-white transition hover:bg-white/15",children:e.jsx(wa,{size:18,"aria-hidden":"true"})}),e.jsxs("span",{className:"text-sm font-bold text-white",children:[xt(X)," / ",xt($)]})]})]}),Z.length>1&&e.jsx("div",{className:"mt-3 flex justify-center gap-1.5",children:Z.map((D,se)=>e.jsx("button",{type:"button","aria-label":`Show frame ${se+1}`,onClick:()=>P(D.startSeconds),className:`h-2 rounded-full transition-all ${D.index===G?.index?"w-8 bg-primary":"w-2 bg-white/45 hover:bg-white/70"}`},`memory-reel-frame-${D.index}`))})]})]})]}):e.jsx("div",{className:"flex h-full min-h-[360px] w-full items-center justify-center bg-grey-7",children:e.jsxs("div",{className:"max-w-sm px-6 text-center",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-lg bg-white/10 text-white",children:e.jsx(nr,{size:28,"aria-hidden":"true"})}),e.jsx("h3",{className:"mt-4 font-primary text-2xl font-bold",children:"This reel is empty"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-white/70",children:"Add visual and audio moments from the Memory Project Library to build the first cut."})]})})});return e.jsxs("div",{className:"mx-auto max-w-5xl space-y-5",children:[M?e.jsx("audio",{ref:q,"data-memory-reel-audio":!0,loop:!0,onLoadedMetadata:v=>ts(v.currentTarget,_),preload:"metadata",src:M,children:e.jsx("track",{default:!0,kind:"captions",label:"Transcript",src:Dl(Q),srcLang:"en"})},M):null,e.jsxs("section",{className:"min-w-0 overflow-hidden rounded-2xl border border-grey-2 bg-white shadow-sm dark:border-transparent dark:bg-grey-0",children:[e.jsxs("header",{className:"flex min-w-0 flex-col gap-3 border-b border-grey-2 px-5 py-4 sm:flex-row sm:items-center sm:justify-between dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:s?"Preview player":"Editable timeline"}),e.jsxs("h3",{className:"mt-1 break-words font-primary text-xl font-bold text-grey-7 dark:text-white",children:[t," Memory Reel"]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-3",children:[e.jsx("div",{className:"inline-flex overflow-hidden rounded-lg border border-grey-2 bg-white p-1 dark:border-grey-2 dark:bg-grey-0","aria-label":"Memory Reel aspect ratio",children:["16:9","9:16"].map(v=>e.jsx("button",{type:"button","aria-pressed":b===v,onClick:()=>g(v),className:`rounded-md px-3 py-1.5 text-xs font-bold transition ${b===v?"bg-primary text-white":"text-grey-5 hover:bg-grey-0 dark:text-white/75 dark:hover:bg-grey-2"}`,children:v},v))}),e.jsxs("button",{type:"button",onClick:()=>k(!0),className:"inline-flex min-h-9 items-center gap-2 rounded-lg border border-grey-2 bg-white px-3 py-1.5 text-sm font-semibold text-grey-6 transition hover:border-primary/30 hover:text-primary dark:bg-grey-0 dark:text-white",children:[e.jsx(ns,{size:15,"aria-hidden":"true"}),"Full view"]}),e.jsxs("p",{className:"text-sm font-semibold text-grey-5 dark:text-white/70",children:[xt(B)," total"]})]})]}),e.jsx("div",{className:"bg-grey-0 p-4 dark:bg-grey-0",children:H()}),s?null:e.jsx(bl,{audioItems:E,items:a,isPlaying:h,onAddAudio:i,onAddVisual:l,onPlayheadChange:P,onPlayingChange:x,onSelectItem:U,onTimelineChange:f,playheadSeconds:X,selectedIndex:w,totalDurationSeconds:B,visualItems:Z})]}),S?e.jsx(Kt,{className:"fixed inset-0 z-[90] m-0 flex h-screen w-screen max-h-none max-w-none items-center justify-center border-0 bg-grey-7/80 p-4 backdrop-blur-sm",onClose:()=>k(!1),titleId:"memory-reel-full-view-title",children:e.jsxs("section",{className:"w-full max-w-6xl overflow-hidden rounded-2xl border border-grey-2 bg-white shadow-2xl dark:border-transparent dark:bg-grey-0",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-3 border-b border-grey-2 px-5 py-4 dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Memory Reel preview"}),e.jsx("h3",{id:"memory-reel-full-view-title",className:"font-primary text-xl font-bold text-grey-7 dark:text-white",children:"Full view player"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex overflow-hidden rounded-lg border border-grey-2 bg-white p-1 dark:border-grey-2 dark:bg-grey-0","aria-label":"Full view Memory Reel aspect ratio",children:["16:9","9:16"].map(v=>e.jsx("button",{type:"button","aria-pressed":b===v,onClick:()=>g(v),className:`rounded-md px-3 py-1.5 text-xs font-bold transition ${b===v?"bg-primary text-white":"text-grey-5 hover:bg-grey-0 dark:text-white/75 dark:hover:bg-grey-2"}`,children:v},v))}),e.jsx("button",{type:"button","aria-label":"Close full view Memory Reel player",onClick:()=>k(!1),className:"inline-flex h-10 w-10 items-center justify-center rounded-lg border border-grey-2 text-grey-5 transition hover:text-grey-7 dark:text-white dark:hover:bg-grey-2",children:e.jsx(fe,{size:18,"aria-hidden":"true"})})]})]}),e.jsx("div",{className:"max-h-[82vh] overflow-auto bg-grey-0 p-4 dark:bg-grey-0",children:H(!0)})]})}
1):null,s?null:a.length===0?e.jsxs("div",{className:"rounded-2xl border border-dashed border-grey-2 bg-white p-8 text-center shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("p",{className:"font-primary text-xl font-bold text-grey-7 dark:text-white",children:"This reel is empty"}),e.jsx("p",{className:"mx-auto mt-2 max-w-md text-sm leading-6 text-grey-5",children:"Use Add visual or Add audio to start building the timeline."})]}):a[w]?e.jsx(fl,{index:w,item:a[w],onMoveDown:()=>d(w),onMoveUp:()=>m(w),onRemove:()=>p(w),onTimelineChange:v=>f(w,v),onTitleChange:v=>j(w,v)}):null]})}function bl({audioItems:t,items:r,isPlaying:s,onAddAudio:a,onAddVisual:i,onPlayheadChange:l,onPlayingChange:d,onSelectItem:m,onTimelineChange:p,playheadSeconds:f,selectedIndex:j,totalDurationSeconds:y,visualItems:b}){const[g,h]=o.useState(16),x=Math.max(y,1),S=128,k=Math.max(740,S+Math.ceil(x*g)+160),N=Math.max(0,Math.min(f,x)),P=g>=24?10:g>=14?15:30,w=Math.floor(x/P),U=Array.from({length:w+1},(K,Z)=>Z*P);U.includes(x)||U.push(x);const q=()=>{y<=0||(!s&&N>=x&&l(0),d(K=>!K))};return e.jsxs("div",{className:"min-w-0 overflow-hidden border-t border-grey-2 bg-white dark:border-grey-2 dark:bg-grey-1",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 border-b border-grey-2 px-4 py-3 sm:flex-row sm:items-center sm:justify-between dark:border-grey-2",children:[e.jsxs("button",{type:"button","aria-label":s?"Pause timeline playback":"Play timeline playback",onClick:q,disabled:y<=0,className:"flex items-center gap-3 rounded-lg pr-3 text-left transition hover:bg-grey-0 disabled:cursor-not-allowed disabled:opacity-50 dark:hover:bg-grey-2",children:[e.jsx("span",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-grey-7 text-white dark:bg-primary",children:s?e.jsx(Na,{size:16,fill:"currentColor","aria-hidden":"true"}):e.jsx(Ca,{size:16,fill:"currentColor","aria-hidden":"true"})}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:"Timeline"}),e.jsxs("span",{className:"block text-sm font-semibold text-grey-7 dark:text-white",children:[xt(N)," / ",xt(y)]})]})]}),e.jsxs("label",{className:"flex min-w-0 flex-wrap items-center gap-3 text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:["Zoom",e.jsx("input",{type:"range",min:10,max:28,step:2,value:g,onChange:K=>h(Number(K.currentTarget.value)),className:"h-1 w-32 accent-primary"}),e.jsxs("span",{className:"min-w-10 text-right text-grey-5 normal-case tracking-normal",children:[g,"px/s"]})]})]}),e.jsx("div",{className:"w-full max-w-full overflow-x-auto bg-grey-0 dark:bg-grey-0",children:e.jsxs("div",{className:"relative",style:{width:`${k}px`},children:[e.jsx("div",{className:"relative h-9 border-b border-grey-2 bg-white dark:border-grey-2 dark:bg-grey-1",children:U.map(K=>e.jsxs("div",{className:"absolute bottom-0 top-0",style:{left:`${S+K*g}px`},children:[e.jsx("span",{className:"absolute bottom-0 h-4 w-px bg-grey-3 dark:bg-white/25"}),e.jsx("span",{className:"absolute bottom-5 -translate-x-1 text-xs font-semibold text-grey-5 dark:text-white/70",children:xt(K)})]},`memory-reel-tick-${K}`))}),e.jsx("div",{className:"absolute bottom-0 top-9 z-20 w-px bg-primary shadow-[0_0_0_1px_rgba(59,130,246,0.25)]",style:{left:`${S+N*g}px`},children:e.jsx("button",{type:"button","aria-label":`Move playhead from ${xt(N)}`,className:"-ml-5 -mt-2 rounded-full bg-primary px-2 py-1 text-[11px] font-bold text-white shadow",onClick:()=>l(N>=x?0:Math.min(x,N+5)),children:xt(N)})}),e.jsx(da,{addLabel:"Add visual",emptyLabel:"Add visual clips to begin the reel.",items:b,label:"Visual track",onAdd:i,onPlayheadChange:l,onSelectItem:m,onTimelineChange:p,pixelsPerSecond:g,selectedIndex:j}),e.jsx(da,{addLabel:"Add audio",emptyLabel:"Add audio or transcript moments for narration.",items:t,label:"Audio track",onAdd:a,onPlayheadChange:l,onSelectItem:m,onTimelineChange:p,pixelsPerSecond:g,selectedIndex:j})]})}),r.length>0&&e.jsxs("p",{className:"px-5 py-3 text-xs font-semibold text-grey-4",children:[r.length," ",r.length===1?"clip":"clips"," in timeline"]})]})}function da({addLabel:t,emptyLabel:r,items:s,label:a,onAdd:i,onPlayheadChange:l,onSelectItem:d,onTimelineChange:m,pixelsPerSecond:p,selectedIndex:f}){const j=s.reduce((g,{duration:h})=>g+h,0),y=(g,h,x,S)=>{g.preventDefault(),g.stopPropagation(),d(x);const k=g.clientX,N=kt(h.timeline)??Vr(h);g.currentTarget.setPointerCapture?.(g.pointerId);const P=U=>{U.preventDefault();const q=Math.round((U.clientX-k)/p);m(x,xa(h,S,q,N))},w=()=>{window.removeEventListener("pointermove",P),window.removeEventListener("pointerup",w)};window.addEventListener("pointermove",P),window.addEventListener("pointerup",w,{once:!0})},b=(g,h,x,S)=>{if(g.key!=="ArrowLeft"&&g.key!=="ArrowRight")return;g.preventDefault();const k=g.key==="ArrowRight"?1:-1;m(x,xa(h,S,k))};return e.jsxs("div",{className:"relative min-h-28 border-b border-grey-2 bg-white/70 dark:border-grey-2 dark:bg-grey-0",children:[e.jsxs("div",{className:"absolute left-0 top-0 flex h-full w-32 flex-col justify-between border-r border-grey-2 bg-white px-3 py-4 dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:a}),e.jsx("p",{className:"text-xs font-semibold text-grey-4",children:xt(j)})]}),e.jsxs("div",{className:"relative ml-32 h-28",children:[s.length===0?e.jsx("div",{className:"absolute inset-3 flex items-center justify-center rounded-lg border border-dashed border-grey-2 px-4 text-sm font-semibold text-grey-4",children:r}):s.map(({duration:g,index:h,item:x,startSeconds:S})=>{const k=Math.max(74,g*p),N=x.title||`Clip ${h+1}`,P=f===h;return e.jsxs("div",{className:`group absolute top-4 h-20 overflow-hidden rounded-lg border bg-white text-left shadow-sm transition hover:border-primary/45 dark:bg-grey-1 ${P?"border-primary ring-2 ring-primary/35":"border-primary/20"}`,style:{left:`${S*p}px`,width:`${k}px`},children:[a==="Visual track"&&x.mediaUrl?e.jsx("img",{src:x.mediaUrl,alt:"",className:"absolute inset-0 h-full w-full object-cover opacity-65 transition group-hover:opacity-80",style:{objectPosition:`50% ${lr(x.imageCrop)}%`}}):null,e.jsxs("button",{type:"button",onClick:()=>{d(h),l(S),m(h,kt(x.timeline))},className:"relative z-10 flex h-full w-full flex-col justify-between p-3 text-left",children:[e.jsx("span",{className:"line-clamp-2 rounded bg-white/90 px-1.5 py-0.5 text-xs font-bold text-grey-7 dark:bg-grey-2/90 dark:text-white",children:N}
1),e.jsx("span",{className:"w-fit rounded bg-grey-7/80 px-1.5 py-0.5 text-xs font-semibold text-white",children:xt(g)})]}),P?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-label":`Trim start ${N}`,onKeyDown:w=>b(w,x,h,"start"),onPointerDown:w=>y(w,x,h,"start"),className:"absolute bottom-0 left-0 top-0 z-20 flex w-4 cursor-ew-resize items-center justify-center bg-primary/85 transition hover:bg-primary",children:[e.jsx("span",{className:"h-8 w-0.5 rounded-full bg-white/80","aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Drag to trim start"})]}),e.jsxs("button",{type:"button","aria-label":`Trim end ${N}`,onKeyDown:w=>b(w,x,h,"end"),onPointerDown:w=>y(w,x,h,"end"),className:"absolute bottom-0 right-0 top-0 z-20 flex w-4 cursor-ew-resize items-center justify-center bg-primary/85 transition hover:bg-primary",children:[e.jsx("span",{className:"h-8 w-0.5 rounded-full bg-white/80","aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Drag to trim end"})]})]}):null]},`timeline-${a}-${x.fileId??x.pageId??x.title??h}-${h}`)}),i?e.jsxs("button",{type:"button",onClick:i,className:"absolute top-1/2 inline-flex h-10 -translate-y-1/2 items-center gap-1 rounded-lg border border-dashed border-grey-3 bg-white/95 px-3 text-xs font-bold text-grey-6 shadow-sm transition hover:border-primary hover:text-primary dark:border-white/25 dark:bg-grey-1 dark:text-white/80",style:{left:`${Math.max(12,j*p+12)}px`},children:[e.jsx(at,{size:14,"aria-hidden":"true"}),t]}):null]})]})}function fl({index:t,item:r,onMoveDown:s,onMoveUp:a,onRemove:i,onTimelineChange:l,onTitleChange:d}){const m=kt(r.timeline)??Vr(r),p=m?.track??Gt(r),f=m?.durationSeconds??ws(r),j=m?.trimStartSeconds??0,y=m?.trimEndSeconds??j+f,b=m?.sourceDurationSeconds,g=r.title||`Clip ${t+1}`,h=p==="audio",x=P=>{l(kt({...m,...P,track:p}))},S=P=>{const w=nt(P,1,b??600),U=b?Math.min(b,j+w):j+w;x({durationSeconds:w,trimEndSeconds:U})},k=P=>{const w=nt(P,0,b??Math.max(y,P)),U=Math.max(w+1,y);x({trimStartSeconds:w,trimEndSeconds:b?Math.min(b,U):U,durationSeconds:Math.max(1,U-w)})},N=P=>{const w=nt(P,j+1,b??Math.max(j+1,P));x({trimEndSeconds:w,durationSeconds:Math.max(1,w-j)})};return e.jsx("article",{className:"min-w-0 rounded-2xl border border-grey-2 bg-white p-4 text-grey-7 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:e.jsxs("div",{className:"flex min-w-0 flex-col gap-4 lg:flex-row lg:items-start",children:[e.jsx("div",{className:"min-w-0 lg:w-44",children:e.jsx("div",{className:"flex aspect-video items-center justify-center overflow-hidden rounded-lg bg-grey-1 dark:bg-grey-2",children:!h&&r.mediaUrl?e.jsx("img",{src:r.mediaUrl,alt:"",className:"h-full w-full object-cover",style:{objectPosition:`50% ${lr(r.imageCrop)}%`}}):e.jsxs("div",{className:"text-center text-grey-4",children:[h?e.jsx(bs,{size:32,className:"mx-auto","aria-hidden":"true"}):e.jsx(nr,{size:34,className:"mx-auto","aria-hidden":"true"}),e.jsx("p",{className:"mt-2 text-xs font-bold uppercase tracking-[0.12em]",children:h?"Audio":"Visual"})]})})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-xs font-bold uppercase tracking-[0.14em] text-grey-4",children:["Selected clip / ",p==="audio"?"Audio track":"Visual track"]}),e.jsx("label",{className:"sr-only",htmlFor:`memory-reel-clip-title-${t}`,children:"Clip title"}),e.jsx("input",{id:`memory-reel-clip-title-${t}`,name:`memoryReelClipTitle-${t}`,value:g,onChange:P=>d(P.target.value),className:"mt-2 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 font-primary text-lg font-bold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap gap-1",children:[e.jsx(fr,{label:`Move up ${g}`,onClick:a,icon:Fa}),e.jsx(fr,{label:`Move down ${g}`,onClick:s,icon:wr}),e.jsx(fr,{label:`Delete ${g}`,onClick:i,icon:gt})]})]}),(r.body||r.summary)&&e.jsx("p",{className:"rounded-lg bg-grey-0 p-4 text-sm leading-6 text-grey-6 dar
1k:bg-grey-2/40",children:r.body||r.summary}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.12em] text-grey-4",children:"Duration"}),e.jsx("input",{type:"number",min:1,max:b??600,value:Math.round(f),onChange:P=>S(Number(P.target.value)),className:"mt-1 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"}),e.jsx("span",{className:"mt-1 block text-xs font-semibold text-primary",children:xt(f)})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.12em] text-grey-4",children:"Trim start"}),e.jsx("input",{type:"number",min:0,max:b??void 0,value:Math.round(j),onChange:P=>k(Number(P.target.value)),className:"mt-1 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-xs font-bold uppercase tracking-[0.12em] text-grey-4",children:"Trim end"}),e.jsx("input",{type:"number",min:1,max:b??void 0,value:Math.round(y),onChange:P=>N(Number(P.target.value)),className:"mt-1 w-full rounded-lg border border-grey-2 bg-grey-0 px-3 py-2 text-sm font-semibold text-grey-7 outline-none transition focus:border-primary dark:border-grey-2 dark:bg-grey-2/50"})]})]}),b?e.jsxs("p",{className:"text-xs font-semibold text-grey-4",children:["Source duration ",xt(b)]}):null]})]})})}function vl({groupName:t,introCopy:r,items:s,onClose:a,title:i}){return e.jsx(Kt,{className:"fixed inset-0 z-[80] m-0 h-screen w-screen max-h-none max-w-none border-0 bg-grey-7/80 p-3 backdrop-blur-sm sm:p-4",onClose:a,titleId:"memory-reel-preview-title",children:e.jsxs("section",{className:"mx-auto flex h-full max-w-7xl flex-col overflow-hidden rounded-2xl border border-grey-2 bg-grey-0 shadow-2xl dark:border-transparent",children:[e.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-grey-2 bg-white px-5 py-4 dark:bg-grey-1",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Memory Reel Preview"}),e.jsx("h3",{id:"memory-reel-preview-title",className:"truncate font-primary text-xl font-bold text-grey-7 dark:text-white",children:i})]}),e.jsxs("button",{type:"button","aria-label":"Close Memory Reel preview",onClick:a,className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-grey-2 text-grey-5 transition hover:border-primary/30 hover:text-grey-7",children:[e.jsx(fe,{size:18,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto bg-grey-0 p-4 dark:bg-grey-0 sm:p-6",children:e.jsx(uo,{groupName:t,introCopy:r,isPreviewOnly:!0,items:s,onMoveDown:()=>{},onMoveUp:()=>{},onRemove:()=>{},onTimelineChange:()=>{},onTitleChange:()=>{},title:i})})]})})}function jl({albumTitle:t,coverImagePosition:r,coverImageUrl:s,dedication:a,items:i,onClose:l}){const d=o.useMemo(()=>xo({albumTitle:t,coverImagePosition:r,coverImageUrl:s,dedication:a,fallbackStoryImageUrl:go(i)??s,items:i}),[t,r,s,a,i]),m=o.useMemo(()=>Jn(d),[d]);return e.jsx(Kt,{className:"fixed inset-0 z-[80] m-0 h-screen w-screen max-h-none max-w-none border-0 bg-grey-7/75 p-3 backdrop-blur-sm sm:p-4",onClose:l,titleId:"memory-album-preview-title",children:e.jsxs("section",{className:"mx-auto flex h-full max-w-7xl flex-col overflow-hidden rounded-2xl border border-grey-2 bg-[#f4f1eb] shadow-2xl",children:[e.jsxs("header",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-grey-2 bg-white px-5 py-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-bold uppercase tracking-[0.16em] text-primary",children:"Memory Album Preview"}),e.jsx("h3",{id:"memory-album-preview-title",className:"truncate font-primary text-xl font-bold text-grey-7",children:t})]}),e.jsxs("button",{type:"button","aria-label":"Close Memory Album preview",onClick:l,className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-grey-2 text-grey-5 transition hover:border-primary/30 hover:text-grey-7",children:[e.jsx(fe,{size:18,"aria-hidden":"true"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-3 py-6 sm:px-8",children:e.jsx("div",{className:"mx-auto
1space-y-8",style:{maxWidth:"min(1180px, calc((100svh - 172px) * 1.414))"},children:m.map((p,f)=>e.jsxs("div",{className:"space-y-3",children:[e.jsx(wl,{left:p[0].content,right:p[1]?.content??e.jsx(Sl,{})}),e.jsxs("p",{className:"text-center text-xs font-semibold text-grey-5",children:["Spread ",f+1," / ",m.length]})]},`memory-album-preview-spread-${p[0].id}-${f}`))})})]})})}function xo({albumTitle:t,coverImagePosition:r,coverImageUrl:s,dedication:a,editControls:i,fallbackStoryImageUrl:l,items:d,onCreateQuoteFromStory:m,onCreateQuoteFromSelection:p,onQuoteSelection:f,quoteSelection:j}){const y=d.map((g,h)=>({id:gs(g,h),label:_l(g),title:g.title||`Page ${h+1}`})),b=[{id:"cover",label:"Cover",title:t,content:e.jsx(kl,{albumTitle:t,coverImagePosition:r,coverImageUrl:s,dedication:a,editControls:i})},{id:"index",label:"Index",title:"Index",content:e.jsx(Nl,{entries:y})}];return d.forEach((g,h)=>{const x=yo(g),S=g.itemType==="quote",k=!x&&!S?g.mediaRemoved?void 0:g.mediaUrl??l:void 0,N=g.body||g.summary||(x?"":"Story text will appear here.");(!x&&!S?Tl(N,!!k):[N]).forEach((w,U)=>{const q=String(b.length+1).padStart(2,"0"),K=U>0;b.push({id:`${gs(g,h)}${K?`-continued-${U}`:""}`,isContinuation:K,itemIndex:h,label:`Page ${q}`,title:K?`${g.title||`Page ${h+1}`} continued`:g.title||`Page ${h+1}`,content:e.jsx(Cl,{bodyOverride:w,fallbackStoryImageUrl:l,editControls:i,isContinuation:K,item:g,itemIndex:h,onCreateQuoteFromStory:m,onCreateQuoteFromSelection:p,onQuoteSelection:f,pageNumber:q,quoteSelection:j?.itemIndex===h?j:null})})})}),b}function wl({left:t,right:r}){return e.jsxs("div",{className:"relative rounded-2xl bg-white p-3 shadow-[0_18px_54px_rgba(49,43,38,0.16)] sm:p-5",children:[e.jsx("div",{className:"pointer-events-none absolute bottom-5 left-1/2 top-5 z-10 w-10 -translate-x-1/2 bg-gradient-to-r from-transparent via-black/15 to-transparent blur-sm"}),e.jsxs("div",{className:"grid grid-cols-2",children:[e.jsx("div",{className:"aspect-[210/297] overflow-hidden rounded-l-sm bg-white shadow-[inset_-18px_0_30px_rgba(0,0,0,0.045)] sm:rounded-l-lg",children:e.jsx(ps,{children:t})}),e.jsx("div",{className:"aspect-[210/297] overflow-hidden rounded-r-sm bg-white shadow-[inset_18px_0_30px_rgba(0,0,0,0.045)] sm:rounded-r-lg",children:e.jsx(ps,{children:r})})]})]})}function ps({children:t}){return e.jsx("div",{className:"relative h-full w-full overflow-hidden bg-white [container-type:inline-size]","data-memory-album-static-page":!0,children:e.jsx("div",{className:"origin-top-left",style:{height:`${Xn}px`,transform:`scale(calc(100cqw / ${na}px))`,width:`${na}px`},children:t})})}function kl({albumTitle:t,coverImagePosition:r,coverImageUrl:s,dedication:a,editControls:i}){const l=!!i,d=rl(t),m=sl(a),f=t.trim().length>40?4:2,j=(a??"").trim().length>70?4:3;return e.jsxs("div",{className:"flex h-full flex-col justify-center px-10 py-9 text-center text-stone-800",children:[s||l?e.jsxs("div",{className:`group relative -mx-2 mb-6 overflow-hidden rounded-sm bg-stone-100 ${l?"focus-within:ring-2 focus-within:ring-primary/35":""}`,children:[s?e.jsx("img",{src:s,alt:"",className:"h-32 w-full object-cover",style:{objectPosition:`50% ${r}%`}}):e.jsxs("div",{className:"flex h-28 flex-col items-center justify-center gap-2 text-stone-300",children:[e.jsx(ft,{size:28,"aria-hidden":"true"}),e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.18em]",children:"Cover image"})]}),i?e.jsxs("div",{className:`absolute inset-x-0 bottom-0 max-h-full bg-white/70 p-2 text-left shadow-[0_-8px_18px_rgba(49,43,38,0.08)] backdrop-blur-[2px] transition duration-150 ${s?"translate-y-[calc(100%-36px)] opacity-0 group-hover:translate-y-0 group-hover:opacity-100 group-focus-within:translate-y-0 group-focus-within:opacity-100":""}`,onClick:y=>y.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("button",{type:"button","aria-label":"Choose cover",onClick:y=>{y.stopPropagation(),i.onToggleCoverPicker()},className:"inline-flex items-center gap-1 rounded border border-stone-200 bg-white px-2 py-1 text-[10px] font-bold uppercase tracking-[0.12em] text-stone-500 shadow-sm transition hover:text-primary",children:[e.jsx(Lr,{size:12,"aria-hidden":"true"}),s?"Replace cover image":"Choose cover"]}
1),s?e.jsx("button",{type:"button","aria-label":"Remove cover image",onClick:y=>{y.stopPropagation(),i.onRemoveCoverImage()},className:"text-[10px] font-bold uppercase tracking-[0.12em] text-stone-400 transition hover:text-red-600",children:"Remove"}):null]}),s?e.jsxs("label",{className:"mt-2 block",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.16em] text-stone-300",children:"Position"}),e.jsx("input",{name:"memoryAlbumCoverPositionInline",type:"range",min:0,max:100,value:r,onClick:y=>y.stopPropagation(),onChange:y=>i.onCoverPositionChange(Number(y.target.value)),className:"mt-1 w-full"})]}):null]}):null]}):null,e.jsx("div",{className:"mx-auto h-px w-16 bg-stone-200"}),e.jsx("p",{className:"mt-8 text-[10px] font-bold uppercase tracking-[0.26em] text-stone-300",children:"Memory Album"}),l?e.jsx("textarea",{"aria-label":"Album title",name:"memoryAlbumCoverTitleInline",value:t,maxLength:oo,onChange:y=>i?.onTitleChange(y.target.value),rows:f,className:`mx-auto mt-8 w-full max-w-md resize-none overflow-hidden border-b border-transparent bg-transparent px-1 py-2 text-center font-primary font-light text-stone-800 outline-none transition [overflow-wrap:anywhere] focus:border-primary/40 ${d}`}):e.jsx("h4",{className:`mx-auto mt-8 max-w-md break-words font-primary font-light text-stone-800 [overflow-wrap:anywhere] ${d}`,children:t}),e.jsx("div",{className:"mx-auto mt-8 h-px w-16 bg-stone-200"}),l?e.jsx("textarea",{"aria-label":"Dedication",name:"memoryAlbumCoverDedicationInline",value:a??"",maxLength:io,onChange:y=>i?.onDedicationChange(y.target.value),placeholder:"write a dedication here...",rows:j,className:`mx-auto mt-8 max-h-28 w-full max-w-xs resize-none overflow-hidden border-b border-transparent bg-transparent px-1 py-1 text-center font-primary font-light text-stone-500 outline-none transition [overflow-wrap:anywhere] placeholder:text-stone-300 focus:border-primary/40 ${m}`}):a?e.jsx("p",{className:`mx-auto mt-8 max-w-xs break-words font-primary font-light text-stone-500 [overflow-wrap:anywhere] ${m}`,children:a}):null,e.jsx("div",{className:"mt-auto pt-12",children:e.jsx(js,{className:"h-5 opacity-[0.18]"})})]})}function Nl({entries:t}){return e.jsxs("div",{className:"flex h-full flex-col px-6 py-8 sm:px-12 sm:py-10",children:[e.jsx("p",{className:"text-[9px] font-bold uppercase tracking-[0.2em] text-stone-300",children:"Index"}),e.jsx("div",{className:"mt-3 h-px w-10 bg-stone-200"}),e.jsxs("div",{className:"mt-8 space-y-1",children:[t.map((r,s)=>e.jsxs("div",{className:"flex items-baseline gap-4 border-b border-stone-100 py-4",children:[e.jsx("span",{className:"shrink-0 font-secondary text-sm text-stone-300",children:String(s+1).padStart(2,"0")}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-primary text-base text-stone-700",children:r.title}),e.jsx("span",{className:"shrink-0 text-[10px] font-bold uppercase tracking-[0.18em] text-stone-300",children:r.label})]},r.id)),t.length===0&&e.jsx("p",{className:"text-sm leading-relaxed text-stone-500",children:"No chapters or story pages are available yet."})]})]})}function Cl({bodyOverride:t,editControls:r,fallbackStoryImageUrl:s,isContinuation:a=!1,item:i,itemIndex:l,onCreateQuoteFromStory:d,onCreateQuoteFromSelection:m,onQuoteSelection:p,pageNumber:f,quoteSelection:j}){const y=yo(i),b=i.title||"Untitled page",g=t??i.body??i.summary??(y?"":"Story text will appear here."),h=Ml(g),x=lr(i.imageCrop),S=!a&&!y&&i.itemType!=="quote"?i.mediaRemoved?void 0:i.mediaUrl??s:void 0,k=!a&&!y&&i.itemType!=="quote"&&!!r,N=!!i.mediaUrl,P=!!(i.fileId&&i.mediaUrl);return y?e.jsxs("div",{className:"flex h-full flex-col",children:[e.jsx("div",{className:"relative flex-1 overflow-hidden bg-stone-50",children:i.mediaUrl?e.jsx("img",{src:i.mediaUrl,alt:"",className:"absolute inset-0 h-full w-full object-cover",style:{objectPosition:`50% ${x}%`}}):e.jsx("div",{className:"flex h-full items-center justify-center text-stone-300",children:e.jsx(ft,{size:40,"aria-hidden":"true"})})}),e.jsxs("div",{className:"px-6 py-7 sm:px-12",children:[r?e.jsx("input",{"aria-label":`Media title ${l+1}`,name:`memoryAlbumMediaTitle-${l}`,value:b,onChange:w=>r.onMediaTitleChange(l,w.target.value),className:"w-full bg-transparent font-primary text-2xl font-light leading-tight text-stone-800 outline-none ring-primary/30 transition focus:ring-2"}):e.jsx("h4",{className:"font-primary text-2xl font-light leading-tight text-stone-800",children:b}),r?e.jsxs("label",{className:"mt-4 block",children:[e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.16em] text-stone-300",children:"Image vertical position"}),e.jsx("input",{name:`memoryAlbumMediaPosition-${l}`,type:"range",min:0,max:100,value:x,onChange:w=>r.onMediaImagePositionChange(l,Number(w.target.value)),className:"mt-1 w-full"})]}):null,e.jsx(Zr,{})]})]}):i.itemType==="quote"?e.jsxs("div",{className:"flex h-full flex-col px-6 py-8 sm:px-12",children:[e.jsx(ca,{pageNumber:f}),e.jsx("p",{className:"mt-16 text-5xl font-primary text-stone-200","aria-hidden":"true",children:'"'}),e.jsxs("p",{className:"mt-5 font-primary text-3xl font-light leading-tight text-stone-800",children:['"',g,'"']}),e.jsx("p",{className:"mt-8 text-[10px] font-bold uppercase tracking-[0.18em] text-stone-300",children:b}),r?e.jsx("button",{type:"button",onClick:()=>
1r.onUndoQuote(l),className:"mt-8 inline-flex w-fit items-center rounded-full border border-stone-200 px-4 py-2 text-xs font-bold uppercase tracking-[0.12em] text-stone-500 transition hover:border-primary/30 hover:text-primary",children:"Undo quote"}):null,e.jsx(Zr,{})]}):e.jsxs("div",{className:"relative flex h-full flex-col",children:[S||k?e.jsxs("div",{className:"group relative h-[24%] overflow-hidden bg-stone-100 focus-within:ring-2 focus-within:ring-primary/35",children:[S?e.jsx("img",{src:S,alt:"",className:"h-full w-full object-cover",style:{objectPosition:`50% ${x}%`}}):e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 text-stone-300",children:[e.jsx(ft,{size:24,"aria-hidden":"true"}),e.jsx("span",{className:"text-[9px] font-bold uppercase tracking-[0.16em]",children:"Story image"})]}),k&&r?e.jsxs("div",{className:`absolute inset-x-0 bottom-0 bg-white/70 p-2 text-left shadow-[0_-8px_18px_rgba(49,43,38,0.08)] backdrop-blur-[2px] transition duration-150 ${S?"translate-y-[calc(100%-34px)] opacity-0 group-hover:translate-y-0 group-hover:opacity-100 group-focus-within:translate-y-0 group-focus-within:opacity-100":""}`,onClick:w=>w.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button","aria-label":`Replace story image for ${b}`,onClick:w=>{w.stopPropagation(),r.onToggleStoryImagePicker(l)},className:"inline-flex items-center gap-1 rounded border border-stone-200 bg-white px-2 py-1 text-[10px] font-bold uppercase tracking-[0.12em] text-stone-500 transition hover:border-primary/30 hover:text-primary",children:[e.jsx(Lr,{size:12,"aria-hidden":"true"}),S?"Replace image":"Choose image"]}),N?e.jsx("button",{type:"button","aria-label":`Remove story image for ${b}`,onClick:w=>{w.stopPropagation(),r.onRemoveStoryImage(l)},className:"text-[10px] font-bold uppercase tracking-[0.12em] text-stone-400 transition hover:text-red-600",children:"Remove"}):null]}),P?e.jsxs("label",{className:"mt-2 block text-[9px] font-bold uppercase tracking-[0.14em] text-stone-300",htmlFor:`memory-album-story-image-position-${l}`,children:["Position",e.jsx("input",{id:`memory-album-story-image-position-${l}`,name:`memoryAlbumStoryImagePosition-${l}`,type:"range",min:0,max:100,value:x,onClick:w=>w.stopPropagation(),onChange:w=>r.onStoryImagePositionChange(l,Number(w.target.value)),className:"mt-1 w-full"})]}):null]}):null]}):null,e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col px-6 py-8 sm:px-12",children:[e.jsx(ca,{pageNumber:f}),a?e.jsx("p",{className:"mt-8 text-[10px] font-bold uppercase tracking-[0.2em] text-stone-300",children:"Continued"}):e.jsxs(e.Fragment,{children:[e.jsx("h4",{"data-album-story-title":!0,className:"mt-8 font-primary text-3xl font-light leading-tight text-stone-800",children:b}),e.jsxs("div",{className:"my-5 flex items-center gap-2",children:[e.jsx("div",{className:"h-px w-6 bg-stone-300"}),e.jsx("div",{className:"h-1 w-1 rounded-full bg-stone-300"}),e.jsx("div",{className:"h-px w-6 bg-stone-300"})]})]}),e.jsx("div",{"data-album-story-body":!0,onMouseUp:w=>{w.stopPropagation(),p?.(l)},onKeyUp:()=>p?.(l),className:"space-y-3 overflow-hidden font-secondary text-[13px] leading-[1.65] text-stone-600",children:h.map((w,U)=>e.jsx("p",{children:w},`${gs(i,U)}-paragraph-${U}`))}),j?e.jsxs("div",{className:"mt-4 flex items-center gap-3 rounded-full bg-stone-950 px-4 py-3 text-white shadow-xl",children:[e.jsxs("p",{className:"min-w-0 flex-1 truncate text-xs text-white/70",children:['"',j.text,'"']}),e.jsx("button",{type:"button",onClick:w=>{w.stopPropagation(),m?.()},className:"shrink-0 rounded-full bg-white px-4 py-2 text-xs font-bold text-stone-900",children:"Mark as quote"})]}):!a&&d?e.jsx("button",{type:"button",onClick:w=>{w.stopPropagation(),d(l)},className:"mt-4 inline-flex w-fit items-center rounded-full border border-stone-200 px-4 py-2 text-[10px] font-bold uppercase tracking-[0.12em] text-stone-500 transition hover:border-primary/30 hover:text-primary focus:outline-none focus:ring-2 focus:ring-primary/30",children:"Create quote"}):null,e.jsx(Zr,{})]})]})}function ca({pageNumber:t}){return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"font-secondary text-xs text-stone-300",children:t}),e.jsx("div",{className:"h-px flex-1 bg-stone-100"}),e.jsx(js,{className:"h-3.5 opacity-[0.16]"})]})}function Zr(){return e.jsx("div",{className:"mt-auto pt-10",children:e.jsx(js,{className:"h-4 opacity-[0.16]"})})}function js({className:t}){return e.jsx("img",{src:"/images/logo.svg",alt:"Autograph",className:`${t} w-auto brightness-0`})}function Sl(){return e.jsx("div",{className:"h-full bg-white"})}function es(t){return t.mediaUrl??t.imageUrl??t.coverImageUrl??t.headerImage??t.thumbnailUrl}function ma(t){return t?.trim().toLowerCase().replace(/\s+/g," ")||null}function Il(t){return t.currentDraftSnapshot?.title??t.title??""}function Pl(t,r){const s=t.trim()||"Untitled draft",a=new Set(r.map(i=>
1i.trim().toLowerCase()).filter(Boolean));if(!a.has(s.toLowerCase()))return s;for(let i=2;i<1e3;i+=1){const l=`${s} v${i}`;if(!a.has(l.toLowerCase()))return l}return`${s} v${Date.now()}`}function Ml(t){return t.split(/\n{2,}/).map(r=>r.trim()).filter(Boolean).slice(0,4)}function Tl(t,r){const s=t.replace(/\s+/g," ").trim();if(!s)return[""];const a=[];let i=s,l=r?el:Zn;for(;i.length>l;){const d=i.slice(0,l),m=Math.max(d.lastIndexOf(". "),d.lastIndexOf("? "),d.lastIndexOf("! "),d.lastIndexOf("; "),d.lastIndexOf(", "),d.lastIndexOf(" ")),p=m>l*.55?m+1:l;a.push(i.slice(0,p).trim()),i=i.slice(p).trim(),l=tl}return i&&a.push(i),a}function po(t){const r=t?.replace(/\s+/g," ").trim().replace(/^["'\u201C\u2018]+|["'\u201D\u2019]+$/g,"");return!r||r.length<12?null:r}function Rl(t){const r=po(t);if(!r)return null;const s=r.search(/[.!?](\s|$)/);if(s>=60&&s<=220)return r.slice(0,s+1);const a=r.slice(0,220).trim();return a.length>=12?a:null}function go(t){return t.find(r=>Gt(r)==="visual"&&r.mediaUrl)?.mediaUrl}function gs(t,r){return`${t.itemType??"item"}-${t.pageId??t.quoteId??t.fileId??t.title??r}-${r}`}function Tt(t){return t?t.replace(/\.[^.]+$/,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,s=>s.toUpperCase())||t:"Untitled image"}function fr({icon:t,label:r,onClick:s}){return e.jsx("button",{type:"button",onClick:s,className:"mt-1 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-grey-2 text-grey-5 transition hover:border-primary/30 hover:text-primary","aria-label":r,children:e.jsx(t,{size:17,"aria-hidden":"true"})})}function El(t,r,s){const a=[t>0?`${t} ${t===1?"story":"stories"}`:null,r>0?`${r} ${r===1?"source":"sources"}`:null,s>0?`${s} ${s===1?"quote":"quotes"}`:null].filter(Boolean);return a.length>0?a.join(", "):"Memory Project collection"}function _l(t){return t.itemType==="page"?"Story":t.itemType==="media"||t.itemType==="source"?Gt(t)==="audio"?"Audio":"Media":t.itemType==="quote"?"Quote":t.itemType==="text"?"Text":Gt(t)==="audio"?"Audio":"Story"}function yo(t){return t.itemType==="media"||t.itemType==="source"}function Gt(t){return t.timeline?.track==="audio"?"audio":t.timeline?.track==="visual"?"visual":t.itemType==="text"||t.itemType==="quote"||t.itemType==="page"?"audio":"visual"}function nt(t,r,s){const a=typeof t=="number"&&Number.isFinite(t)?t:r;return Math.min(s,Math.max(r,a))}function kt(t){if(!t)return;const r={};(t.track==="visual"||t.track==="audio")&&(r.track=t.track);const s=typeof t.sourceDurationSeconds=="number"&&t.sourceDurationSeconds>0?nt(t.sourceDurationSeconds,1,86400):void 0,a=typeof t.trimStartSeconds=="number"?nt(t.trimStartSeconds,0,s??86400):void 0,i=typeof t.trimEndSeconds=="number"?nt(t.trimEndSeconds,a!==void 0?a+1:1,s??86400):void 0,l=typeof t.transcriptStartSeconds=="number"?nt(t.transcriptStartSeconds,0,s??86400):void 0,d=typeof t.transcriptEndSeconds=="number"?nt(t.transcriptEndSeconds,l!==void 0?l+1:1,s??86400):void 0,m=typeof t.durationSeconds=="number"&&t.durationSeconds>0?nt(t.durationSeconds,1,86400):a!==void 0&&i!==void 0?Math.max(1,i-a):void 0;return s!==void 0&&(r.sourceDurationSeconds=s),a!==void 0&&(r.trimStartSeconds=a),i!==void 0&&(r.trimEndSeconds=i),l!==void 0&&(r.transcriptStartSeconds=l),d!==void 0&&(r.transcriptEndSeconds=d),m!==void 0&&(r.durationSeconds=m),Object.keys(r).length>0?r:void 0}function ua(t,r){const s=typeof t.durationSecs=="number"&&t.durationSecs>0?nt(t.durationSecs,1,86400):void 0,a=s?Math.min(s,r==="audio"?18:8):r==="audio"?18:8;return kt({track:r,sourceDurationSeconds:s,trimStartSeconds:0,trimEndSeconds:a,durationSeconds:a})}function Vr(t){const r=Gt(t),s=r==="audio"?12:8;return kt({track:r,durationSeconds:s,trimStartSeconds:0,trimEndSeconds:s})}function ws(t){const r=kt(t.timeline)??Vr(t);return r?.durationSeconds?r.durationSeconds:r?.trimStartSeconds!==void 0&&r.trimEndSeconds!==void 0?Math.max(1,r.trimEndSeconds-r.trimStartSeconds):Gt(t)==="audio"?12:8}function xa(t,r,s,a){const i=kt(a??t.timeline)??Vr(t),l=i?.track??Gt(t),d=i?.trimStartSeconds??0,m=i?.durationSeconds??ws(t),p=i?.trimEndSeconds??d+m,f=i?.sourceDurationSeconds;if(r==="start"){const b=nt(d+s,0,p-1);return kt({...i,track:l,trimStartSeconds:b,durationSeconds:Math.max(1,p-b)})}const j=Math.max(d+1,p+s,p),y=nt(p+s,d+1,f??j);return kt({...i,track:l,trimEndSeconds:y,durationSeconds:Math.max(1,y-d)})}function pa(t,r){let s=0;return t.map((a,i)=>({item:a,index:i})).filter(({item:a})=>Gt(a)===r).map(({item:a,index:i})=>{const l=ws(a),d={duration:l,endSeconds:s+l,index:i,item:a,startSeconds:s,track:r};return s+=l,d})}function zl(t,r){const s=t.at(-1)?.endSeconds??0,a=r.at(-1)?.endSeconds??0;return Math.max(s,a)}function ga(t,r){return t.length===0?void 0:t.find(({endSeconds:a,startSeconds:i})=>r>=i&&r<a)??t.at(-1)}function Dl(t){const s=`WEBVTT 2 300:00:00.000 --> 23:59:59.000 4${(t?.body||t?.summary||t?.title||"Audio track").replace(/\s+/g," ").trim()||"Audio track"}`;return`data:text/vtt;charset=utf-8,${encodeURIComponent(s)}`}function Al(t,r){const s=Math.max(0,r);return Number.isFinite(t.duration)&&t.duration>0&&s>t.duration?s%t.duration:!Number.isFinite(t.duration)&&s>0?0:s}function ts(t,r){if(!Number.isFinite(r))return;const s=Al(t,r);Math.abs(t.currentTime-s)>.5&&(t.currentTime=s)}function xt(t){const r=nt(t??0,0,86400),s=Math.round(r),a=Math.floor(s/60),i=s%60;return a>0?`${a}
4:${String(i).padStart(2,"0")}`:`${i}s`}function ks(t,r){return t instanceof Error&&t.message.trim()?t.message:r}function $l(t){const r=ks(t,"Publish failed. Please try again.");return r.includes("Memory Album requires a final PDF export before publishing")?ol:r.match(/Uncaught Error:\s*(.+?)(?:\s+at\s|\s+Called by client|$)/s)?.[1]?.trim()||r}function Ul(t){return t?new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}).format(new Date(t)):"recently"}function ya({title:t,description:r}){return e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-xl font-bold text-grey-7",children:t}),e.jsx("p",{className:"mt-1 text-sm leading-6 text-grey-5",children:r})]})}function Ll(t){return Wr.map(r=>{const s=t.find(a=>a.type===r.type);return s?{...s,type:r.type}:{placeholder:!0,type:r.type}})}function Fl(t){return t.filter(r=>r.type==="memoryAlbum"||r.type==="memoryReel").map(r=>({...r,type:r.type}))}function ha({keepsakes:t,canManage:r,onUnpublish:s,onView:a}){return e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:t.map((i,l)=>e.jsx(Ol,{keepsake:i,canManage:r,onUnpublish:s,onView:a},i.keepsakeId??i.publicSlug??l))})}function Ol({keepsake:t,canManage:r,onUnpublish:s,onView:a}){const[i,l]=o.useState(!1),[d,m]=o.useState(null),[p,f]=o.useState(!1);if(t.placeholder){const g=dt(t.type),h=t.type==="memoryReel"?nr:st;return e.jsx("article",{className:"flex min-h-[220px] flex-col justify-between rounded-xl border border-dashed border-grey-2 bg-grey-0 p-4 dark:border-grey-2 dark:bg-grey-2/30",children:e.jsxs("div",{children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-white text-primary shadow-sm dark:bg-grey-1",children:e.jsx(h,{size:18,"aria-hidden":"true"})}),e.jsx("p",{className:"mt-4 text-xs font-semibold uppercase tracking-[0.12em] text-grey-4",children:g}),e.jsxs("h3",{className:"mt-1 font-primary text-base font-bold text-grey-7",children:[g," not published yet"]}),e.jsx("p",{className:"mt-2 text-sm leading-5 text-grey-5",children:"Publish from Studio when this keepsake is ready for members."})]})})}const j=t.title??t.heroTitle??dt(t.type),y=async()=>{m(null),f(!0);try{await s(t),l(!1)}catch(g){m(ks(g,"Unpublish failed. Please try again."))}finally{f(!1)}},b=r?i?e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2 text-right",children:[e.jsx("p",{className:"basis-full text-xs font-semibold text-grey-5",children:"Remove this public page?"}),d&&e.jsx("p",{className:"basis-full text-xs font-semibold text-red-600 dark:text-red-400",children:d}),e.jsx("button",{type:"button",onClick:()=>{l(!1),m(null)},disabled:p,className:"inline-flex rounded-full border border-grey-2 px-3 py-1.5 text-xs font-semibold text-grey-5 transition hover:border-primary/30 hover:text-primary disabled:cursor-not-allowed disabled:text-grey-4",children:"Cancel"}),e.jsx("button",{type:"button",onClick:()=>{y()},disabled:p,className:"inline-flex rounded-full border border-red-200 px-3 py-1.5 text-xs font-bold text-red-600 transition hover:bg-red-50 disabled:cursor-not-allowed disabled:border-grey-2 disabled:text-grey-4",children:"Confirm unpublish"})]}):e.jsx("button",{type:"button",onClick:()=>{l(!0),m(null)},"aria-label":`Unpublish ${j}`,className:"inline-flex h-9 w-9 items-center justify-center rounded-full border border-grey-2 text-grey-5 transition hover:border-red-200 hover:bg-red-50 hover:text-red-600",children:e.jsx(gt,{size:16,"aria-hidden":"true"})}):null;return e.jsxs("article",{className:"overflow-hidden rounded-xl border border-grey-1 bg-grey-0 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsx("div",{className:"relative aspect-[16/10] bg-grey-1 dark:bg-grey-2",children:t.coverImageUrl?e.jsx("img",{src:t.coverImageUrl,alt:"",className:"h-full w-full object-cover"}):e.jsx("div",{className:"flex h-full items-center justify-center bg-primary-light text-primary",children:e.jsx(ft,{size:28,"aria-hidden":"true"})})}),e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.12em] text-grey-4",children:dt(t.type)}),e.jsx("h3",{className:"mt-1 font-primary text-base font-bold text-grey-7",children:j}),t.heroDescription&&e.jsx("p",{className:"mt-1 line-clamp-2 text-sm leading-5 text-grey-5",children:t.heroDescription})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>a(t.urlPath),className:"inline-flex items-center gap-2 rounded-full bg-grey-7 px-3 py-2 text-sm font-semibold text-white transition hover:bg-grey-6 dar
4k:bg-grey-2 dark:text-grey-7 dark:hover:bg-grey-2/80",children:[e.jsx(xi,{size:14,"aria-hidden":"true"}),"View"]}),b]})]})]})}function Bl({groupName:t,deliverables:r,onComingSoon:s,onOpenDeliverable:a,seedReadyByType:i}){return e.jsxs("div",{className:"mt-4",children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Your keepsakes are ready"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:"Walter has enough project context and source material to prepare owner review."}),e.jsx("div",{className:"mt-5 grid gap-3 sm:grid-cols-2",children:Wr.map(l=>{const d=r.find(f=>f.type===l.type),m=d?mo(d)&&i[l.type]:!1,p=l.icon;return e.jsxs("div",{className:"flex min-h-[172px] flex-col justify-between rounded-xl border border-grey-1 bg-grey-0 p-4 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-white text-primary shadow-sm dark:bg-grey-1",children:e.jsx(p,{size:18,"aria-hidden":"true"})}),e.jsx("span",{className:`rounded-full px-2.5 py-1 text-xs font-semibold ${m?"bg-green-50 text-green-700":"bg-grey-1 text-grey-5"}`,children:m?"Ready":"Waiting"})]}),e.jsxs("h3",{className:"mt-4 break-words font-primary text-base font-bold text-grey-7",children:[t," ",l.label]}),e.jsx("p",{className:"mt-1 text-sm leading-5 text-grey-5",children:l.description})]}),e.jsxs("button",{type:"button",onClick:()=>m?a(l.type):s(),disabled:!m,className:"mt-4 inline-flex items-center justify-center gap-2 rounded-full bg-primary px-3 py-2 text-sm font-semibold text-white transition hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:["Review & publish",e.jsx(zt,{size:14,"aria-hidden":"true"})]})]},l.type)})})]})}function Kl({criteria:t}){return e.jsxs("div",{className:"mt-4",children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Smart keepsakes coming soon"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-grey-5",children:"Walter will prepare Memory Album and Memory Reel starting points after the project has enough context."}),t.length>0&&e.jsx("div",{className:"mt-5 space-y-2",children:t.map((r,s)=>{const a=nl(r);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-grey-1 bg-grey-0 px-4 py-3 dark:border-grey-2 dark:bg-grey-2/40",children:[e.jsxs("span",{className:"flex items-center gap-3 text-sm font-medium text-grey-7",children:[e.jsx(cr,{size:17,className:r.met?"text-green-600":"text-grey-3","aria-hidden":"true"}),r.label]}),a&&e.jsx("span",{className:"text-xs font-semibold text-grey-4",children:a})]},r.key??r.label??s)})})]})}function ba({icon:t,title:r,body:s}){return e.jsxs("section",{className:"rounded-2xl border border-grey-1 bg-white p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-xl bg-primary-light text-primary",children:e.jsx(t,{size:18,"aria-hidden":"true"})}),e.jsx("h2",{className:"mt-4 font-primary text-base font-bold text-grey-7",children:r}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-grey-5",children:s})]})}function Gl({isOwner:t}){return e.jsxs("div",{className:t?"grid gap-5 lg:grid-cols-[minmax(0,1.85fr)_minmax(300px,1fr)]":"space-y-5",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"h-48 animate-pulse rounded-2xl bg-grey-1/70 dark:bg-grey-2/70"}),t&&e.jsx("div",{className:"h-40 animate-pulse rounded-2xl bg-grey-1/70 dark:bg-grey-2/70"})]}),t&&e.jsx("div",{className:"h-40 animate-pulse rounded-2xl bg-grey-1/70 dark:bg-grey-2/70"})]})}const ho=[{key:"information",label:"Info",icon:Ci},{key:"members",label:"Members",icon:Gr},{key:"sessions",label:"Sessions",icon:Zt},{key:"library",label:"Library",icon:st},{key:"collections",label:"Collections",icon:mr}],bo=[{key:"information",label:"Information",icon:or},{key:"members",label:"Members",icon:Gr},{key:"sessions",label:"Sessions",icon:kr},{key:"sources",label:"Sources",icon:br},{key:"library",label:"Library",icon:st},{key:"collections",label:"Collections",icon:Ko},{key:"keepsakes",label:"Keepsakes",icon:ki}],ql=new Set(ho.map(t=>t.key)),Wl=new Set(bo.map(t=>t.key));function Vl(t){return t.tab??"information"}function Hl(t,r){return(r?Wl:ql).has(t)}function Yl({libraryTabCount:t}){return{information:0,members:0,sessions:0,sources:0,library:t,collections:0,keepsakes:0}}function Ql(t,r,s,a,i,l){if(t==="owner"){const d=a?.ownerSetupCallCompleted===!0,m=new Set(i?.checkedChecklistItems??[]),p=i?.objectiveCompletions?.hasInvitedContributors===!0||(l?.contributors??0)>0,f=i?.objectiveCompletions?.hasUploadedSources===!0;return{title:"Owner checklist",items:[{key:"review_project_guide",label:"Review project guide",checked:m.has("review_project_guide")},{key:"invite_contributors",label:"Invite contributors",checked:m.has("invite_contributors")||p,objectiveComplete:p,action:"invite"}
4,{key:"schedule_owner_call",label:"Schedule owner call",checked:m.has("schedule_owner_call")||d,objectiveComplete:d,...s?.canScheduleCall&&!d?{action:"schedule",actionLabel:"Talk now",scheduleLaterLabel:"Schedule for later"}:{}},{key:"upload_sources",label:"Upload files",checked:m.has("upload_sources")||f,objectiveComplete:f,...s?.canUploadSource?{action:"upload"}:{}},{key:"track_calls_uploads_usage",label:"Track calls, uploads, usage",checked:m.has("track_calls_uploads_usage")},{key:"build_keepsakes",label:"Build the keepsakes",checked:m.has("build_keepsakes")}]}}if(t==="contributor"){const d=r==="capture_open";return{title:"Contributor checklist",items:[s?.canScheduleCall&&d?{label:"Schedule your Walter call",action:"schedule",actionLabel:"Schedule a call"}:{label:"Review the capture window status"},{label:"Review project guide"},s?.canUploadSource&&d?{label:"Share photos or files"}:{label:"Review finished stories and sources"},{label:"Walter can draft story pages after your call"}]}}return{title:"Viewer checklist",items:[{label:"Review project guide"},{label:"Browse finished stories after capture closes"},{label:"Use read-only access to follow the project"}]}}function Jl({group:t,memoryProjectMembership:r,search:s,currentMemberRole:a,hasContributorCallActivity:i}){const l=t.viewerRole??(t.isOwner?"owner":a??"viewer"),d=l==="viewer",m=!!r,p=r?.role==="contributor",f=r?.memoryProjectId,j=r?.phase,y=r?.capabilities,b=!m||!!y?.canUploadSource||j==="capture_open",g=r?.role??l,h=s.memoryProjectSetup==="owner"&&m&&l==="owner"&&!!f,x=p&&j==="capture_open"&&!!y?.canScheduleCall&&!i,S=s.memoryProjectWelcome==="contributor"&&x&&!!f,k=l==="owner"&&r?.usage?.ownerSetupCallCompleted===!0;return{currentRole:l,isViewer:d,isMemoryProjectGroup:m,isMemoryProjectContributor:p,canContributeToMemoryProject:b,memoryProjectRoleForLibrary:g,shouldShowOwnerSetupModal:h,shouldShowContributorPrompt:x,shouldShowContributorWelcomeModal:S,hasCompletedOwnerMemoryProjectSetup:k}}const rs={heart:"â¤ï¸",star:"â",users:"ð¥"},Xl=2*1024*1024,fa=Ao("/_app/$slug/groups/$groupId");function Zl(t){if(typeof t=="object"&&t!==null&&"storageId"in t&&typeof t.storageId=="string")return{storageId:t.storageId};throw new Error("Upload response missing storage ID")}const ed=new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric"}),td=new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}),rd={moment:"Moment",milestone:"Milestone",era:"Era"};function va(t){return t?ed.format(new Date(t)):null}function sd(t){return t?td.format(new Date(t)):null}function ad(t,r){const s=va(t),a=va(r);return s&&a?`${s} - ${a}`:s??a??"Not set"}function od(t){return t?rd[t]??t.replace(/[-_]/g," ").replace(/\b\w/g,r=>r.toUpperCase()):"Memory Project"}function id(t){return t?`Deadline ${Or(t,{exclusive:!0})}`:"Deadline not set"}function nd(t){return t==null?"0":Number.isInteger(t)?`${t}`:t.toFixed(1)}function ld(t){if(!t)return null;const r=1440*60*1e3;return Math.max(0,Math.ceil((t-Date.now())/r))}function dd({role:t,summary:r,ownerExperienceState:s,onScheduleCall:a,onStartCall:i,onInviteContributors:l,onUploadSources:d,onToggleChecklistItem:m}){const p=r.usage,f=r.plan,j=r.capabilities,y=ld(r.captureWindowEndsAt),b=Ql(t,r.phase,j,p,s,r.counts),g=t==="owner"&&r.capabilities?.canViewUsage&&p,h=g?[{label:"Min included",value:p.includedInterviewMinutes??f?.includedInterviewMinutes??0},{label:"Min used",value:p.usedCompletedCallMinutes??0},{label:"Min scheduled",value:p.scheduledEstimatedCallMinutes??0},{label:"Min remaining",value:p.remainingIncludedCallMinutes??0}]:[];return e.jsxs("aside",{className:"space-y-5",children:[e.jsxs("section",{className:"rounded-lg border border-grey-2 bg-white p-5 shadow-sm dark:border-transparent dark:bg-grey-1",children:[e.jsx("h2",{className:"font-primary text-xl font-bold leading-tight text-grey-7",children:b.title}),e.jsx("div",{className:"mt-4 grid gap-2",children:b.items.map(x=>e.jsxs("div",{className:"rounded-lg bg-grey-0 px-3 py-2 text-sm text-grey-6 dark:bg-grey-2",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[x.key?e.jsx("input",{type:"checkbox","aria-label":x.label,checked:x.checked===!0,disabled:x.objectiveComplete===!0,onChange:S=>m?.(x.key,S.currentTarget.checked),className:"mt-0.5 h-4 w-4 shrink-0 rounded border-grey-2 text-primary focus:ring-primary/30 disabled:cursor-default disabled:opacity-70"}):e.jsx(cr,{size:16,className:"mt-0.5 shrink-0 text-primary","aria-hidden":"true"}),e.jsx("span",{className:x.checked?"font-medium text-grey-7":void 0,children:x.label})]}),x.action==="schedule"&&e.jsxs("div",{className:"mt-3 grid gap-2",children:[e.jsxs("button",{type:"button",onClick:i,className:"inline-flex w-full items-center justify-center gap-2 rounded-lg bg-memory-cta px-4 py-2 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 dark:bg-grey-3 dark:text-white dark:hover:bg-grey-4",children:[e.jsx(kr,{size:16,"aria-hidden":"true"}),x.actionLabel??"Talk now"]}),e.jsxs("button",{type:"button",onClick:a,className:"inline-flex w-full items-center justify-center gap-2 rounded-lg border border-grey-2 bg-white px-4 py-2 text-sm font-semibold text-grey-7 shadow-sm transition-colors hover:bg-grey-1 dark:border-transparent dark:bg-grey-2 dark:text-white dark:hover:bg-grey-3",children:[e.jsx(Zt,{size:16,"aria-hidden":"true"}),x.scheduleLaterLabel??"Schedule a call"]})]}),x.action==="invite"&&e.jsxs("button",{type:"button",onClick:l,className:"mt-3 inline-flex w-full items-center justify-center gap-2 rounded-lg bg-memory-cta px-4 py-2 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 dark:bg-grey-3 dark:text-white dark:hover:bg-grey-4",children:[e.jsx(sr,{size:16,"aria-hidden":"true"}),"Invite contributors"]}),x.action==="upload"&&e.jsxs("button",{type:"button",onClick:d,className:"mt-3 inline-flex w-full items-center justify-center gap-2 rounded-lg bg-memory-cta px-4 py-2 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 dark:bg-grey-3 dark:text-white dark:hover:bg-grey-4",children:[e.jsx(br,{size:16,"aria-hidden":"true"}),"Upload files"]})]},x.label))}),e.jsxs("div",{className:"mt-5 border-t border-grey-1 pt-4 dark:border-grey-2",children:[e.jsx("h3",{className:"text-[11px] font-bold uppercase tracking-wide text-grey-4",children:"Project timing"}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-1",children:[e.jsxs("div",{className:"rounded-lg bg-grey-0 p-3 dark:bg-grey-2",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wide text-grey-4",children:"Phase"}),e.jsx("p",{className:"mt-1 text-sm font-bold text-grey-7",children:r.phase?Sa[r.phase]:"Memory Project"}),e.jsx("p",{className:"mt-1 text-xs text-grey-5",children:y===null?"Capture dates are not set":y===0?"Capture deadline reached":`${y} days left`})]}),e.jsxs("div",{className:"rounded-lg bg-grey-0 p-3 dark:bg-grey-2",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wide text-grey-4",children:"Capture window"}),e.jsx("p",{className:"mt-1 text-sm font-bold text-grey-7",children:ad(r.captureWindowStartsAt,r.captureWindowEndsAt)}),e.jsx("p",{className:"mt-1 text-xs text-grey-5",children:"Calls and uploads follow this window"})]}),e.jsxs("div",{className:"rounded-lg bg-grey-0 p-3 dark:bg-grey-2",children:[e.jsx("p",{className:"text-[11px] font-bold uppercase tracking-wide text-grey-4",children:"Storage window"}),e.jsx("p",{className:"mt-1 text-sm font-bold text-grey-7",children:r.storageExpiresAt?`V
4ault through ${sd(r.storageExpiresAt)}`:"Not set"}),e.jsx("p",{className:"mt-1 text-xs text-grey-5",children:"Library and keepsake files stay available."})]})]})]})]}),g&&e.jsxs("section",{className:"rounded-lg border border-grey-2 bg-white p-5 shadow-sm dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(bs,{size:17,className:"text-primary","aria-hidden":"true"}),e.jsx("h2",{className:"text-sm font-bold uppercase tracking-wide text-grey-7",children:"Usage"})]}),e.jsx("div",{className:"mt-4 grid grid-cols-2 gap-3",children:h.map(x=>e.jsxs("div",{className:"rounded-lg bg-grey-2 p-4 text-grey-7 dark:bg-grey-2",children:[e.jsx("div",{className:"text-2xl font-bold leading-none",children:nd(x.value)}),e.jsx("div",{className:"mt-2 text-[11px] font-bold uppercase tracking-wide text-grey-6",children:x.label})]},x.label))})]})]})}function fo(t){return(t.counts?.contributors??0)<2}function cd({groupName:t,summary:r,onInviteContributors:s,onOpenInviteLinks:a,onDismiss:i}){const l=fo(r),d=r.plan?.contributorLimit,m=r.counts?.contributors??0,p=r.capabilities?.canManageInviteLinks!==!1,f=d!=null?`${m} of ${d} contributor spots filled`:`${m} contributors invited`;return e.jsxs("section",{"data-testid":"memory-project-setup-complete",className:"relative w-full rounded-lg border border-memory/20 bg-white p-5 shadow-sm dark:border-transparent dark:bg-grey-1 sm:p-6",children:[e.jsx("button",{type:"button",onClick:i,"aria-label":"Dismiss setup complete invite prompt",className:"absolute right-3 top-3 inline-flex h-8 w-8 items-center justify-center rounded-full text-grey-4 transition-colors hover:bg-grey-0 hover:text-grey-7 dark:hover:bg-grey-2",children:e.jsx(fe,{size:16,"aria-hidden":"true"})}),e.jsxs("div",{className:"grid gap-5 pr-8 md:grid-cols-[minmax(0,1fr)_auto] md:items-center",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-md bg-primary-light px-3 py-1 text-xs font-semibold text-primary",children:[e.jsx(vt,{size:14,"aria-hidden":"true"}),"Setup complete"]}),e.jsx("h2",{className:"mt-3 font-primary text-xl font-bold leading-tight text-grey-7",children:"Invite contributors to add their stories"}),e.jsxs("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-grey-5",children:["Share the invite link or invite people by email so they can schedule Walter calls, upload sources, and help fill out ",t,"."]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2 text-xs font-semibold text-grey-5",children:[e.jsx("span",{className:"rounded-md bg-grey-0 px-2.5 py-1 dark:bg-grey-2",children:f}),l&&e.jsx("span",{className:"rounded-md bg-memory/10 px-2.5 py-1 text-memory dark:bg-grey-2 dark:text-grey-6",children:"Invite contributors next"})]})]}),e.jsxs("div",{className:"flex w-full shrink-0 flex-col gap-2 sm:flex-row md:w-auto md:flex-col lg:flex-row",children:[p&&e.jsxs("button",{type:"button",onClick:a,className:"inline-flex w-full items-center justify-center gap-2 rounded-lg bg-memory-cta px-4 py-3 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-memory-cta/90 sm:w-auto dark:bg-grey-3 dark:text-white dark:hover:bg-grey-4",children:[e.jsx(as,{size:17,"aria-hidden":"true"}),"Share invite link"]}),e.jsxs("button",{type:"button",onClick:s,className:"inline-flex w-full items-center justify-center gap-2 rounded-lg border border-grey-2 bg-white px-4 py-3 text-sm font-semibold text-grey-6 transition-colors hover:bg-grey-0 sm:w-auto dark:border-transparent dark:bg-grey-2 dark:text-grey-7 dark:hover:bg-grey-3",children:[e.jsx(sr,{size:17,"aria-hidden":"true"}),"Invite contributors by email"]})]})]})]})}function md({groupName:t,currentRole:r,memoryProjectId:s,memoryProjectRole:a,summary:i,ownerExperienceState:l,guideEditRequestKey:d,onScheduleCall:m,onStartCall:p,onInviteContributors:f,onOpenInviteLinks:j,onDismissSetupGuidance:y,onDismissSetupCompleteInvite:b,onToggleChecklistItem:g,onUploadSources:h}){const x=a==="owner"&&i.usage?.ownerSetupCallCompleted===!0&&fo(i)&&i.capabilities?.canEnableContributorLink===!0&&l!==void 0&&l?.dismissedSetupCompleteInvite!==!0;return e.jsxs("div",{className:"space-y-5",children:[x&&e.jsx(cd,{groupName:t,summary:i,onInviteContributors:f,onOpenInviteLinks:j,onDismiss:b}),e.jsxs("div",{className:"grid gap-5 lg:grid-cols-[minmax(0,1.45fr)_minmax(320px,0.75fr)] lg:items-start",children:[e.jsx("div",{className:"space-y-5",children:e.jsx(zn,{memoryProjectId:s,groupName:t,role:r,openEditorRequestKe
4y:d,isSetupGuidanceDismissed:l?.dismissedSetupGuidance===!0,onDismissSetupGuidance:y})}),e.jsx(dd,{role:a,summary:i,ownerExperienceState:l,onScheduleCall:m,onStartCall:p,onInviteContributors:f,onUploadSources:h,onToggleChecklistItem:g})]})]})}function ud({groupName:t,onClose:r,onCompleteManually:s,onStartKickoff:a,onScheduleKickoff:i}){const l=o.useRef(null),d=o.useRef(null),m=[{title:"Tell Walter what this project is for",description:"Use the kickoff call to explain the project goal, the people involved, and what should be collected."},{title:"Review the first project guide",description:"Walter can draft the project description, suggested topics, and source gaps from your setup call."},{title:"Invite contributors when you are ready",description:"After the guide feels right, share the Contributor link so people know what to add."}];return o.useEffect(()=>{const p=l.current;if(p)return p.open||p.showModal(),d.current?.focus({preventScroll:!0}),()=>{p.open&&p.close()}},[]),e.jsx(F.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"pointer-events-none fixed inset-0 z-50",children:e.jsx("dialog",{ref:l,className:"pointer-events-auto fixed inset-0 z-50 m-0 flex h-full w-full max-w-none items-center justify-center border-0 bg-transparent p-4 backdrop:bg-black/40 backdrop:backdrop-blur-sm","aria-labelledby":"memory-project-owner-setup-title","aria-modal":"true",onCancel:p=>{p.preventDefault(),r()},children:e.jsxs("section",{className:"w-full max-w-3xl overflow-hidden rounded-3xl bg-white shadow-2xl dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 p-6 sm:p-8",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-primary/20 bg-primary-light px-3 py-1 text-sm font-semibold text-primary",children:[e.jsx($o,{size:16,"aria-hidden":"true"}),"Project created"]}),e.jsx("h2",{id:"memory-project-owner-setup-title",className:"mt-4 font-primary text-3xl font-bold leading-tight text-grey-7",children:"Start building your Memory Project"}),e.jsx("p",{className:"mt-4 max-w-2xl text-base leading-relaxed text-grey-5",children:"Before inviting people in, you can schedule a short Walter kickoff so Walter understands the project goal, the people involved, and the memories you want to collect. You can also complete the Memory Project guide manually."})]}),e.jsx("button",{type:"button",onClick:r,className:"rounded-full p-2 text-grey-4 transition-colors hover:bg-grey-1 hover:text-grey-7 dark:hover:bg-grey-2","aria-label":`Close ${t} setup`,children:e.jsx(fe,{size:22})})]}),e.jsx("div",{className:"border-y border-grey-1 p-6 dark:border-grey-2 sm:p-8",children:e.jsxs("div",{className:"rounded-2xl border border-grey-1 p-5 dark:border-grey-2",children:[e.jsx("h3",{className:"font-primary text-lg font-bold text-grey-7",children:"Recommended setup path"}),e.jsx("div",{className:"mt-4 space-y-3",children:m.map(p=>e.jsxs("div",{className:"flex gap-4 rounded-2xl border border-grey-1 p-4 dark:border-grey-2",children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-full bg-primary-light text-primary",children:e.jsx(vt,{size:18,"aria-hidden":"true"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-grey-7",children:p.title}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-grey-5",children:p.description})]})]},p.title))})]})}),e.jsxs("div",{className:"flex flex-col-reverse justify-end gap-3 p-6 sm:flex-row sm:p-8",children:[e.jsx("button",{type:"button",onClick:s,className:"inline-flex items-center justify-center rounded-full border border-grey-2 px-5 py-3 text-sm font-semibold text-grey-7 transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:"Complete manually"}),e.jsxs("button",{ref:d,type:"button",onClick:a,className:"inline-flex items-center justify-center gap-2 rounded-full bg-primary px-5 py-3 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-primary/90",children:[e.jsx(kr,{size:18,"aria-hidden":"true"}),"Talk now"]}),e.jsxs("button",{type:"button",onClick:i,className:"inline-flex items-center justify-center gap-2 rounded-full border border-grey-2 px-5 py-3 text-sm font-semibold text-grey-7 transition-colors hover:bg-grey-1 dark:hover:bg-grey-2",children:[e.jsx(Zt,{size:18,"aria-hidden":"true"}),"Schedule for later"]})]})]})})})}
4function xd(t){const r=new URL(`/${t.slug}/groups/${t.groupId}`,t.origin);r.searchParams.set("tab","information");const s=new URL(r);return s.searchParams.set("memoryProjectSetup","owner"),s.searchParams.set("session_id","{CHECKOUT_SESSION_ID}"),{successUrl:zs(s.toString(),{result:"success",surface:"memory_project_checkout",productType:t.plan.productType,plan:t.plan.name,planFrequency:t.plan.planFrequency}),cancelUrl:zs(r.toString(),{result:"cancel",surface:"memory_project_checkout",productType:t.plan.productType,plan:t.plan.name,planFrequency:t.plan.planFrequency})}}function pd({options:t,checkoutInFlightPlanCode:r,onStartCheckout:s}){return t.length===0?null:e.jsxs("section",{className:"rounded-2xl border border-memory/20 bg-white p-5 dark:border-transparent dark:bg-grey-1 sm:p-6",children:[e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-primary-light px-3 py-1 text-xs font-semibold text-primary",children:[e.jsx(pt,{size:14,"aria-hidden":"true"}),"Add a Memory Project"]}),e.jsx("h2",{className:"mt-3 font-primary text-xl font-bold text-grey-7",children:"Upgrade this group"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-grey-5",children:"Keep the members and shared content here, then add Memory Project setup, contributor capture, and vault storage after checkout."})]}),e.jsxs("div",{className:"flex items-center gap-2 rounded-xl bg-grey-0 px-3 py-2 text-xs font-semibold text-grey-5 dark:bg-grey-2",children:[e.jsx(Ls,{size:15,"aria-hidden":"true"}),"One-time add-on"]})]}),e.jsx("div",{className:"mt-5 grid gap-3 md:grid-cols-3",children:t.map(a=>{const i=r===a.planCode;return e.jsxs("div",{className:"rounded-xl border border-grey-1 p-4 dark:border-grey-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-primary text-base font-bold text-grey-7",children:a.name}),e.jsxs("p",{className:"mt-1 text-sm font-semibold text-grey-6",children:[a.price," ",e.jsx("span",{className:"text-xs font-medium text-grey-4",children:a.priceSuffix})]})]}),a.popular&&e.jsx("span",{className:"rounded-full bg-primary-light px-2 py-1 text-[11px] font-semibold text-primary",children:"Popular"})]}),e.jsx("p",{className:"mt-3 line-clamp-2 text-sm leading-5 text-grey-5",children:a.description}),e.jsxs("button",{type:"button",onClick:()=>s(a),disabled:r!==null||!a.checkoutEligible,className:"mt-4 inline-flex w-full items-center justify-center gap-2 rounded-full bg-primary px-4 py-2 text-sm font-semibold text-white shadow-sm transition-colors hover:bg-primary/90 disabled:cursor-not-allowed disabled:bg-grey-2 disabled:text-grey-4",children:[i?e.jsx(Xe,{size:16,className:"animate-spin","aria-hidden":"true"}):e.jsx(Ls,{size:16,"aria-hidden":"true"}),i?"Starting...":"Start checkout"]})]},`${a.productType}:${a.planCode}`)})})]})}function gd(){const{slug:t,groupId:r}=fa.useParams(),s=fa.useSearch(),a=Ro(),{GROUPS:i,PAGES:l=[],isLoading:d}=Kr(),{user:m}=hs(),p=o.useRef(null),[f,j]=o.useState(!1),[y,b]=o.useState(null),[g,h]=o.use
4State(null),[x,S]=o.useState(!0),k=o.useRef(null),N=o.useRef(r),P=o.useRef(null),[w,U]=o.useState(0),[q,K]=o.useState(null),[Z,E]=o.useState(!1),B=Eo(O.billingActions.createCatalogCheckoutSession),le=ne(O.files.generateUploadUrl),$=ne(O.groups.updateCoverImage),X=ne(O.groups.update),G=ne(O.groups.leave),ae=ne(O.groups.remove),ee=!r.startsWith("group-"),Q=i.find(R=>R.id===r),M=be(O.groups.getForCurrentUser,ee&&!Q?{groupId:r}:"skip"),_=M?_o(M):void 0,T=Q??_??zo(r),z=ee&&!Q&&M===void 0,C=be(O.groups.getPendingInvites,ee?{groupId:r}:"skip")??[],L=O,H=!!L.memoryProjects?.getActiveMemoryProjectMembershipByGroup,v=!!L.memoryProjects?.getOwnerExperienceState,D=!!L.scheduledCalls?.listByMemoryProject,se=!!L.calls?.listByMemoryProject,de=L.memoryProjects?.getActiveMemoryProjectMembershipByGroup??"memoryProjects.getActiveMemoryProjectMembershipByGroup",ze=L.memoryProjects?.getOwnerExperienceState??"memoryProjects.getOwnerExperienceState",ke=ne(L.memoryProjects?.updateOwnerExperienceState??"memoryProjects.updateOwnerExperienceState"),Pe=L.scheduledCalls?.listByMemoryProject??"scheduledCalls.listByMemoryProject",Ne=L.calls?.listByMemoryProject??"calls.listByMemoryProject",ce=be(de,H&&ee?{groupId:r}:"skip"),oe=H&&ee&&ce===void 0,te=H?ce:null,re=te?.memoryProjectId,me=te?.role,Ce=be(ze,v&&me==="owner"&&re?{memoryProjectId:re}:"skip"),he=v?Ce:null,c=me==="contributor"&&!!re,Y=be(Pe,D&&c?{memoryProjectId:re}:"skip"),ie=be(Ne,se&&c?{memoryProjectId:re}:"skip"),ue=!!T?.isOwner&&ee&&te===null,Se=be(O.pricingCatalog.getLaunchPricingCatalogForCurrentUser,ue?{}:"skip"),Ee=be(O.groups.listSharedPages,te?.memoryProjectId&&T?.id?{groupId:T.id,limit:200}:"skip"),Ke=o.useMemo(()=>Array.isArray(Se?.memoryProjects)?Go(Se.memoryProjects):[],[Se]),Me=Vl(s);o.useEffect(()=>()=>{y&&URL.revokeObjectURL(y)},[y]),o.useEffect(()=>{N.current!==r&&(N.current=r,b(null),j(!1),h(null),E(!1),k.current&&(clearTimeout(k.current),k.current=null))},[r]),o.useEffect(()=>()=>{k.current&&clearTimeout(k.current)},[]),o.useEffect(()=>{if(typeof window>"u")return;const R=new URLSearchParams(window.location.search).get("tab");!R||te===void 0||Hl(R,!!te)||a({to:".",search:Ie=>({...Ie,tab:"information"}),replace:!0})},[te,a]);const[Nt,He]=o.useState(!1),[tt,Oe]=o.useState(""),[ct,Ye]=o.useState(""),[ot,Ve]=o.useState(!1),Qe=o.useRef(null),[Dt,Le]=o.useState(!1),[Ze,jt]=o.useState(""),[Ct,St]=o.useState(0),[De,rt]=o.useState(0);o.useEffect(()=>{function R(Ie){Qe.current&&!Qe.current.contains(Ie.target)&&Ve(!1)}if(ot)return document.addEventListener("mousedown",R),()=>document.removeEventListener("mousedown",R)},[ot]);const Fe=R=>{k.current&&clearTimeout(k.current),h(R),k.current=setTimeout(()=>{h(null),k.current=null},3e3)},yt=async R=>{if(!T?.isOwner||We||q)return;if(!R.checkoutEligible){Uo({contactId:m?.id,surface:"memory_project_checkout",context:"memory_project_checkout",productType:R.productType,plan:R.name,planFrequency:R.planFrequency,groupId:r,reason:"price_id_missing"}),Fe(`${R.name} is not available right now. Please choose another Memory Project plan.`);return}K(R.planCode);const Ie={contactId:m?.id,surface:"memory_project_checkout",context:"memory_project_checkout",productType:R.productType,plan:R.name,planFrequency:R.planFrequency,groupId:r};Lo(Ie);try{const Be=typeof window>"u"?"https://app.autograph.ai":window.location.origin,{successUrl:Mt,cancelUrl:Xr}=xd({origin:Be,slug:t,groupId:r,plan:R});Fo(Ie);const{url:Ss}=await B({productType:R.productType,planCode:R.planCode,groupId:r,successUrl:Mt,cancelUrl:Xr});Ss?window.location.href=Ss:(_s({...Ie,reason:"missing_checkout_url"}),Fe("Could not start checkout. Please try again."))}catch(Be){_s({...Ie,reason:"checkout_action_rejected"}),console.error("Memory Project group checkout error:",Be),Fe("Checkout failed. Please try again.")}finally{K(null)}},V=async R=>{if(!m?.id||!T?.id)return;if(R.size>Xl){Fe("Cover photo must be under 2MB");return}j(!0);const Ie=URL.createObjectURL(R);b(Ie);try{const Be=await le(),Mt=await fetch(Be,{method:"POST",headers:{"Content-Type":R.type},body:R});if(!Mt.ok)throw new Error("Upload failed");const{storageId:Xr}=Zl(await Mt.json());await $({groupId:T.id,coverImageStorageId:Xr})}catch(Be){console.error("Cover upload failed:",Be),URL.revokeObjectURL(Ie),b(null),Fe("Failed to upload cover photo")}finally{j(!1)}};if(!T)return d||z?e.jsxs("div",{className:"mx-auto max-w-2xl space-y-8 animate-pulse",children:[e.jsx("div",{className:"h-4 w-12 rounded bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"-mx-4 sm:-mx-0 h-[120px] rounded-2xl bg-grey-1 dark:bg-grey-2"}),e.jsxs("div",{className:"flex items-start gap-5 pt-3",children:[e.jsx("div",{className:"h-16 w-16 rounded-2xl bg-grey-1 dark:bg-grey-2"}),e.jsxs("div",{className:"flex-1 space-y-2 pt-2",children:[e.jsx("div",{className:"h-6 w-48 rounded bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"h-4 w-24 rounded bg-grey-1 dark:bg-grey-2"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-20 rounded bg-grey-1 dark:bg-grey-2"}),e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-grey-1 dark:border-transparent px-4 py-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"h-4 w-32 rounded bg-grey-1 dark:bg-grey-2"})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-xl border border-grey-1 dark:border-transparent px-4 py-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"h-4 w-28 rounded bg-grey-1 dark:bg-grey-2"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-4 w-28 rounded bg-grey-1 dark:bg-grey-2"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx("div",{className:"h-24 rounded-xl border border-grey-1 dark:border-transparent bg-grey-1/30 dark:bg-grey-2/30"}),e.jsx("div",{className:"h-24 rounded-xl border border-grey-1 dark:border-transparent bg-grey-1/30 dark:bg-grey-2/30"})]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-center",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-2xl bg-grey-1 text-grey-5 dark:bg-grey-2",children:e.jsx(Us,{size:20,"aria-hidden":"true"})}),e.jsx("h2",{className:"mt-4 font-primary text-xl font-bold text-grey-7",children:"Group unavailable"}),e.jsx("p",{className:"mt-2 max-w-sm text-sm leading-6 text-grey-5",children:"You may no longer have access to this group, or the group may no longer be available."}),e.jsx(Et,{to:"/$slug/library",params:{slug:t},search:{collections:"open"},className:"mt-4 text-sm font-medium text-primary",children:"Back to Library"})]});const pe=ct||rs[T.emoji]||T.emoji||"ð¥",ye=Nt?tt:T.name,Ge=T.sharedPages??(T.sharedPageIds??[]).map(R=>{const Ie=l.find(Be=>Be.id===R);return{id:R,title:Ie?.title??"Untitled page",preview:Ie?.preview??"",updatedAt:Ie?.updatedAt??""}}),ht=T.members.filter(R=>!R.inviteStatus||R.inviteStatus==="accepted"),je=ht.find(R=>R.email?.toLowerCase()===m?.email?.toLowerCase()),ve=te?.memoryProjectId,At=te?.phase,qt=te?.captureWindowStartsAt,qe=te?.captureWindowEndsAt,et=te,$t=!v||me!=="owner"||he!==void 0,Wt=Z||he?.dismissedMembersInvitePrompt===!0,Ut=Y??[],ur=ie??[],xr=Ut.length>0||ur.length>0,{currentRole:bt,isViewer:It,isMemoryProjectGroup:We,isMemoryProjectContributor:pr,canContributeToMemoryProject:Je,memoryProjectRoleForLibrary:Pt,shouldShowOwnerSetupModal:gr,shouldShowContributorPrompt:Vt,shouldShowContributorWelcomeModal:Ht,hasCompletedOwnerMemoryProjectSetup:Lt}=Jl({group:T,memoryProjectMembership:te,search:s,currentMemberRole:je?.role,hasContributorCallActivity:xr}),wt=We?At:void 0,tr=We&&Ee!==void 0?Ee.length:Ge.length,ut=C.map(R=>
4{const Ie=R.name??R.email??"??",Be=Ie.split(" "),Mt=Be.length>=2?(Be[0][0]+Be[1][0]).toUpperCase():Ie.substring(0,2).toUpperCase();return{id:R.id,name:Ie,initials:Mt,avatarColor:"bg-grey-4",inviteStatus:"pending",email:R.email,role:R.role}}),u=Yl({libraryTabCount:tr}),A=R=>{a({to:".",search:Ie=>({...Ie,tab:R}),replace:!0})},ge=()=>{a({to:".",search:R=>({...R,tab:"information",memoryProjectSetup:void 0}),replace:!0})},we=()=>{a({to:".",search:R=>({...R,memoryProjectWelcome:void 0}),replace:!0})},xe=()=>{a({to:".",search:R=>({...R,tab:"information",memoryProjectSetup:void 0}),replace:!0}),U(R=>R+1)},Te=()=>{ve&&a({to:"/sessions/schedule",search:{destination:"memoryProject",callIntent:"memoryProjectSetup",groupId:r,memoryProjectId:ve,...je?.contactId?{storytellerId:je.contactId}:{}}})},Ae=()=>{ve&&Ds({skipUpsell:!0,surface:"memory_project",storytellerId:je?.contactId,storytellerName:je?.name,callContext:{destination:"memoryProject",callIntent:"memoryProjectSetup",groupId:r,memoryProjectId:ve}})},it=()=>{ve&&a({to:"/sessions/schedule",search:{destination:"memoryProject",groupId:r,memoryProjectId:ve,...je?.contactId?{storytellerId:je.contactId}:{}}})},_e=()=>{ve&&Ds({skipUpsell:!0,surface:"memory_project",storytellerId:je?.contactId,storytellerName:je?.name,callContext:{destination:"memoryProject",callIntent:"contributorAsk",groupId:r,memoryProjectId:ve,...je?.contactId?{contributorContactId:je.contactId}:{}}})},Yt=()=>{T.isOwner&&(St(R=>R+1),A("members"))},Hr=()=>{T.isOwner&&(rt(R=>R+1),A("members"))},Yr=async()=>{if(ve)try{await ke({memoryProjectId:ve,dismissedSetupGuidance:!0,includeObjectiveCompletions:!1})}catch(R){console.error("Failed to dismiss Memory Project setup guidance:",R),Fe("Could not update setup guidance. Please try again.")}},n=async()=>{if(ve)try{await ke({memoryProjectId:ve,dismissedSetupCompleteInvite:!0,includeObjectiveCompletions:!1})}catch(R){console.error("Failed to dismiss Memory Project invite prompt:",R),Fe("Could not dismiss invite prompt. Please try again.")}},I=async()=>{if(ve){E(!0);try{await ke({memoryProjectId:ve,dismissedMembersInvitePrompt:!0,includeObjectiveCompletions:!1})}catch(R){console.error("Failed to dismiss Memory Project members invite prompt:",R),E(!1),Fe("Could not update invite reminder. Please try again.")}}},J=async(R,Ie)=>{if(ve)try{await ke({memoryProjectId:ve,checklistItemKey:R,checked:Ie})}catch(Be){console.error("Failed to update Memory Project checklist:",Be),Fe("Could not update checklist. Please try again.")}},W=()=>{A("sources")},$e=async()=>{if(!P.current){P.current="leave";try{await G({groupId:r}),a({to:"/$slug",params:{slug:t}})}catch(R){throw console.error("Failed to leave group:",R),Fe("Failed to leave group. Please try again."),R}finally{P.current=null}}},Ft=async()=>{if(!P.current){P.current="delete";try{await ae({groupId:r}),a({to:"/$slug",params:{slug:t}})}catch(R){throw console.error("Failed to delete group:",R),Fe("Failed to delete group. Please try again."),R}finally{P.current=null}}},Ot=()=>{T.isOwner&&(Oe(T.name),Ye(rs[T.emoji]||T.emoji||"ð¥"),He(!0))},Re=()=>{He(!1),Oe(""),Ye(""),Ve(!1)},Qr=()=>{if(!T.isOwner)return;const R={};if(tt.trim()&&(R.name=tt.trim()),ct){const Ie=Object.entries(rs).find(([,Be])=>Be===ct)?.[0];R.emoji=Ie||ct}X({groupId:T.id,...R}),He(!1),Ve(!1)},Cr=()=>{T.isOwner&&(jt(T.description??""),Le(!0))},Ns=async()=>{if(!T.isOwner)return;const R=Ze.trim();await X({groupId:T.id,description:R}),Le(!1)},Cs=et?.plan?.planCode??null,vo=ye,jo=Cs?od(Cs):"Milestone",wo=id(qe),Jr=We&&et?{activeTab:Me,tabs:bo.map(R=>({...R,count:u[R.key]})),onTabChange:R=>A(R),title:vo,chips:Array.from(new Set(["Memory Project",jo,Sa[At??"capture_open"]??"Memory Project",wo]))}:void 0,Qt=Jr?{id:`memory-project-panel-${Me}`,role:"tabpanel","aria-labelledby":`memory-project-tab-${Me}`,tabIndex:0}:{};return e.jsxs(Do,{children:[e.jsxs(lt,{children:[gr&&e.jsx(ud,{groupName:T.name,onClose:ge,onCompleteManually:xe,onStartKickoff:()=>{ge(),Ae()},onScheduleKickoff:Te}),Ht&&e.jsx(An,{groupName:T.name,onClose:we,onStartCall:()=>{we(),_e()},onScheduleCall:it}),g&&e.jsxs(F.div,{initial:{opacity:0,y:-12}
4,animate:{opacity:1,y:0},exit:{opacity:0,y:-12},className:"fixed top-4 right-4 z-50 flex items-center gap-2 rounded-xl bg-grey-7 px-4 py-3 text-sm font-medium text-white shadow-lg dark:bg-grey-1 dark:text-grey-7",role:"alert",children:[e.jsx(ss,{size:16,className:"text-amber-300"}),g]},g)]}),e.jsxs("div",{className:"mx-auto max-w-6xl space-y-8",children:[e.jsx(F.div,{variants:Ue,children:e.jsxs(F.button,{type:"button",whileHover:{x:-3},whileTap:{scale:.95},onClick:()=>window.history.back(),className:"inline-flex items-center gap-2 text-sm font-medium text-grey-5 transition-colors hover:text-grey-7",children:[e.jsx(ir,{size:16}),"Back"]})}),oe?e.jsx(F.div,{variants:Ue,"data-testid":"memory-project-header-loading","aria-label":"Loading group header",className:"-mx-4 min-h-[240px] rounded-t-none border-t border-grey-2 bg-grey-1 p-5 shadow-sm dark:border-grey-2 dark:bg-grey-1 sm:mx-0 sm:rounded-t-lg sm:border-x sm:p-8",children:e.jsxs("div",{className:"flex h-full min-h-[200px] flex-col justify-end",children:[e.jsxs("div",{className:"mb-4 flex gap-2",children:[e.jsx("div",{className:"h-7 w-20 animate-pulse rounded-md bg-white/60 dark:bg-grey-2"}),e.jsx("div",{className:"h-7 w-28 animate-pulse rounded-md bg-white/60 dark:bg-grey-2"})]}),e.jsx("div",{className:"h-12 w-2/3 max-w-xl animate-pulse rounded-lg bg-white/70 dark:bg-grey-2"})]})}):e.jsx(Ri,{group:T,coverPreview:y,coverUploading:f,coverInputRef:p,handleCoverUpload:V,currentEmoji:pe,currentName:ye,isEditingName:Nt,editName:tt,setEditName:Oe,editEmoji:ct,setEditEmoji:Ye,showEmojiPicker:ot,setShowEmojiPicker:Ve,emojiPickerRef:Qe,startEditing:Ot,cancelEditing:Re,saveEditing:Qr,acceptedMembers:ht,pendingMembersFromBackend:ut,isOwner:!!T.isOwner,notificationsOn:x,onToggleNotifications:()=>S(R=>!R),onDeleteGroup:Ft,onLeaveGroup:$e,memoryProjectHeader:Jr}),!Jr&&!oe&&e.jsx("nav",{className:"flex flex-wrap items-center gap-2",children:ho.map(R=>{const Ie=R.icon,Be=Me===R.key,Mt=u[R.key];return e.jsxs("button",{type:"button",onClick:()=>A(R.key),className:`inline-flex items-center gap-2 rounded-full px-3 py-2 text-sm font-medium transition-colors ${Be?"bg-grey-1 text-grey-7 dark:bg-grey-2":"text-grey-4 hover:bg-grey-1 hover:text-grey-6 dark:hover:bg-grey-2"}`,children:[e.jsx(Ie,{size:16}),R.label,Mt>0&&e.jsx("span",{className:"rounded-full bg-primary-light px-1.5 py-0.5 text-[10px] font-semibold text-primary",children:Mt})]},R.key)})}),Vt&&e.jsx(Dn,{captureWindowEndsAtLabel:qe?Or(qe,{exclusive:!0}):null,onStartCall:_e,onScheduleCall:it}),!oe&&!Lt&&ht.length<=1&&Ge.length===0&&Me!=="sessions"&&Me!=="keepsakes"&&e.jsxs(F.div,{variants:Ue,className:"rounded-2xl border-2 border-dashed border-primary/20 bg-primary-light p-6 text-center",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-2xl bg-primary/10",children:e.jsx(sr,{size:24,className:"text-primary"})}),e.jsxs("h3",{className:"mt-4 font-primary text-lg font-bold text-grey-7",children:["Welcome to ",T.name,"!"]}),e.jsx("p",{className:"mt-2 text-sm leading-relaxed text-grey-5",children:We?"Invite contributors so they can schedule Walter calls and upload sources for this Memory Project. Story pages will appear in the Project Library as Walter captures them.":"Groups let you share stories with the people who matter. Start by inviting family members, then add pages to the Library."}),T.isOwner&&e.jsxs(F.button,{type:"button",whileHover:{scale:1.02},whileTap:{scale:.98},onClick:Yt,className:"mt-4 inline-flex items-center justify-center gap-2 rounded-full bg-primary px-4 py-2 text-sm font-medium text-white shadow-sm",children:[e.jsx(sr,{size:16,"aria-hidden":"true"}),We?"Invite contributors":"Invite people"]})]}),e.jsxs(lt,{mode:"wait",children:[Me==="information"&&e.jsxs(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-10",children:[We&&et&&ve&&e.jsx(md,{groupName:T.name,currentRole:bt,memoryProjectId:ve,memoryProjectRole:te?.role??bt,summary:et,ownerExperienceState:he,guideEditRequestKey:w,onScheduleCall:bt==="owner"?Te:it,onStartCall:bt==="owner"?Ae:_e,onInv
4iteContributors:Yt,onOpenInviteLinks:Hr,onDismissSetupGuidance:Yr,onDismissSetupCompleteInvite:n,onToggleChecklistItem:J,onUploadSources:W}),ue&&e.jsx(pd,{options:Ke,checkoutInFlightPlanCode:q,onStartCheckout:yt}),oe?e.jsxs("section",{children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Info"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:"Loading project details and access."})]}):We?null:e.jsxs("section",{children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Info"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:"Group overview, privacy, and settings."}),e.jsxs("div",{className:"mt-6 grid gap-6 lg:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 font-primary text-base font-bold text-grey-7",children:"About"}),e.jsx("div",{className:"min-h-[164px] rounded-xl border border-grey-1 bg-white p-5 dark:border-transparent dark:bg-grey-1",children:Dt?e.jsxs("div",{className:"space-y-3",children:[e.jsx("textarea",{value:Ze,onChange:R=>jt(R.target.value),onKeyDown:R=>{R.key==="Escape"&&Le(!1),(R.metaKey||R.ctrlKey)&&R.key==="Enter"&&(R.preventDefault(),Ns().catch(console.error))},autoFocus:!0,rows:5,placeholder:"Add a group description...",className:"w-full resize-none rounded-lg border border-grey-2 bg-white px-3 py-2 text-sm leading-relaxed text-grey-6 outline-none focus:border-primary focus:ring-1 focus:ring-primary/20 dark:bg-grey-1"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>Ns().catch(console.error),className:"rounded-full bg-primary px-4 py-1.5 text-sm font-medium text-white",children:"Save"}),e.jsx("button",{type:"button",onClick:()=>Le(!1),className:"rounded-full bg-grey-1 px-4 py-1.5 text-sm font-medium text-grey-5 hover:bg-grey-2 dark:bg-grey-2",children:"Cancel"})]})]}):e.jsx("button",{type:"button",onClick:Cr,className:`block w-full text-left text-sm leading-relaxed text-grey-6 ${T.isOwner?"hover:text-grey-7":"cursor-default"}`,children:T.description||"Add a description so members understand what belongs in this group."})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-3 font-primary text-base font-bold text-grey-7",children:"Details"}),e.jsxs("div",{className:"overflow-hidden rounded-xl border border-grey-1 bg-white dark:border-transparent dark:bg-grey-1",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-4",children:[e.jsx(Us,{size:16,className:"text-grey-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-grey-4",children:"Visibility"}),e.jsx("p",{className:"text-sm font-semibold text-grey-7",children:"Private"})]})]}),e.jsx("div",{className:"border-t border-grey-1 dark:border-grey-2"}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-4",children:[e.jsx(Gr,{size:16,className:"text-grey-4"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-grey-4",children:"Member count"}),e.jsxs("p",{className:"text-sm font-semibold text-grey-7",children:[ht.length," ",ht.length===1?"person":"people"]})]})]})]})]})]})]}),!We&&e.jsx(Wi,{currentEmoji:pe,currentName:ye,isOwner:!!T.isOwner,isMemoryProject:We,isMemoryProjectContributor:pr,groupName:T.name,startEditing:Ot,notificationsOn:x,onToggleNotifications:()=>S(R=>!R),onDeleteGroup:Ft,onLeaveGroup:$e})]},"information"),Me==="members"&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:e.jsx($i,{groupId:r,slug:t,acceptedMembers:ht,pendingInvites:ut,isOwner:!!T.isOwner,inviteRequestKey:Ct,inviteLinksRequestKey:De,onInviteRequestHandled:()=>St(0),onInviteLinksRequestHandled:()=>rt(0),memoryProjectSummary:We?et??void 0:void 0,canEvaluateMemoryProjectInvitePrompt:$t,isMemoryProjectInvitePromptDismissed:Wt,onDismissMemoryProjectInvitePrompt:I})},"members"),Me==="library"&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:We?e.jsx(Ln,{groupId:r,slug:t,groupName:T.name,sharedPages:Ge,canManageLibrary:!It&&Je,isOwner:!!T.isOwner,memoryProjectId:ve,memoryProjectPhase:wt,memoryProjectRole:Pt}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-primary text-2xl font-bold text-grey-7",children:"Library"}),e.jsx("p",{className:"mt-1 text-sm text-grey-4",children:"Pages and media shared directly with this group."})]}),e.jsx(Oa,{groupId:r,slug:t,sharedPages:Ge,canManageLibrary:!It&&Je,isOwner:!!T.isOwner,isMemoryProject:!1}),e.jsx(ds,{groupId:r,slug:t,canManageLibrary:!It&&Je})]})},"library"),Me==="sources"&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8}
4,animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:We?e.jsx(Fn,{groupId:r,slug:t,canManageLibrary:!It&&Je,memoryProjectId:ve,memoryProjectPhase:wt,memoryProjectRole:Pt}):e.jsx(ds,{groupId:r,slug:t,canManageLibrary:!It&&Je})},"sources"),Me==="collections"&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:oe?e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"h-7 w-36 animate-pulse rounded bg-grey-1 dark:bg-grey-2"}),e.jsx("div",{className:"h-28 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"}),e.jsx("div",{className:"h-56 animate-pulse rounded-xl bg-grey-1/70 dark:bg-grey-2/70"})]})]}):e.jsx(un,{groupId:r,slug:t,canManageCollections:!!T.isOwner,memoryProjectId:ve,memoryProjectRole:bt})},"collections"),Me==="sessions"&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:e.jsx(In,{groupId:r,role:bt,memoryProjectId:ve,memoryProjectPhase:wt,memoryProjectCaptureWindowStartsAt:qt,memoryProjectCaptureWindowEndsAt:qe})},"sessions"),Me==="keepsakes"&&We&&ve&&e.jsx(F.div,{...Qt,initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},className:"space-y-6",children:e.jsx(ll,{memoryProjectId:ve,memoryProjectRole:te?.role??bt,groupName:T.name,onComingSoon:()=>Fe("Coming soon")})},"keepsakes")]})]})]})}const ic=gd;export{ic as component};
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.