module.exports=[153,a=>{"use strict";var b=a.i(37936),c=a.i(12259),d=a.i(18558),e=a.i(4361);async function f(a){let b=`
    SELECT i.*, c.name_en as category_name_en, c.name_ar as category_name_ar 
    FROM initiatives i 
    LEFT JOIN categories c ON i.category_id = c.id 
    WHERE 1=1
  `,d=[];a?.status&&(b+=" AND status = ?",d.push(a.status)),a?.categoryId&&(b+=" AND category_id = ?",d.push(a.categoryId)),a?.ownerId&&(b+=" AND owner_id = ?",d.push(a.ownerId)),b+=" ORDER BY created_at DESC",a?.limit&&(b+=" LIMIT ?",d.push(a.limit));try{return c.default.prepare(b).all(...d)}catch(a){return console.error("Error fetching initiatives:",a),[]}}async function g(a){try{return c.default.prepare("SELECT * FROM initiatives WHERE id = ?").get(a)||null}catch(a){return console.error("Error fetching initiative:",a),null}}async function h(a){let b=await (0,e.getProfile)();if(!b)return{error:"Unauthorized"};let f={id:crypto.randomUUID(),owner_id:b.id,title:a.get("title"),title_ar:a.get("titleAr"),description:a.get("description"),description_ar:a.get("descriptionAr"),category_id:a.get("categoryId")||null,status:"draft",target_beneficiaries:parseInt(a.get("targetBeneficiaries"))||0,start_date:a.get("startDate")||null,end_date:a.get("endDate")||null,location:a.get("location"),location_ar:a.get("locationAr")};try{return c.default.prepare(`
      INSERT INTO initiatives (
        id, owner_id, title, title_ar, description, description_ar, 
        category_id, status, target_beneficiaries, start_date, end_date, 
        location, location_ar
      ) VALUES (
        @id, @owner_id, @title, @title_ar, @description, @description_ar,
        @category_id, @status, @target_beneficiaries, @start_date, @end_date,
        @location, @location_ar
      )
    `).run(f),(0,d.revalidatePath)("/dashboard"),{data:f}}catch(a){return{error:a.message}}}async function i(a,b){let f=await (0,e.getProfile)();if(!f)return{error:"Unauthorized"};let g={};["title","description","status","location"].forEach(a=>{let c=b.get(a);null!==c&&(g[a]=c)});let h=b.get("titleAr");h&&(g.title_ar=h);let i=b.get("descriptionAr");i&&(g.description_ar=i);let j=b.get("categoryId");j&&(g.category_id=j);let k=b.get("locationAr");k&&(g.location_ar=k);let l=b.get("targetBeneficiaries");l&&(g.target_beneficiaries=parseInt(l));let m=b.get("currentBeneficiaries");m&&(g.current_beneficiaries=parseInt(m));let n=b.get("startDate");n&&(g.start_date=n);let o=b.get("endDate");if(o&&(g.end_date=o),g.updated_at=new Date().toISOString(),0===Object.keys(g).length)return{data:null};let p=[],q=[];for(let[a,b]of Object.entries(g))p.push(`${a} = ?`),q.push(b);q.push(a),q.push(f.id);try{return c.default.prepare(`UPDATE initiatives SET ${p.join(", ")} WHERE id = ? AND owner_id = ?`).run(...q),(0,d.revalidatePath)("/dashboard"),(0,d.revalidatePath)(`/initiatives/${a}`),{data:{id:a,...g}}}catch(a){return{error:a.message}}}async function j(a){let b=await (0,e.getProfile)();if(!b)return{error:"Unauthorized"};try{return c.default.prepare("DELETE FROM initiatives WHERE id = ? AND owner_id = ?").run(a,b.id),(0,d.revalidatePath)("/dashboard"),{success:!0}}catch(a){return{error:a.message}}}async function k(){try{return c.default.prepare("SELECT * FROM categories ORDER BY name_en").all()}catch(a){return console.error("Error fetching categories:",a),[]}}async function l(){try{let a=c.default.prepare("SELECT COUNT(*) as count FROM users").get(),b=c.default.prepare("SELECT COUNT(*) as count FROM initiatives").get(),d=c.default.prepare("SELECT COUNT(*) as count FROM join_requests").get();return{users:a.count,initiatives:b.count,joinRequests:d.count}}catch(a){return console.error("Error fetching global stats:",a),{users:0,initiatives:0,joinRequests:0}}}(0,a.i(13095).ensureServerEntryExports)([f,g,h,i,j,k,l]),(0,b.registerServerReference)(f,"40422d00aa06544af57882b17b095d2cffb030913d",null),(0,b.registerServerReference)(g,"40849a149609df662f4c8c7a7b880c6289f48789a9",null),(0,b.registerServerReference)(h,"40d15704019e2a0cb56cfd38b4f2adc5fbdbcbd8d0",null),(0,b.registerServerReference)(i,"600d21ee18a5edf14c480edaa1e751f6d88a117409",null),(0,b.registerServerReference)(j,"40ce843c6cba456248fa2478687866afd0e93b1bc4",null),(0,b.registerServerReference)(k,"007c76d9803c4a02000c43cfb6d2835279f4febbd8",null),(0,b.registerServerReference)(l,"007fbe34eb4cd3b4132d5d225ffa698d13e89e55fe",null),a.s(["createInitiative",0,h,"deleteInitiative",0,j,"getCategories",0,k,"getGlobalStats",0,l,"getInitiative",0,g,"getInitiatives",0,f,"updateInitiative",0,i])},75297,a=>{"use strict";var b=a.i(153),c=a.i(4361);a.s([],58482),a.i(58482),a.s(["0053f151110d6d75703d9fc023fe010ef247a2af24",()=>c.getProfile,"007c76d9803c4a02000c43cfb6d2835279f4febbd8",()=>b.getCategories,"007fbe34eb4cd3b4132d5d225ffa698d13e89e55fe",()=>b.getGlobalStats,"00a0df3d73092d96f20630b3c101b2b59332844306",()=>c.signOut,"00cc2076c3c855352ca3d3cc6d478acf6d93fa2fac",()=>c.getSession,"401aa66eceeee6a419930418593565bd958d22d704",()=>c.signIn,"40422d00aa06544af57882b17b095d2cffb030913d",()=>b.getInitiatives,"40849a149609df662f4c8c7a7b880c6289f48789a9",()=>b.getInitiative,"40ce843c6cba456248fa2478687866afd0e93b1bc4",()=>b.deleteInitiative,"40d15704019e2a0cb56cfd38b4f2adc5fbdbcbd8d0",()=>b.createInitiative,"600d21ee18a5edf14c480edaa1e751f6d88a117409",()=>b.updateInitiative],75297)}];

//# sourceMappingURL=_0y7-gbb._.js.map