/**
 * Dealer Proposal Required Email Template
 * Sent when dealer is assigned to submit proposal (Step 1)
 * This is different from approval request - dealer needs to submit, not approve
 */

import { DealerProposalRequiredData } from './types';
import { getEmailFooter, getPrioritySection, getEmailHeader, HeaderStyles, getResponsiveStyles, wrapRichText, getEmailContainerStyles, getCustomMessageSection } from './helpers';
import { getBrandedHeader } from './branding.config';

export function getDealerProposalRequiredEmail(data: DealerProposalRequiredData): string {
  return `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="format-detection" content="telephone=no">
    <title>Proposal Required</title>
    ${getResponsiveStyles()}
</head>
<body style="margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; background-color: #f4f4f4;">
    <table role="presentation" style="width: 100%; border-collapse: collapse; background-color: #f4f4f4;" cellpadding="0" cellspacing="0">
        <tr>
            <td style="padding: 40px 0;">
                <table role="presentation" class="email-container" style="${getEmailContainerStyles()}" cellpadding="0" cellspacing="0">
                    <!-- Header -->
                    ${getEmailHeader(getBrandedHeader({
                      title: 'Proposal Required',
                      ...HeaderStyles.info
                    }))}
                    
                    <!-- Content -->
                    <tr>
                        <td class="email-content" style="padding: 40px 30px;">
                            <p style="margin: 0 0 20px; color: #333333; font-size: 16px; line-height: 1.6;">
                                Dear <strong style="color: #667eea;">${data.dealerName}</strong>,
                            </p>
                            
                            <p style="margin: 0 0 30px; color: #666666; font-size: 16px; line-height: 1.6;">
                                You have been assigned to submit a proposal for a new claim request. <strong style="color: #333333;">${data.initiatorName}</strong> has created a claim request that requires your proposal submission.
                            </p>
                            
                            <!-- Request Details Box -->
                            <table role="presentation" style="width: 100%; border-collapse: collapse; background-color: #f8f9fa; border-radius: 6px; margin-bottom: 30px;" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="padding: 25px;">
                                        <h2 style="margin: 0 0 20px; color: #333333; font-size: 18px; font-weight: 600;">Request Details</h2>
                                        
                                        <table role="presentation" style="width: 100%; border-collapse: collapse;" cellpadding="0" cellspacing="0">
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px; width: 140px;">
                                                    <strong>Request ID:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.requestId}
                                                </td>
                                            </tr>
                                            ${data.requestTitle ? `
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Title:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.requestTitle}
                                                </td>
                                            </tr>
                                            ` : ''}
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Activity Name:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px; font-weight: 600;">
                                                    ${data.activityName}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Activity Type:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.activityType}
                                                </td>
                                            </tr>
                                            ${data.activityDate ? `
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Activity Date:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.activityDate}
                                                </td>
                                            </tr>
                                            ` : ''}
                                            ${data.location ? `
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Location:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.location}
                                                </td>
                                            </tr>
                                            ` : ''}
                                            ${data.estimatedBudget ? `
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Estimated Budget:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ₹${data.estimatedBudget.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}
                                                </td>
                                            </tr>
                                            ` : ''}
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Requestor:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.initiatorName}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Created On:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.requestDate}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Time:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px;">
                                                    ${data.requestTime}
                                                </td>
                                            </tr>
                                            ${data.tatHours ? `
                                            <tr>
                                                <td style="padding: 8px 0; color: #666666; font-size: 14px;">
                                                    <strong>Due Date:</strong>
                                                </td>
                                                <td style="padding: 8px 0; color: #333333; font-size: 14px; font-weight: 600;">
                                                    ${data.dueDate || 'Please submit as soon as possible'}
                                                </td>
                                            </tr>
                                            ` : ''}
                                        </table>
                                    </td>
                                </tr>
                            </table>
                            
                            <!-- Custom Message Section -->
                            ${getCustomMessageSection(data.customMessage)}
                            
                            <!-- Description (supports rich text HTML including tables) -->
                            ${data.requestDescription ? `
                            <div style="margin-bottom: 30px;">
                                <h3 style="margin: 0 0 15px; color: #333333; font-size: 16px; font-weight: 600;">Request Description:</h3>
                                <div style="padding: 15px; background-color: #f8f9fa; border-left: 4px solid #667eea; border-radius: 4px; overflow-x: auto;">
                                    ${wrapRichText(data.requestDescription)}
                                </div>
                            </div>
                            ` : ''}
                            
                            <!-- What You Need to Submit -->
                            <div style="padding: 20px; background-color: #fff3cd; border-left: 4px solid #ffc107; border-radius: 4px; margin-bottom: 30px;">
                                <h3 style="margin: 0 0 10px; color: #856404; font-size: 16px; font-weight: 600;">📋 What You Need to Submit:</h3>
                                <ul style="margin: 10px 0 0 0; padding-left: 20px; color: #856404; font-size: 14px; line-height: 1.8;">
                                    <li><strong>Proposal Document</strong> - Detailed proposal with requested information</li>
                                    <li><strong>Cost Breakdown</strong> - Itemized list of costs and expenses</li>
                                    <li><strong>Timeline</strong> - Expected completion date or number of days</li>
                                    <li><strong>Supporting Documents</strong> - Any additional documents or attachments</li>
                                    <li><strong>Comments</strong> - Any additional information or clarifications</li>
                                </ul>
                            </div>
                            
                            <!-- Priority Section (dynamic) -->
                            ${getPrioritySection(data.priority)}
                            
                            <!-- View Details Button -->
                            <table role="presentation" style="width: 100%; border-collapse: collapse; margin-bottom: 20px;" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td style="text-align: center;">
                                        <a href="${data.viewDetailsLink}" class="cta-button" style="display: inline-block; padding: 15px 40px; background-color: #1a1a1a; color: #ffffff; text-decoration: none; text-align: center; border-radius: 6px; font-size: 16px; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); min-width: 200px;">
                                            Submit Proposal
                                        </a>
                                    </td>
                                </tr>
                            </table>
                            
                            <p style="margin: 0; color: #666666; font-size: 14px; line-height: 1.6; text-align: center;">
                                Click the button above to view the request details and submit your proposal.
                            </p>
                        </td>
                    </tr>
                    
                    ${getEmailFooter(data.companyName)}
                </table>
            </td>
        </tr>
    </table>
</body>
</html>
  `;
}

