var C=Object.defineProperty;var y=(e)=>e;function S(e,t){this[e]=y.bind(null,t)}var h=(e,t)=>{for(var o in t)C(e,o,{get:t[o],enumerable:!0,configurable:!0,set:S.bind(t,o)})};var w=(e,t)=>()=>(e&&(t=e(e=0)),t);import{Logger as _}from"@contractspec/lib.logger";import{createClient as x,Temv1alpha1 as u}from"@scaleway/sdk";var m={email:"noreply@transactional.contractspec.io",name:"ContractSpec"},p={email:"contact@contractspec.io",name:"ContractSpec Team"},v="fr-par",s=null,n=null,l=(e)=>new u.API(e),R=(e)=>{let t=e?.trim().toLowerCase();if(t==="par"||t==="fr-par")return"fr-par";if(t==="ams"||t==="nl-ams")return"nl-ams";if(t==="waw"||t==="pl-waw")return"pl-waw";return v},E=()=>{if(s)return{ok:!0,config:s};let e=process.env.SCALEWAY_ACCESS_KEY||process.env.SCALEWAY_ACCESS_KEY_QUEUE,t=process.env.SCALEWAY_SECRET_KEY||process.env.SCALEWAY_SECRET_KEY_QUEUE,o=process.env.SCALEWAY_PROJECT_ID;if(!e||!t||!o)return{ok:!1,errorMessage:"Email service is not configured. Please contact us directly at contact@contractspec.io."};let r=R(process.env.SCALEWAY_REGION);return s={accessKey:e,secretKey:t,projectId:o,region:r,defaultZone:`${r}-1`,from:{email:process.env.SCALEWAY_EMAIL_FROM_EMAIL??m.email,name:process.env.SCALEWAY_EMAIL_FROM_NAME??m.name},teamInbox:{email:process.env.SCALEWAY_EMAIL_TEAM_EMAIL??p.email,name:process.env.SCALEWAY_EMAIL_TEAM_NAME??p.name}},{ok:!0,config:s}},I=(e)=>{if(n)return n;let t=x({accessKey:e.accessKey,secretKey:e.secretKey,defaultProjectId:e.projectId,defaultRegion:e.region,defaultZone:e.defaultZone});return n=l(t),n},d=async(e,t)=>{try{return await I(e).createEmail({region:e.region,projectId:e.projectId,from:e.from,to:t.to,subject:t.subject,text:t.text,html:t.html||t.text,additionalHeaders:t.replyTo?[{key:"Reply-To",value:t.replyTo}]:void 0}),{success:!0}}catch(o){return new _().error("scaleway_tem_email_send_failed",{context:t.context??"email",error:o instanceof Error?o.message:o}),{success:!1,error:o,errorMessage:"Failed to send email via Scaleway."}}},Y={resetCaches(){n=null,s=null,l=(e)=>new u.API(e)},setApiFactory(e){l=e},setClient(e){n=e}};var i=(e)=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),f=(e)=>i(e).replaceAll(`
`,"<br />");var T="Email service is not configured. Please contact us directly at contact@contractspec.io.",M="Failed to send message. Please contact us directly at contact@contractspec.io.",$=async(e)=>{let t=(e.get("name")??"").toString().trim(),o=(e.get("email")??"").toString().trim(),r=(e.get("message")??"").toString().trim();if(!o)return{success:!1,text:"Please fill in all required fields."};let a=E();if(!a.ok||!a.config)return{success:!1,text:a.errorMessage??T};let c=t||o,g=`
New contact form submission from ${c}

Contact Information:
- Name: ${t||"Not provided"}
- Email: ${o}

Message:
${r||"No message provided"}

---
Submitted via ContractSpec contact form
  `.trim(),A=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <h1 style="color: #8b5cf6; margin-bottom: 12px;">New contact form submission</h1>
      <p style="margin: 0 0 12px;">From ${i(c)}</p>
      <h2 style="color: #8b5cf6; margin: 16px 0 8px;">Contact Information</h2>
      <ul style="padding-left: 16px; line-height: 1.6; margin: 0 0 16px;">
        <li>Name: ${i(t||"Not provided")}</li>
        <li>Email: ${i(o)}</li>
      </ul>
      <h2 style="color: #8b5cf6; margin: 16px 0 8px;">Message</h2>
      <div style="border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; background: #f9fafb; white-space: pre-wrap; line-height: 1.6;">
        ${r?f(r):"No message provided"}
      </div>
      <p style="color: #6b7280; font-size: 12px; margin-top: 20px;">Submitted via ContractSpec contact form</p>
    </div>
  `;if(!(await d(a.config,{to:[a.config.teamInbox],subject:`New Contact Form Message from ${c}`,text:g,html:A,replyTo:o,context:"contact-form"})).success)return{success:!1,text:M};return{success:!0,text:"Message sent successfully!"}};export{$ as submitContactForm};
