1import{r as c,j as e,k as w,b as Ne,z as be,f as Fe,t as N,x as ee,g as P}from"./index-Dgn6DKPx.js";import{u as S}from"./useMutation-DP92Tosv.js";import{c as te,C as se,S as z,a as T}from"./content.service-eRBNahxE.js";import{F as B,f as A,g as Ie,E as De}from"./folder-icons-BB4O67sD.js";import{a as Se}from"./article.service-fj3O5Zdm.js";import{s as Ae}from"./scrap.service-DMQCJ4Y6.js";import{P as we}from"./page-container-BDM2U9rw.js";import{P as Ee}from"./page-breadcrumb-BFJdCzkb.js";import{B as E}from"./index-CA1oIEuC.js";import{D as _e,a as Me,b as ze,c as Te,d as ke,e as Le}from"./dialog-C7vFcwGg.js";import{I as Oe}from"./input-mTxZQvhe.js";import{L as k}from"./label-Cu9BovJp.js";import{u as K}from"./useTranslation-DwAXk-Kx.js";import{E as Pe,P as Be}from"./edit-folder-modal-BJcDMD8t.js";import{D as qe,a as Re,b as Ke,c as re}from"./dropdown-menu-CO3ygi2g.js";import{A as ne,b as oe,c as ae,d as le,e as ie,f as ce,g as de,h as me}from"./alert-dialog-Bzm_q3sc.js";import{C as $e}from"./content-card-BTheBu3M.js";import{P as Qe}from"./plus-BXeH85nO.js";import{T as Ve}from"./trash-2-ChwV9tob.js";import{C as He}from"./chevron-right-B-l8byzU.js";import"./code-yDb0KUMc.js";import"./tooltip-Wxteot61.js";import"./index-DLKsWNUv.js";import"./index-BGAq7GE9.js";import"./index-DCYs_jYw.js";import"./index-CLg1BKAD.js";import"./x-Rel1YFG_.js";import"./index-BUcHZ7IE.js";import"./index-CZ30QPVs.js";import"./card-CUy5snoM.js";import"./globe-DNPhtTvc.js";import"./file-DtI2lfs6.js";import"./file-text-DOyULCur.js";import"./calendar-CJ3DHkEA.js";const q=["#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#8b5cf6","#ec4899","#888888"],R=100,Ue=/[<>:"/\\|?*\x00-\x1F]/g;function Ge(s,a){const x=s.trim();return x?x.length>R?a("folder.create.validation.tooLong",{max:R}):Ue.test(x)?a("folder.create.validation.invalidChars"):null:a("folder.create.validation.required")}function Xe({open:s,onOpenChange:a,onSubmit:x,isLoading:l=!1}){const{t:n}=K(),[m,h]=c.useState(""),[g,C]=c.useState(q[4]),[u,f]=c.useState(B[0]),[y,i]=c.useState(null),_=()=>{h(""),C(q[4]),f(B[0]),i(null),a(!1)},b=async()=>{const r=Ge(m,n);if(r){i(r);return}i(null);try{await x({name:m.trim(),color:g,icon:u.id}),_()}catch(v){i(v instanceof Error?v.message:"Failed to create folder")}},j=r=>{r.key==="Enter"&&!l&&b()};return e.jsx(_e,{open:s,onOpenChange:a,children:e.jsxs(Me,{className:"sm:max-w-[500px]",children:[e.jsxs(ze,{children:[e.jsx(Te,{children:n("folder.create.title")}),e.jsx(ke,{children:n("folder.create.description")})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"folder-name",children:n("folder.create.nameLabel")}),e.jsx(Oe,{id:"folder-name",placeholder:n("folder.create.namePlaceholder"),value:m,onChange:r=>h(r.target.value),onKeyDown:j,maxLength:R,autoFocus:!0}),y&&e.jsx("p",{className:"text-sm text-destructive",children:y})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:n("folder.create.iconLabel")}),e.jsx("div",{className:"grid grid-cols-9 gap-2",children:B.map(r=>{const v=r.icon,F=u.id===r.id;return e.jsx("button",{type:"button",onClick:()=>f(r),className:`flex items-center justify-center size-10 rounded-md border-2 transition-all hover:scale-105 ${F?"border-primary bg-primary/10":"border-border hover:border-primary/50"}`,title:r.name,children:e.jsx(v,{className:`size-5 ${F?"text-primary":"text-muted-foreground"}`})},r.id)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:n("folder.create.colorLabel")}),e.jsx("div",{className:"flex gap-2",children:q.map(r=>{const v=g===r;return e.jsx("button",{type:"button",onClick:()=>C(r),className:`size-10 rounded-md transition-all hover:scale-105 ${v?"ring-2 ring-primary ring-offset-2":""}`,style:{backgroundColor:r},"aria-label":`Select color ${r}`},r)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:n("folder.create.previewLabel")}),e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-4",children:[e.jsx("div",{className:"flex items-center justify-center size-12 rounded-lg bg-muted",children:(()=>{const r=u.icon;return e.jsx(r,{className:"size-6",style:{color:g}})})()}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:m||n("folder.create.previewDefault")}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[u.name," ⢠",g]})]})]})]})]}),e.jsxs(Le,{children:[e.jsx(E,{variant:"outline",onClick:_,disabled:l,children:n("common.cancel")}),e.jsxs(E,{onClick:b,disabled:l||!m.trim(),children:[l&&e.jsx(w,{className:"mr-2 size-4 animate-spin"}),n(l?"folder.create.creating":"folder.create.createButton")]})]})]})})}function ue({folder:s,items:a,isLoading:x,onItemClick:l,onViewAll:n,onEdit:m,onDelete:h,onDeleteItem:g,onMoveItem:C,availableFolders:u=[]}){const{t:f}=K(),y=Ie(s?.icon);return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center size-12 rounded-lg transition-transform hover:scale-105 bg-muted",children:e.jsx(y,{className:"size-6",style:{color:s?.color||void 0}})}),e.jsx("div",{children:e.jsx("h3",{className:"font-semibold text-lg",children:s?.name||f("
1content.folder.uncategorized")})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s&&m&&h&&e.jsxs(qe,{children:[e.jsx(Re,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon",className:"size-8",children:e.jsx(De,{className:"size-4"})})}),e.jsxs(Ke,{align:"end",children:[e.jsxs(re,{onClick:m,children:[e.jsx(Be,{className:"size-4 mr-2"}),f("common.edit")]}),e.jsxs(re,{onClick:h,className:"text-destructive",children:[e.jsx(Ve,{className:"size-4 mr-2"}),f("common.delete")]})]})]}),e.jsxs(E,{variant:"ghost",size:"sm",onClick:n,className:"flex items-center gap-1",children:[e.jsx("span",{children:f("common.viewAll")}),e.jsx(He,{className:"size-4"})]})]})]}),e.jsx("div",{className:"relative",children:x?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(w,{className:"size-6 animate-spin text-muted-foreground"})}):a.length===0?e.jsx("div",{className:"text-sm text-muted-foreground py-8 text-center",children:f("content.folder.noContentInFolder")}):e.jsx("div",{className:"overflow-x-auto overflow-y-hidden pb-3 -mb-3",style:{scrollbarWidth:"thin",scrollbarColor:"hsl(var(--muted-foreground) / 0.3) transparent"},children:e.jsx("div",{className:"flex gap-4 pr-4",children:a.slice(0,10).map(i=>e.jsx($e,{item:i,onClick:()=>l(i),onDelete:g,onMove:C,availableFolders:u,currentFolderId:s?.folderId||null},`${i.type}-${i.id}`))})})})]})}function Et(){const{t:s}=K(),a=Ne(),x=be.useSearch(),l=Fe(),[n]=c.useState(x.sortBy||"newest"),[m,h]=c.useState(!1),[g,C]=c.useState(!1),[u,f]=c.useState(null),[y,i]=c.useState(null),[_,b]=c.useState(!1),[j,r]=c.useState(null),[v,F]=c.useState(!1);c.useEffect(()=>{const t={page:"content",viewing_folder:!1,sort_by:n,timestamp:new Date().toISOString()};N("Content Page Viewed",t)},[n]);const $=S({mutationFn:t=>A.createFolder(t),onSuccess:()=>{l.invalidateQueries({queryKey:["folders"]})}}),Q=S({mutationFn:t=>A.updateFolder(t.folderId,t.updates),onSuccess:()=>{l.invalidateQueries({queryKey:["folders"]})}}),V=S({mutationFn:t=>A.deleteFolder(t),onSuccess:()=>{l.invalidateQueries({queryKey:["folders"]})}}),L=S({mutationFn:async t=>{t.type==="article"?await Se.deleteArticle(t.id):await Ae.deleteScrap(t.id)},onSuccess:(t,o)=>{o.type==="article"?N("Article Deleted",{article_id:o.id,folder_id:null}):N("Material Deleted",{scrap_id:o.id,folder_id:null}),l.invalidateQueries({queryKey:["content"]})}}),fe=S({mutationFn:async({item:t,targetFolderId:o})=>{const p=t.type==="article"?{articleIds:[t.id]}:{scrapIds:[t.id]};await A.moveItemsToFolder(null,o,p)},onSuccess:(t,{item:o,targetFolderId:p})=>{o.type==="article"?N("Article Moved",{article_id:o.id,from_folder:null,to_folder:p}):N("Material Moved",{scrap_id:o.id,from_folder:null,to_folder:p}),l.invalidateQueries({queryKey:["content"]}),l.invalidateQueries({queryKey:["folder-contents"]});let M=s("content.folder.uncategorized");if(p){const D=(d||[]).find(O=>O.folderId===p);D&&(M=D.name)}ee.success(s("content.moveSuccess",{folderName:M}))},onError:()=>{ee.error(s("content.moveError"))}}),H=()=>{switch(n){case"newest":return{sortBy:T.CREATED_AT,sortOrder:z.DESC};case"oldest":return{sortBy:T.CREATED_AT,sortOrder:z.ASC};case"title":return{sortBy:T.TITLE,sortOrder:z.ASC};default:return{sortBy:T.CREATED_AT,sortOrder:z.DESC}}},{data:d,isLoading:U,error:G}=P({queryKey:["folders","root"],queryFn:()=>A.getFolders(null)}),{data:pe,isLoading:xe}=P({queryKey:["content","uncategorized",n],queryFn:async()=>{const{sortBy:t,sortOrder:o}=H();return te.getUnifiedContent({type:se.ALL,folderId:null,page:1,limit:10,sortBy:t,sortOrder:o})}}),X=P({queryKey:["folder-contents",d,n],queryFn:async()=>{if(!d||d.length===0)return{};const{sortBy:t,sortOrder:o}=H(),p=d.map(async I=>{const D=await te.getUnifiedContent({type:se.ALL,folderId:I.folderId,page:1,limit:10,sortBy:t,sortOrder:o});return{folderId:I.folderId,content:D}});return(await Promise.all(p)).reduce((I,{folderId:D,content:O})=>(I[D]=O,I),{})},enabled:!!d&&d.length>0}),W=t=>{N("Content Item Clicked",{content_id:t.id,content_type:t.type,content_title:t.title,from_folder:null,has_hero_image:!!t.heroImageUrl,created_at:t.createdAt}),t.type==="article"?a({to:"/workspace/articles/$articleId",params:{articleId:t.id},search:{fromFolder:void 0}}):a({to:"/workspace/materials/$scrapId",params:{scrapId:t.id},search:{fromFolder:void 0}})},J=t=>{a(t?{to:"/workspace/folder/$folderId",params:{folderId:t},search:{sortBy:n}}:{to:"/workspace/folder/$folderId",params:{folderId:"null"},search:{sortBy:n}})},he=async t=>{await $.mutateAsync(t),N("Folder Created",{folder_name:t.name,folder_color:t.color,folder_icon:t.icon})},ge=t=>{f(t),C(!0)},ye=async t=>{u&&await Q.mutateAsync({folderId:u.folderId,updates:t})},je=t=>{i(t),b(!0)},ve=async()=>{y&&(await V.mutateAsync(y.folderId),b(!1),i(null))},Y=t=>{r(t),F(!0)},Ce=async()=>{j&&(await L.mutateAsync(j),F(!1),r(null))},Z=async(t,o)=>{await fe.mutateAsync({item:t,targetFolderId:o})};return e.jsxs(we,{children:[e.jsx(Ee,{segments:[{label:s("content.title")}]}),e.jsxs("div",{className:"mt-6 space-y-8",children:[e.jsx("div",{className:"flex justify-start",children:e.jsxs(E,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(Qe,{className:"size-4 mr-2"}),s("content.folder.blankFolder")]})}),G&&e.jsxs("div",{className:"rounded-md border border-red-200 bg-red-50 p-4 text-red-700",children:["Failed to load folders: ",String(G)]}),U&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx(w,{className:"size-8 animate-spin text-muted-foreground"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:s("common.loadingFolders")})]})}),!U&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(ue,{items:pe?.items||[],isLoading:xe,onItemClick:W,onViewAll:()=>J(),onDeleteItem:Y,onMoveItem:Z,availableFolders:d||[]}),d&&d.length>0&&d.map(t=>{const p=X.data?.[t.folderId]?.items||[];return e.jsx(ue,{folder:t,items:p,isLoading:X.isLoading,onItemClick:W,onViewAll:()=>J(t.folderId),onEdit:()=>ge(t),onDelete:()=>je(t),onDeleteItem:Y,onMoveItem:Z,availableFolders:d||[]},t.folderId)})]})]}),e.jsx(Xe,{open:m,onOpenChange:h,onSubmit:he,isLoading:$.isPending}),e.jsx(Pe,{open:g,onOpenChange:C,folder:u,onSubmit:ye,isLoading:Q.isPending}),e.jsx(ne,{open:_,onOpenChange:b,children:e.jsxs(oe,{children:[e.jsxs(ae,{children:[e.jsx(le,{children:s("content.folder.deleteConfirmTitle")}),e.jsx(ie,{children:s("content.folder.deleteConfirmMessage",{name:y?.name})})]}),e.jsxs(ce,{children:[e.jsx(de,{onClick:()=>i(null),children:s("common.cancel")}),e.jsxs(me,{onClick:ve,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[V.isPending&&e.jsx(w,{className:"mr-2 size-4 animate-spin"}),s("common.delete")]})]})]})}),e.jsx(ne,{open:v,onOpenChange:F,children:e.jsxs(oe,{children:[e.jsxs(ae,{children:[e.jsx(le,{children:j&&s("content.deleteConfirm",{type:j.type==="article"?s("content.filter.article"):s("content.filter.material")})}),e.jsx(ie,{children:j&&s("content.deleteConfirmMessage",{title:j.title||s("common.noTitle")})})]}),e.jsxs(ce,{children:[e.jsx(de,{onClick:()=>r(null),children:s("common.cancel")}),e.jsxs(me,{onClick:Ce,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[L.isPending&&e.jsx(w,{className:"mr-2 size-4 animate-spin"}),L.isPending?s("content.deleting"):s("common.delete")]})]})]})})]})}export{Et 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.