import{a as e,n as t,r as n}from"./createLucideIcon-D9Kay8o_.js";import{t as r}from"./useQuery-CiIFqdui.js";import{a as i}from"./use-items-B5MLguJC.js";import{t as a}from"./arrow-left-C7bHQ3yU.js";import{t as o}from"./BookmarkCard-Bfm6Erlx.js";import{t as s}from"./grid-3x3-CMmhrVPl.js";import{t as c}from"./list-BKI2irzM.js";import{t as l}from"./client-Cjdmbj0a.js";import{E as u,M as d,P as f,l as p,o as m,v as h,x as g}from"./index-BV_X4mzm.js";import{t as _}from"./use-collections-p5KFtfi0.js";var v=e(n(),1),y=t();function b(){let{id:e}=f(),{viewMode:t,setViewMode:n}=m(),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(``),w=_(),{data:T}=i(S),{data:E,isLoading:D}=r({queryKey:[`collection`,e],queryFn:()=>l.get(`/api/v1/collections/${e}`),enabled:!!e}),{data:O,isLoading:k}=r({queryKey:[`collection`,e,`items`],queryFn:()=>l.get(`/api/v1/collections/${e}/items`),enabled:!!e}),A=D||k;return(0,y.jsxs)(`div`,{className:`animate-fade-in p-6 max-w-6xl mx-auto`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-6`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(d,{to:`/collections`,className:`p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-all duration-200 cursor-pointer`,"aria-label":`Back to collections`,children:(0,y.jsx)(a,{className:`h-5 w-5 text-gray-500`})}),(0,y.jsx)(u,{className:`h-6 w-6 text-sky-600`}),D?(0,y.jsx)(`div`,{className:`h-7 w-48 animate-pulse bg-gray-200 dark:bg-gray-800 rounded`}):(0,y.jsx)(`h1`,{className:`text-2xl font-bold text-gray-900 dark:text-gray-100`,children:E?.name??`Collection`})]}),(0,y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,y.jsx)(`button`,{onClick:()=>x(!b),className:`p-2.5 rounded-lg text-sm bg-sky-600 text-white hover:bg-sky-700 transition-all duration-200 cursor-pointer mr-2`,"aria-label":`Add items`,children:(0,y.jsx)(g,{className:`h-4 w-4`})}),(0,y.jsx)(`button`,{onClick:()=>n(`grid`),className:`p-2.5 rounded-lg text-sm transition-all duration-200 cursor-pointer ${t===`grid`?`bg-sky-600 text-white`:`bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:shadow-md`}`,"aria-label":`Grid view`,children:(0,y.jsx)(s,{className:`h-4 w-4`})}),(0,y.jsx)(`button`,{onClick:()=>n(`list`),className:`p-2.5 rounded-lg text-sm transition-all duration-200 cursor-pointer ${t===`list`?`bg-sky-600 text-white`:`bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400 hover:shadow-md`}`,"aria-label":`List view`,children:(0,y.jsx)(c,{className:`h-4 w-4`})})]})]}),E?.description&&(0,y.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-6`,children:E.description}),b&&(0,y.jsxs)(`div`,{className:`mb-6 p-4 border border-sky-200 dark:border-sky-800 rounded-xl bg-sky-50/50 dark:bg-sky-950/20`,children:[(0,y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,y.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:`Add Items to Collection`}),(0,y.jsx)(`button`,{onClick:()=>x(!1),className:`p-1 text-gray-400 hover:text-gray-600`,children:(0,y.jsx)(p,{className:`w-4 h-4`})})]}),(0,y.jsxs)(`div`,{className:`relative mb-3`,children:[(0,y.jsx)(h,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400`}),(0,y.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`Search items to add...`,className:`w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800`,autoFocus:!0})]}),T&&T.length>0&&(0,y.jsx)(`div`,{className:`max-h-48 overflow-y-auto space-y-1`,children:T.slice(0,10).map(t=>(0,y.jsxs)(`button`,{onClick:()=>{w.mutate({collectionId:e,itemIds:[t.id]})},className:`w-full flex items-center gap-2 p-2 text-left text-sm rounded-lg hover:bg-white dark:hover:bg-gray-800 transition-colors`,children:[(0,y.jsx)(g,{className:`w-3.5 h-3.5 text-sky-500 shrink-0`}),(0,y.jsx)(`span`,{className:`truncate text-gray-800 dark:text-gray-200`,children:t.title||t.url||`Untitled`})]},t.id))})]}),A?(0,y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:Array.from({length:8}).map((e,t)=>(0,y.jsx)(`div`,{className:`h-48 animate-pulse bg-gray-200 dark:bg-gray-800 rounded-lg`},t))}):!O||O.length===0?(0,y.jsxs)(`div`,{className:`text-center py-16 rounded-xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm`,children:[(0,y.jsx)(u,{className:`h-12 w-12 text-gray-300 dark:text-gray-600 mx-auto mb-4`}),(0,y.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-lg mb-1`,children:`No items in this collection`}),(0,y.jsx)(`p`,{className:`text-gray-400 dark:text-gray-500 text-sm`,children:`Add items to this collection from the Knowledge Base`})]}):(0,y.jsx)(`div`,{className:t===`grid`?`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`:`flex flex-col gap-3`,children:O.map(e=>(0,y.jsx)(o,{item:e,variant:t},e.id))})]})}export{b as default};