import{r as n,J as O,j as e,d as N,a as P}from"./app-BBZbvTSO.js";import{B as _}from"./button-CZmOQP7j.js";import{S as k}from"./search-bar-FrEZMnbC.js";import{D as L,C as A,P as B,G as R}from"./dnd.esm-Cel5mZtS.js";import{D as G,a as Q,b as V,g as b}from"./dropdown-menu-DkvU_mzU.js";import w from"./CreateCollectionModal-DJqF8xIf.js";import z from"./DeleteCollectionModal-DwYdUse-.js";import{P as F}from"./plus-D8fMMvfS.js";import{S as H}from"./settings-1sj5BLwD.js";import{E as J}from"./ellipsis-vertical-DoJR9-bA.js";/* empty css            */import"./utils-YhN_nlHn.js";import"./input-dmj4QjAp.js";import"./Select-BSWSW26d.js";import"./floating-ui.dom-DtF1XweH.js";import"./index-CbDI-tXU.js";import"./index-13DH8-b5.js";import"./index-IvSACaye.js";import"./index-BosTFUDi.js";import"./Combination-9YgcTppv.js";import"./index-hDbW6ayQ.js";import"./index-AiAmtg3H.js";import"./index-C1VwruLz.js";import"./index-Dbn6AP0q.js";import"./dialog-D_v2qgP5.js";import"./index-C0VDnRYN.js";import"./label-BPDCCRHl.js";import"./input-error-Bz7f2c6i.js";import"./checkbox-B0_9jnY6.js";import"./index-BCYyBCUm.js";import"./check-yuW7wFtQ.js";function we({project:s}){const[D,u]=n.useState(!1),[S,x]=n.useState(!1),[E,h]=n.useState(!1),[f,g]=n.useState(null),[a,M]=n.useState(""),[C,c]=n.useState(s.collections??[]),l=O(),i=l.props.userCan,{collection:d}=l.props;n.useEffect(()=>{c(s.collections??[])},[s.collections]);const p=l.component==="Collections/Edit",y=o=>l.component==="Collections/Show"||l.component==="Collections/Edit"?(d==null?void 0:d.id)===o:!1,j=C.filter(o=>o.name.toLowerCase().includes(a.toLowerCase())||o.slug.toLowerCase().includes(a.toLowerCase())),I=async o=>{if(!o.destination)return;const t=Array.from(C),[m]=t.splice(o.source.index,1);t.splice(o.destination.index,0,m),c(t);try{await P.post(route("projects.collections.reorder",s.id),{collections:t.map((r,v)=>({id:r.id,order:v}))})}catch(r){console.error("Failed to update collection order:",r),c(s.collections??[])}};return e.jsxs("div",{children:[e.jsxs("aside",{className:"w-full lg:w-64 space-y-4 sticky top-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-medium",children:"Collections"}),i.create_collection&&e.jsxs(_,{variant:"default",size:"sm",className:"h-6 px-1 text-xs",onClick:()=>u(!0),children:[e.jsx(F,{className:"mr-1"}),"Add New"]})]}),e.jsx(k,{value:a,onChange:M,placeholder:"Search collections...",className:"px-1"}),e.jsx(L,{onDragEnd:I,children:e.jsx(A,{droppableId:"collections",children:o=>e.jsxs("div",{...o.droppableProps,ref:o.innerRef,className:"space-y-1",children:[j.map((t,m)=>e.jsx(B,{draggableId:t.id.toString(),index:m,isDragDisabled:!p,children:r=>e.jsxs("div",{ref:r.innerRef,...r.draggableProps,className:"flex items-center space-x-2",children:[p&&e.jsx("div",{...r.dragHandleProps,className:"p-2 text-muted-foreground hover:text-foreground cursor-grab",children:e.jsx(R,{className:"w-4 h-4"})}),e.jsx(N,{href:route("projects.collections.show",[s.id,t.id]),className:`flex-1 p-2 text-sm rounded-md hover:bg-accent ${y(t.id)?"bg-accent text-accent-foreground":""}`,children:t.name}),i.access_collection_settings&&e.jsx(N,{href:route("projects.collections.edit",[s.id,t.id]),className:"block p-2 text-sm rounded-md hover:bg-accent",children:e.jsx(H,{className:"w-4 h-4"})}),p&&(i.update_collection||i.delete_collection)&&e.jsxs(G,{children:[e.jsx(Q,{asChild:!0,children:e.jsx("button",{className:"block p-2 text-sm rounded-md hover:bg-accent",children:e.jsx(J,{className:"w-4 h-4"})})}),e.jsxs(V,{align:"end",children:[i.update_collection&&e.jsx(b,{className:"cursor-pointer",onClick:()=>{g(t),x(!0)},children:"Edit Collection"}),i.delete_collection&&e.jsx(b,{className:"text-destructive cursor-pointer",onClick:()=>{g(t),h(!0)},children:"Delete Collection"})]})]})]})},t.id)),o.placeholder,j.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground px-2",children:a?"No collections found":"No collections yet"})]})})})]}),e.jsx(w,{open:D,onOpenChange:u,projectId:s.id}),e.jsx(w,{open:S,onOpenChange:x,projectId:s.id,collection:f}),e.jsx(z,{open:E,onOpenChange:h,projectId:s.id,collection:f})]})}export{we as default};
