import { getCurrentYear } from "../../../utils/helpers"

export const projectThresholdAlertEmail = (
  projectName: string,
  clientName: string,
  budgetAmount: number,
  spentAmount: number,
  thresholdPercentage: number,
  remainingBudget: number,
): string => {
  const spentPercentage = ((spentAmount / budgetAmount) * 100).toFixed(1)
  const formattedBudget = budgetAmount.toLocaleString()
  const formattedSpent = spentAmount.toLocaleString()
  const formattedRemaining = remainingBudget.toLocaleString()

  return `
<!DOCTYPE html>
<html lang="en" class="no-js">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>Project Budget Alert - Costifys</title>
    <style type="text/css" rel="stylesheet">
      body,
      html {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        padding: 0;
        margin: 0;
      }
      *,
      ::after,
      ::before {
        box-sizing: border-box;
      }
      body,
      html,
      p {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Helvetica, Arial, sans-serif;
        color: #111111;
        font-size: 16px;
        line-height: 22px;
      }
      body {
        background: #fafafa;
      }
      center {
        width: 600px;
        text-align: center;
        margin: 50px auto;
      }
      .email-top {
        height: 3px;
        background-color: #111111;
        margin-top: 36px;
      }
      .email-bottom {
        margin-bottom: 36px;
        height: 3px;
        background-color: #111111;
      }
      .email-body {
        padding: 50px;
        text-align: left;
        background: #fff;
      }
      h1 {
        margin-top: -20px;
        margin-bottom: 0;
      }
      img.blog-img {
        border-radius: 10px;
        margin-bottom: 15px;
        object-fit: cover;
        max-width: 100%;
      }
      h2 {
        margin-top: 0;
        line-height: 36px;
        font-size: 24px;
        font-weight: 700;
        margin-bottom: 5px;
      }
      .btn {
        border-radius: 6px;
        background-color: #2f855a;
        color: #fff;
        text-align: center;
        font-size: 16px;
        letter-spacing: 0;
        line-height: 18px;
        padding: 16px 20px;
        display: inline-block;
        min-width: 200px;
      }
      .btn:focus,
      .btn:hover {
        color: #fff;
        opacity: 0.85;
      }
      p {
        margin-top: 0;
      }
      ul {
        list-style: decimal;
        padding-left: 26px;
        margin-top: 0;
        margin-bottom: 20px;
      }
      li {
        padding-left: 10px;
      }
      .f-18 {
        font-size: 18px;
      }
      a {
        text-decoration: none;
        color: #262f37;
      }
      a:hover {
        color: #2f855a;
      }
      .downloads {
        height: 50px;
      }
      .warning-box {
        background-color: #fff3cd;
        border: 1px solid #ffeaa7;
        color: #856404;
        padding: 20px;
        border-radius: 6px;
        margin: 25px 0;
      }
      .project-details {
        background-color: #f8f9fa;
        border: 1px solid #dee2e6;
        padding: 20px;
        border-radius: 6px;
        margin: 25px 0;
      }
      @media (max-width: 650px) {
        center {
          width: 430px;
        }
        img.blog-img {
          height: 170px;
        }
      }
      @media (max-width: 420px) {
        center {
          width: 100%;
          padding: 0 15px;
          margin: 30px 0;
        }
        .email-body {
          padding: 30px 20px;
        }
        .downloads {
          height: auto;
        }
      }
    </style>
  </head>
  <body>
    <center>
      <img src="cid:unique@cidLogo" alt="Costify Logo" height="50" />
      <div class="email-top"></div>
      <div class="email-body">
        <p
          style="
            margin-top: 0;
            margin-bottom: 25px;
            font-size: 20px;
            line-height: 22px;
            font-weight: bold;
            color: #111111;
          "
        >
          Project Budget Alert
        </p>
        <p style="margin-bottom: 25px">
          A project in your company has reached its budget threshold limit and requires your attention.
        </p>
        
        <div class="warning-box">
          <strong>⚠️ Threshold Alert:</strong> The project "${projectName}" has reached ${spentPercentage}% of its budget, exceeding the ${thresholdPercentage}% threshold limit.
        </div>

        <div class="project-details">
          <h3 style="margin-top: 0; margin-bottom: 15px; color: #111111;">Project Details</h3>
          <p style="margin-bottom: 10px;"><strong>Project Name:</strong> ${projectName}</p>
          <p style="margin-bottom: 10px;"><strong>Client:</strong> ${clientName}</p>
          <p style="margin-bottom: 10px;"><strong>Total Budget:</strong> $${formattedBudget}</p>
          <p style="margin-bottom: 10px;"><strong>Amount Spent:</strong> $${formattedSpent} (${spentPercentage}%)</p>
          <p style="margin-bottom: 10px;"><strong>Remaining Budget:</strong> $${formattedRemaining}</p>
          <p style="margin-bottom: 0;"><strong>Threshold Limit:</strong> ${thresholdPercentage}%</p>
        </div>

        <p style="margin-bottom: 25px">
          Please review the project expenses and take appropriate action to ensure the project stays within budget. Consider adjusting the project scope or budget allocation as needed.
        </p>

        <div>
          <p style="margin-bottom: 0px">Regards,</p>
          <p style="margin-bottom: 0px">Support Team</p>
          <p style="margin-bottom: 0px">Costifys App</p>
          <p style="margin-bottom: 0px">
            <a href="https://www.costifys.com/">https://www.costifys.com/</a>
          </p>
        </div>
      </div>
      <div class="email-bottom"></div>
      <div class="email-footer">
        <img src="cid:unique@cidLogo" alt="Costify Logo" height="50" />
        <p style="line-height: 18px">${getCurrentYear()} Costifys | All Rights Reserved.</p>
      </div>
    </center>
  </body>
</html>
    `
}
