// @bun
import{Logger as _}from"@contractspec/lib.logger";import{createClient as W,Temv1alpha1 as w}from"@scaleway/sdk";var b={email:"noreply@transactional.contractspec.io",name:"ContractSpec"},S={email:"contact@contractspec.io",name:"ContractSpec Team"},$="fr-par",g=null,d=null,y=(e)=>new w.API(e),P=(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 $},m=()=>{if(g)return{ok:!0,config:g};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,i=process.env.SCALEWAY_PROJECT_ID;if(!e||!t||!i)return{ok:!1,errorMessage:"Email service is not configured. Please contact us directly at contact@contractspec.io."};let o=P(process.env.SCALEWAY_REGION);return g={accessKey:e,secretKey:t,projectId:i,region:o,defaultZone:`${o}-1`,from:{email:process.env.SCALEWAY_EMAIL_FROM_EMAIL??b.email,name:process.env.SCALEWAY_EMAIL_FROM_NAME??b.name},teamInbox:{email:process.env.SCALEWAY_EMAIL_TEAM_EMAIL??S.email,name:process.env.SCALEWAY_EMAIL_TEAM_NAME??S.name}},{ok:!0,config:g}},k=(e)=>{if(d)return d;let t=W({accessKey:e.accessKey,secretKey:e.secretKey,defaultProjectId:e.projectId,defaultRegion:e.region,defaultZone:e.defaultZone});return d=y(t),d},n=async(e,t)=>{try{return await k(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(i){return new _().error("scaleway_tem_email_send_failed",{context:t.context??"email",error:i instanceof Error?i.message:i}),{success:!1,error:i,errorMessage:"Failed to send email via Scaleway."}}},Q={resetCaches(){d=null,g=null,y=(e)=>new w.API(e)},setApiFactory(e){y=e},setClient(e){d=e}};var a=(e)=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;"),r=(e)=>a(e).replaceAll(`
`,"<br />");var M="Email service is not configured. Please contact us directly at contact@contractspec.io.",F="Failed to send message. Please contact us directly at contact@contractspec.io.",O=async(e)=>{let t=(e.get("name")??"").toString().trim(),i=(e.get("email")??"").toString().trim(),o=(e.get("message")??"").toString().trim();if(!i)return{success:!1,text:"Please fill in all required fields."};let s=m();if(!s.ok||!s.config)return{success:!1,text:s.errorMessage??M};let l=t||i,c=`
New contact form submission from ${l}

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

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

---
Submitted via ContractSpec contact form
  `.trim(),p=`
    <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 ${a(l)}</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: ${a(t||"Not provided")}</li>
        <li>Email: ${a(i)}</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;">
        ${o?r(o):"No message provided"}
      </div>
      <p style="color: #6b7280; font-size: 12px; margin-top: 20px;">Submitted via ContractSpec contact form</p>
    </div>
  `;if(!(await n(s.config,{to:[s.config.teamInbox],subject:`New Contact Form Message from ${l}`,text:c,html:p,replyTo:i,context:"contact-form"})).success)return{success:!1,text:F};return{success:!0,text:"Message sent successfully!"}};var Y="Newsletter service is not configured. Please try again later.",E="Failed to subscribe. Please try again later or contact us directly.",L=async(e)=>{let t=(e.get("email")??"").toString().trim();if(!t||!t.includes("@"))return{success:!1,text:"Please enter a valid email address."};let i=m();if(!i.ok||!i.config)return{success:!1,text:i.errorMessage??Y};let o=`
Welcome to ContractSpec!

Thanks for subscribing to our newsletter. You'll receive updates on:

\u2022 New integrations (Stripe, OpenAI, Qdrant, and more)
\u2022 Product features and improvements
\u2022 New templates and examples
\u2022 Architecture insights and best practices
\u2022 Documentation updates

Stay tuned for exciting updates!

---
ContractSpec Team
https://contractspec.io

Unsubscribe: Reply to this email with "unsubscribe"
  `.trim(),s=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <h1 style="color: #8b5cf6;">Welcome to ContractSpec!</h1>
      <p>Thanks for subscribing to our newsletter. You'll receive updates on:</p>
      <ul style="line-height: 1.8;">
        <li>New integrations (Stripe, OpenAI, Qdrant, and more)</li>
        <li>Product features and improvements</li>
        <li>New templates and examples</li>
        <li>Architecture insights and best practices</li>
        <li>Documentation updates</li>
      </ul>
      <p>Stay tuned for exciting updates!</p>
      <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;" />
      <p style="color: #6b7280; font-size: 14px;">
        ContractSpec Team<br />
        <a href="https://contractspec.io" style="color: #8b5cf6;">contractspec.io</a>
      </p>
      <p style="color: #9ca3af; font-size: 12px;">
        To unsubscribe, reply to this email with "unsubscribe"
      </p>
    </div>
  `;if(!(await n(i.config,{to:[{email:t}],subject:"Welcome to ContractSpec Newsletter",text:o,html:s,context:"newsletter-welcome"})).success)return{success:!1,text:E};let c=`New newsletter subscription from: ${t}`,p=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <p style="margin: 0 0 8px;">New newsletter subscription</p>
      <p style="margin: 0;"><strong>Email:</strong> ${r(t)}</p>
    </div>
  `;if(!(await n(i.config,{to:[i.config.teamInbox],subject:`New Newsletter Subscription: ${t}`,text:c,html:p,context:"newsletter-team-notification"})).success)return{success:!1,text:E};return{success:!0,text:"Successfully subscribed!"}};var j="Waitlist service is not configured. Please try again later.",C="Failed to join waitlist. Please try again later or contact us directly.",H=async(e)=>{let t=(e.get("email")??"").toString().trim();if(!t||!t.includes("@"))return{success:!1,text:"Please enter a valid email address."};let i=m();if(!i.ok||!i.config)return{success:!1,text:i.errorMessage??j};let o=`
You're on the waitlist!

Thanks for joining the ContractSpec waitlist. You're now in line for early access to:

\u2022 Stabilize your AI-generated code with ContractSpec
\u2022 Multi-surface consistency (API, DB, UI, events)
\u2022 Safe regeneration without breaking changes
\u2022 AI governance and contract enforcement

We'll notify you as soon as early access is available. In the meantime, you can:

\u2022 Check out our docs: https://contractspec.io/docs
\u2022 Follow our progress on GitHub
\u2022 Book a demo call to see ContractSpec in action

We're excited to have you on board!

---
ContractSpec Team
https://contractspec.io

To remove yourself from the waitlist, reply to this email with "remove"
  `.trim(),s=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <h1 style="color: #8b5cf6;">You're on the waitlist!</h1>
      <p>Thanks for joining the ContractSpec waitlist. You're now in line for early access to:</p>
      <ul style="line-height: 1.8;">
        <li>Stabilize your AI-generated code with ContractSpec</li>
        <li>Multi-surface consistency (API, DB, UI, events)</li>
        <li>Safe regeneration without breaking changes</li>
        <li>AI governance and contract enforcement</li>
      </ul>
      <p>We'll notify you as soon as early access is available. In the meantime, you can:</p>
      <ul style="line-height: 1.8;">
        <li>Check out our <a href="https://contractspec.io/docs" style="color: #8b5cf6;">docs</a></li>
        <li>Follow our progress on GitHub</li>
        <li>Book a demo call to see ContractSpec in action</li>
      </ul>
      <p>We're excited to have you on board!</p>
      <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;" />
      <p style="color: #6b7280; font-size: 14px;">
        ContractSpec Team<br />
        <a href="https://contractspec.io" style="color: #8b5cf6;">contractspec.io</a>
      </p>
      <p style="color: #9ca3af; font-size: 12px;">
        To remove yourself from the waitlist, reply to this email with "remove"
      </p>
    </div>
  `;if(!(await n(i.config,{to:[{email:t}],subject:"You're on the ContractSpec waitlist!",text:o,html:s,context:"waitlist-welcome"})).success)return{success:!1,text:C};let c=`New waitlist signup from: ${t}`,p=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <p style="margin: 0 0 8px;">New waitlist signup</p>
      <p style="margin: 0;"><strong>Email:</strong> ${r(t)}</p>
    </div>
  `;if(!(await n(i.config,{to:[i.config.teamInbox],subject:`New Waitlist Signup: ${t}`,text:c,html:p,context:"waitlist-team-notification"})).success)return{success:!1,text:C};return{success:!0,text:"Successfully joined waitlist!"}};var z="Waitlist application service is not configured. Please try again later.",v="Failed to submit application. Please try again later or contact us directly.",D=async(e)=>{let t=(e.get("email")??"").toString().trim(),i=(e.get("name")??"").toString().trim(),o=(e.get("company")??"").toString().trim(),s=(e.get("role")??"").toString().trim(),l=(e.get("whatBuilding")??"").toString().trim(),c=(e.get("whatSolving")??"").toString().trim(),p=(e.get("teamSize")??"").toString().trim(),f=(e.get("timeline")??"").toString().trim(),h=e.get("openToSessions")==="on",x=e.get("okayWithCaseStudies")==="on";if(!t||!t.includes("@"))return{success:!1,text:"Please enter a valid email address."};if(!i||!l||!c)return{success:!1,text:"Please fill in all required fields."};let u=m();if(!u.ok||!u.config)return{success:!1,text:u.errorMessage??z};let A=`
You're on the list.

Thanks for applying to the ContractSpec design partner program. We're slowly onboarding design partners in waves. If your use case is a good fit, we'll reach out personally.

What happens next:
\u2022 We review applications weekly
\u2022 If selected, we'll reach out via email to schedule an intro call
\u2022 During early access, you'll get hands-on support and influence over the roadmap

In the meantime:
\u2022 Check out our docs: https://contractspec.io/docs
\u2022 Book a demo call: https://contractspec.io/contact

We're excited about the possibility of working together!

---
ContractSpec Team
https://contractspec.io
  `.trim(),N=`
    <div style="font-family: sans-serif; max-width: 640px; margin: 0 auto;">
      <h1 style="color: #8b5cf6;">You're on the list.</h1>
      <p>Thanks for applying to the ContractSpec design partner program. We're slowly onboarding design partners in waves. If your use case is a good fit, we'll reach out personally.</p>
      <h2 style="color: #8b5cf6; margin-top: 24px;">What happens next:</h2>
      <ul style="line-height: 1.8;">
        <li>We review applications weekly</li>
        <li>If selected, we'll reach out via email to schedule an intro call</li>
        <li>During early access, you'll get hands-on support and influence over the roadmap</li>
      </ul>
      <h2 style="color: #8b5cf6; margin-top: 24px;">In the meantime:</h2>
      <ul style="line-height: 1.8;">
        <li>Check out our <a href="https://contractspec.io/docs" style="color: #8b5cf6;">docs</a></li>
        <li>Book a demo call: <a href="https://contractspec.io/contact" style="color: #8b5cf6;">contractspec.io/contact</a></li>
      </ul>
      <p>We're excited about the possibility of working together!</p>
      <hr style="margin: 30px 0; border: none; border-top: 1px solid #e5e7eb;" />
      <p style="color: #6b7280; font-size: 14px;">
        ContractSpec Team<br />
        <a href="https://contractspec.io" style="color: #8b5cf6;">contractspec.io</a>
      </p>
    </div>
  `;if(!(await n(u.config,{to:[{email:t}],subject:"You're on the ContractSpec design partner waitlist!",text:A,html:N,context:"waitlist-application-welcome"})).success)return{success:!1,text:v};let I=`
Open to 1:1 product/design sessions: ${h?"Yes":"No"}
Okay with anonymized case studies: ${x?"Yes":"No"}
  `.trim(),T=`
New Design Partner Waitlist Application

Contact Information:
- Name: ${i}
- Email: ${t}
${o?`- Company/Project: ${o}`:""}
${s?`- Role: ${s}`:""}

Application Details:
- What are you building with AI today?
${l}

- What do you hope ContractSpec will solve for you?
${c}

- Team Size: ${p||"Not specified"}
- Timeline: ${f||"Not specified"}

Preferences:
- Open to 1:1 product/design sessions: ${h?"Yes":"No"}
- Okay with anonymized case studies: ${x?"Yes":"No"}

---
Submitted via ContractSpec waitlist application form
  `.trim(),R=`
    <div style="font-family: sans-serif; max-width: 720px; margin: 0 auto;">
      <h1 style="color: #8b5cf6;">New Design Partner Waitlist Application</h1>
      <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: ${a(i)}</li>
        <li>Email: ${a(t)}</li>
        ${o?`<li>Company/Project: ${a(o)}</li>`:""}
        ${s?`<li>Role: ${a(s)}</li>`:""}
      </ul>
      <h2 style="color: #8b5cf6; margin: 16px 0 8px;">Application Details</h2>
      <p style="margin: 0 0 8px; font-weight: 600;">What are you building with AI today?</p>
      <div style="border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; background: #f9fafb; white-space: pre-wrap; line-height: 1.6;">
        ${r(l)}
      </div>
      <p style="margin: 16px 0 8px; font-weight: 600;">What do you hope ContractSpec will solve for you?</p>
      <div style="border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; background: #f9fafb; white-space: pre-wrap; line-height: 1.6;">
        ${r(c)}
      </div>
      <ul style="padding-left: 16px; line-height: 1.6; margin: 16px 0;">
        <li>Team Size: ${a(p||"Not specified")}</li>
        <li>Timeline: ${a(f||"Not specified")}</li>
      </ul>
      <h2 style="color: #8b5cf6; margin: 16px 0 8px;">Preferences</h2>
      <div style="border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px; background: #f9fafb; line-height: 1.6;">
        ${r(I)}
      </div>
      <p style="color: #6b7280; font-size: 12px; margin-top: 20px;">Submitted via ContractSpec waitlist application form</p>
    </div>
  `;if(!(await n(u.config,{to:[u.config.teamInbox],subject:`New Design Partner Application: ${i} (${t})`,text:T,html:R,replyTo:t,context:"waitlist-application-team-notification"})).success)return{success:!1,text:v};return{success:!0,text:"Application submitted successfully!"}};export{L as subscribeToNewsletter,D as submitWaitlistApplication,O as submitContactForm,H as joinWaitlist};
