1import{ax as m,z as o,bZ as c,bY as u,D as s,s as n,e as l}from"./index-BwaMfbd5.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new e.Error().stack;a&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[a]="e0b3a749-5086-42c5-be7d-64780a8ea93f",e._sentryDebugIdIdentifier="sentry-dbid-e0b3a749-5086-42c5-be7d-64780a8ea93f")}catch{}})();/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const y=m("Columns2",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]]);function f(e){return o({queryKey:["projects-by-account",e],queryFn:async()=>{if(!e)return[];const{data:a,error:r}=await n.from("projects").select("id, brand_name, industry").eq("account_id",e).order("brand_name");if(r)throw r;return a||[]},enabled:!!e})}function p(e){return o({queryKey:["brand-assets-by-project",e],queryFn:async()=>{if(!e)return[];const{data:a,error:r}=await n.from("brand_assets").select("id, asset_type, file_url, metadata").eq("project_id",e);if(r)throw r;return a||[]},enabled:!!e})}function _(e){return o({queryKey:["email-campaigns",e??null],queryFn:async()=>{let a=n.from("email_campaigns").select("*").order("created_at",{ascending:!1});e&&(a=a.eq("project_id",e));const{data:r,error:i}=await a;if(i)throw i;return r}})}function g(e){return o({queryKey:["email-campaign",e],enabled:!!e,queryFn:async()=>{const{data:a,error:r}=await n.from("email_campaigns").select("*").eq("id",e).maybeSingle();if(r)throw r;return a}})}function b(e){return o({queryKey:["email-campaign-recipients",e],enabled:!!e,queryFn:async()=>{const{data:a,error:r}=await n.from("email_campaign_recipients").select("*").eq("campaign_id",e).order("created_at",{ascending:!1});if(r)throw r;return a}})}function q(){const e=c(),{user:a}=l();return u({mutationFn:async r=>{if(r.id){const{error:i}=await n.from("email_campaigns").update(r).eq("id",r.id);if(i)throw i;return r}else{const{data:i,error:t}=await n.from("email_campaigns").insert({...r,created_by:a==null?void 0:a.id}).select().single();if(t)throw t;return i}},onSuccess:()=>{e.invalidateQueries({queryKey:["email-campaigns"]})},onError:r=>s.error("toast_error.operation_failed",r.message)})}function w(){const e=c();return u({mutationFn:async a=>{const{error:r}=await n.from("email_campaigns").delete().eq("id",a);if(r)throw r},onSuccess:()=>{e.invalidateQueries({queryKey:["email-campaigns"]}),s.success("toast_success.campaña_eliminada","Campaña eliminada")},onError:a=>s.error("toast_error.operation_failed",a.message)})}function h(){const e=c();return u({mutationFn:async a=>{const r=await n.functions.invoke("send-email-campaign",{body:{campaign_id:a}});if(r.error)throw r.error;return r.data},onSuccess:()=>{e.invalidateQueries({queryKey:["email-campaigns"]}),e.invalidateQueries({queryKey:["email-campaign-recipients"]}),s.success("toast_success.campaña_enviada_exitosamente","Campaña enviada exitosamente")},onError:a=>s.error("toast_error.error_al_enviar_emessage","Error al enviar: "+a.message)})}function v(){const e=c();return u({mutationFn:async({campaignId:a,contacts:r})=>{await n.from("email_campaign_recipients").delete().eq("campaign_id",a).eq("status","pending");const i=r.map(t=>({campaign_id:a,contacto_id:t.id,email:t.email,nombre:`${t.nombre||""} ${t.apellido||""}`.trim(),status:"pending"}));if(i.length>0){const{error:t}=await n.from("email_campaign_recipients").insert(i);if(t)throw t}return await n.from("email_campaigns").update({recipient_count:i.length}).eq("id",a),i.length},onSuccess:a=>{e.invalidateQueries({queryKey:["email-campaigns"]}),e.invalidateQueries({queryKey:["email-campaign-recipients"]}),s.success("toast_success.destinatarios_configurados",`${a} destinatarios configurados`)},onError:a=>s.error("toast_error.operation_failed",a.message)})}export{y as C,b as a,_ as b,w as c,q as d,h as e,v as f,f as g,g as h,p as u}; 7//# sourceMappingURL=useEmailCampaigns-Bwhd7Vk4.js.map
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.