const moment = require("moment");

/* eslint-disable no-useless-escape */
module.exports = {
	html: (leaveApplication) => {
		const leaveBalanceSection =
			leaveApplication.leavetype_name !== "Sick Leave" && leaveApplication.leavetype_name !== "Leave Without Pay"
				? `
<!-- Leave balance section -->
<tr>
  <td style="padding:0 24px 30px 24px;">
    <table width="100%" cellpadding="10" cellspacing="0" role="presentation" style="background-color:#ffedd5; border-radius:8px; font-size:13px; color:#7c2d12; border-left:6px solid #fb923c;">
      <tr>
        <td align="left" width="33%" style="font-weight:500; color:#7c2d12; padding:12px 16px;">
          <div style="font-weight:700; margin-bottom:4px;">Your leave days</div>
          ${
						leaveApplication.leave_balance > 0
							? leaveApplication.total_leave_days === 1
								? "1 day has been returned to your leave balance."
								: `${leaveApplication.total_leave_days} days have been returned to your leave balance.`
							: "No days have been returned to your leave balance."
					}
        </td>
      </tr>
    </table>
  </td>
</tr>
`
				: "";

		return `<!DOCTYPE html>
        <html lang="id">
        <head>
          <meta charset="UTF-8" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Leave Application Cancelled</title>
          <style>
            body, table, td, a {
              -webkit-text-size-adjust: 100%;
              -ms-text-size-adjust: 100%;
            }
            table, td {
              mso-table-lspace: 0pt;
              mso-table-rspace: 0pt;
            }
            table {
              border-collapse: separate !important; /* penting untuk border radius */
              border-spacing: 0;
              border-radius: 12px;
            }
            img {
              -ms-interpolation-mode: bicubic;
            }
            .ExternalClass {
              width: 100%;
              line-height: 100%;
            }
            a[x-apple-data-detectors] {
              color: inherit !important;
              text-decoration: none !important;
              font-size: inherit !important;
              font-family: inherit !important;
              font-weight: inherit !important;
              line-height: inherit !important;
            }
          </style>
        </head>
        <body style="margin:0; padding:0; background-color:#f8fafc; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; color:#334155;">
          <center>
            <table width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffedd5" style="padding:20px 0; min-width:320px;">
              <tr>
                <td align="center">
                  <table width="600" cellpadding="0" cellspacing="0" border="0" bgcolor="#ffffff" 
                         style="border-radius:12px; overflow:hidden; border:1px solid #e2e8f0; max-width:600px;">
                    
                    <!-- Header -->
                    <tr bgcolor="#fb923c"> <!-- orange cerah untuk cancel -->
                      <td style="padding:18px 24px; text-align:left; color:#fff;">
                        <h2 style="margin:0; font-weight:700; font-size:18px; font-family: Arial, sans-serif;">Leave Application Cancelled</h2>
                        <p style="margin:6px 0 0 0; font-weight:400; font-size:14px; color:#fff; font-family: Arial, sans-serif;">
                          Your leave request has been cancelled.
                        </p>
                      </td>
                    </tr>
        
                    <!-- Dates info -->
                    <tr>
                      <td style="padding:24px;">
                        <table width="100%" cellpadding="10" cellspacing="0" role="presentation" 
                               style="background-color:#ffedd5; border-radius:8px; font-size:13px; color:#7c2d12; border-left:6px solid #fb923c;">
                          <tr>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px; font-family: Arial, sans-serif;">Submitted Date</div>
                              ${moment(leaveApplication.submitted_date).format(
																"YYYY-MM-DD"
															)}
                            </td>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px; font-family: Arial, sans-serif;">Cancellation Date</div>
                              ${
																moment(
																	leaveApplication.cancellation_date
																).format("YYYY-MM-DD") || "-"
															}
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
        
                    <!-- Leave details -->
                    <tr>
                      <td style="padding:0 24px 20px 24px;">
                        <table width="100%" cellpadding="10" cellspacing="0" role="presentation"
                               style="background-color:#ffedd5; border-radius:8px; font-size:13px; color:#7c2d12; border-left:6px solid #fb923c;">
                          <tr>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px; font-family: Arial, sans-serif;">Leave Type</div>
                              ${leaveApplication?.leavetype_name}
                            </td>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px;">Duration</div>
                              ${leaveApplication.total_leave_days > 1 ? `${leaveApplication.total_leave_days} days` : `${leaveApplication.total_leave_days} day`}
                            </td>
                          </tr>
                          <tr>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px;">From</div>
                              ${moment(leaveApplication.from_date).format(
																"YYYY-MM-DD"
															)}
                            </td>
                            <td width="50%" valign="top" style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px;">To</div>
                              ${moment(leaveApplication.to_date).format(
																"YYYY-MM-DD"
															)}
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
        
                    <!-- Reason -->
                    <tr>
                      <td style="padding:0 24px 20px 24px;">
                        <table width="100%" cellpadding="10" cellspacing="0" role="presentation"
                               style="background-color:#ffedd5; border-radius:8px; font-size:13px; color:#7c2d12; border-left:6px solid #fb923c;">
                          <tr>
                            <td style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px;">Reason</div>
                              ${leaveApplication?.reason || "-"}
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
        
                    <tr>
                      <td style="padding:0 24px 20px 24px;">
                        <table width="100%" cellpadding="10" cellspacing="0" role="presentation"
                               style="background-color:#ffedd5; border-radius:8px; font-size:13px; color:#7c2d12; border-left:6px solid #fb923c;">
                          <tr>
                            <td style="font-weight:600; padding:12px 16px;">
                              <div style="font-weight:700; margin-bottom:6px;">Cancel Reason</div>
                              ${leaveApplication?.cancel_reason || "-"}
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                    
                    ${leaveBalanceSection}
        
                    <!-- Cancelled by -->
                    <tr>
                      <td style="font-weight: 600; padding:20px 24px 0px;">Cancelled by:</td>
                    </tr>
                    <tr>
                      <td style="padding:20px 24px;">
                        <table width="100%" cellpadding="0" cellspacing="0" role="presentation" style="border-spacing:0;">
                          <tr>
                            <td width="48" valign="top" style="padding-right:12px;">
                              <div style="width:40px; height:40px; background:#ffedd5; border-radius:50%; text-align:center; line-height:40px; font-size:20px; color:#7c2d12; font-family: Arial, sans-serif;">
                                &#128100;
                              </div>
                            </td>
                            <td valign="middle" style="font-family: Arial, sans-serif;">
                              <strong style="font-size:15px; color:#7c2d12;">${
																leaveApplication?.leave_approver_name || "N/A"
															}</strong><br />
                              <span style="font-size:13px; color:#a65213;">${
																leaveApplication?.leave_approver_designation_territory ||
																"N/A"
															}</span>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>
        
                    <!-- Footer -->
                    <tr>
                      <td style="font-size:12px; color:#94a3b8; padding:12px 24px; text-align:center;">
                        This is an automated notification. Please do not reply.
                      </td>
                    </tr>
        
                  </table>
                </td>
              </tr>
            </table>
          </center>
        </body>
        </html>`;
	},
};
