@php
    use App\Services\CompanyEmailDetails;

    // Get company details using global helper function
    $companyDetails = CompanyEmailDetails::getCompanyEmailDetails();

    // Extract variables for easier use in template
    $logoPath = $companyDetails['logoPath'];
    $companyName = $companyDetails['companyName'];
    $companyAddress = $companyDetails['companyAddress'];
    $companyCity = $companyDetails['companyCity'];
    $companyState = $companyDetails['companyState'];
    $companyPostCode = $companyDetails['companyPostCode'];
    $companyCountry = $companyDetails['companyCountry'];
    $companyPhone = $companyDetails['companyPhone'];
    $companyEmail = $companyDetails['companyEmail'];

    // Format full address
    $fullAddress = $companyAddress;
    if (!empty($companyCity)) {
        $fullAddress .= ', ' . $companyCity;
    }
    if (!empty($companyState)) {
        $fullAddress .= ', ' . $companyState;
    }
    if (!empty($companyPostCode)) {
        $fullAddress .= ' ' . $companyPostCode;
    }
    if (!empty($companyCountry)) {
        $fullAddress .= ', ' . $companyCountry;
    }
    // Set defaults for variables that might not be provided
    if (!isset($subject)) {
        $subject = 'Leave Request Update';
    }

    // Default status configuration in case it's not provided
if (!isset($status_config)) {
    $status_config = [
        'status_text' => 'Unknown',
        'color' => '#6B7280', // Gray
        'background' => 'linear-gradient(135deg, #F3F4F6 0%, #E5E7EB 100%)',
        'icon' => '📄',
        'message' => 'Leave request status information.',
        ];
    }
@endphp

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>{{ $subject }}</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
        rel="stylesheet">
    <style>
        * {
            padding: 0;
            margin: 0;
            font-family: 'Inter', sans-serif !important;
            box-sizing: border-box;
        }

        body {
            background-color: #f8f9fa;
            padding: 20px 0;
        }

        #email-body {
            min-width: 600px;
            width: 600px;
            max-width: 600px;
            margin: 0 auto;
            background-color: #ffffff;
            font-family: 'Inter', sans-serif !important;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            overflow: hidden;
        }

        #email-header {
            padding: 18px 25px;
            background: #fff !important;
            text-align: left;
            position: relative;
        }

        #email-header::after {
            content: '';
            position: absolute;
            top: 0;
            right: 0;
            width: 100px;
            height: 100%;
            background: rgba(255, 255, 255, 0.1);
            transform: skew(-15deg);
            transform-origin: top right;
        }

        #email-header img {
            height: 54px;
            width: auto;
            display: inline-block;
        }

        #email-header h2 {
            color: white;
            margin: 0;
            font-weight: 700;
            font-size: 24px;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        }

        #email-content {
            padding: 42px 34px;
            color: #333333;
        }

        .greeting-section {
            font-size: 14px;
            margin-bottom: 18px;
            color: #6b7280;
        }

        .greeting-section strong {
            color: #1f2937;
            font-weight: 600;
        }

        .notification-title {
            font-size: 22px;
            font-weight: 700;
            margin-bottom: 20px;
            color: {{ $status_config['color'] }};
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .notification-title::before {
            content: "{{ $status_config['icon'] }}";
            font-size: 24px;
        }

        .alert-box {
            background: {{ $status_config['background'] }};
            border: 1px solid {{ $status_config['color'] }};
            border-radius: 8px;
            padding: 16px;
            margin-bottom: 24px;
            position: relative;
        }

        .alert-box::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 4px;
            background: {{ $status_config['color'] }};
            border-radius: 4px 0 0 4px;
        }

        .alert-box p {
            margin: 0;
            font-size: 14px;
            color: {{ $status_config['color'] }};
            font-weight: 500;
        }

        .info-card {
            background: #f9fafb;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 20px;
            margin-bottom: 20px;
            position: relative;
            transition: transform 0.2s ease;
        }

        .info-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .info-card h3 {
            color: #1f2937;
            margin-bottom: 12px;
            font-weight: 600;
            font-size: 16px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .leave-details h3::before {
            content: '📅';
            font-size: 18px;
        }

        .employee-details h3::before {
            content: '👤';
            font-size: 18px;
        }

        .info-card p {
            margin-bottom: 8px;
            font-size: 14px;
            color: #374151;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .info-card p:last-child {
            margin-bottom: 0;
        }

        .info-card strong {
            font-weight: 600;
            color: #1f2937;
            min-width: 120px;
        }

        .info-value {
            font-weight: 500;
            color: #4b5563;
        }

        .status-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            background: {{ $status_config['background'] }};
            color: {{ $status_config['color'] }};
            border: 1px solid {{ $status_config['color'] }};
        }

        .email-content-area p {
            font-size: 14px;
            margin-bottom: 15px;
            line-height: 1.6;
            color: #4b5563;
        }

        .divider {
            height: 1px;
            background: linear-gradient(90deg, transparent 0%, #e5e7eb 50%, transparent 100%);
            margin: 24px 0;
        }

        .footer-message {
            background: #f0f9ff;
            border: 1px solid #0ea5e9;
            border-radius: 8px;
            padding: 16px;
            margin: 24px 0;
            position: relative;
        }

        .footer-message::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 4px;
            background: #0ea5e9;
            border-radius: 4px 0 0 4px;
        }

        .footer-message p {
            margin: 0;
            font-size: 14px;
            color: #0c4a6e;
            font-weight: 500;
        }

        #email-footer {
            margin-top: 20px;
        }

        #tagline-section {
            background-color: #EDEDED;
            padding: 16px;
            text-align: center;
            font-size: 13px;
            color: #6b7280;
        }

        .big-tagline {
            margin-top: 8px;
            font-size: 14px;
            color: #374151;
        }

        .big-tagline a {
            color: #787f83;
            font-weight: 700;
            text-decoration: none;
        }

        .company-details {
            padding: 20px;
            text-align: center;
        }

        .footer-logo {
            height: 35px;
           
            margin-bottom: 12px;
        }

        .company-title {
            font-size: 14px;
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 8px;
        }

        .company-address-contact {
            font-size: 12px;
            color: #6b7280;
            line-height: 1.5;
        }
    </style>
</head>

<body>
    <div id="email-body">
        <div id="email-header">
            @if (!empty($logoPath) && file_exists(public_path($logoPath)))
                <img src="{{ url($logoPath) }}" alt="WMS Logo" />
            @else
                <h2>{{ $companyName }}</h2>
            @endif
        </div>

        <div id="email-content">
            <div class="greeting-section">
                Hello, <strong>{{ $name ?? 'Employee' }}</strong>
            </div>

            <div class="notification-title">
                {{ $subject }}
            </div>

            <div class="alert-box">
                <p>{{ $status_config['message'] }}</p>
            </div>

            <div class="email-content-area">
                <p>{{ $message ?? 'Your leave request status has been updated.' }}</p>
            </div>

            <div class="info-card leave-details">
                <h3>Leave Details</h3>
                @if (isset($ticket_details) && is_array($ticket_details))
                    @foreach ($ticket_details as $key => $value)
                        <p>
                            <strong>{{ $key }}:</strong>
                            <span class="info-value">
                                @if ($key == 'Status')
                                    <span class="status-badge">{{ $value }}</span>
                                @else
                                    {{ $value }}
                                @endif
                            </span>
                        </p>
                    @endforeach
                @else
                    <p><strong>Request ID:</strong> <span class="info-value">{{ $request_id ?? 'N/A' }}</span></p>
                    <p><strong>Leave Type:</strong> <span class="info-value">{{ $leave_type ?? 'N/A' }}</span></p>
                    <p><strong>Start Date:</strong> <span class="info-value">{{ $start_date ?? 'N/A' }}</span></p>
                    <p><strong>End Date:</strong> <span class="info-value">{{ $end_date ?? 'N/A' }}</span></p>
                    <p><strong>Status:</strong> <span class="status-badge">{{ $status_config['status_text'] }}</span>
                    </p>
                @endif
            </div>

            <div class="divider"></div>

            <div class="footer-message">
                <p>💡 If you have any questions or need further information, please contact your manager or HR
                    department.</p>
            </div>
        </div>

        <div id="email-footer">
            <div id="tagline-section">
                <p>This is an auto-generated email. Please do not reply.</p>
                <p class="big-tagline">For questions or support, contact
                    <a href="mailto:{{ $companyEmail }}">{{ $companyEmail }}</a>
                </p>
            </div>

            <div class="company-details">
                @if (!empty($logoPath) && file_exists(public_path($logoPath)))
                    <img src="{{ url($logoPath) }}" class="footer-logo" alt="Logo">
                @endif
                <div class="company-title">{{ $companyName }}</div>
                <div class="company-address-contact">
                    {{ $fullAddress }}<br />
                    Call: {{ $companyPhone }}
                </div>
            </div>
        </div>
    </div>
</body>

</html>
