import{c as l,k as g}from"./main-B-KzsHRi.js";const d="frenocorp_projects";function j(){try{const o=localStorage.getItem(d);return o?JSON.parse(o):[]}catch{return[]}}function P(o){localStorage.setItem(d,JSON.stringify(o))}function A(){const[o,s]=l(j()),[u,a]=l(!1);g(()=>{const t=o();P(t)});const f=async(t,n,r)=>{a(!0);const e={id:b(),name:t,description:n,ownerId:r,status:"draft",collaborators:[],createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};return s(c=>[e,...c]),a(!1),e},i=async(t,n)=>(a(!0),s(r=>r.map(e=>e.id===t?{...e,...n,updatedAt:new Date().toISOString()}:e)),a(!1),o().find(r=>r.id===t));return{projects:o,loading:u,createProject:f,updateProject:i,deleteProject:async t=>{a(!0),s(n=>n.filter(r=>r.id!==t)),a(!1)},addCollaborator:async(t,n,r)=>(a(!0),s(e=>e.map(c=>c.id!==t||c.collaborators.find(S=>S.userId===n)?c:{...c,collaborators:[...c.collaborators,{userId:n,role:r,addedAt:new Date().toISOString()}],updatedAt:new Date().toISOString()})),a(!1),o().find(e=>e.id===t)),removeCollaborator:async(t,n)=>(a(!0),s(r=>r.map(e=>e.id!==t?e:{...e,collaborators:e.collaborators.filter(c=>c.userId!==n),updatedAt:new Date().toISOString()})),a(!1),o().find(r=>r.id===t)),archiveProject:async t=>i(t,{status:"archived"})}}function b(){return`proj_${Date.now()}_${Math.random().toString(36).slice(2,9)}`}export{A as c};
//# sourceMappingURL=service-DriRc7_Z.js.map
