<!DOCTYPE html>
<html lang="hr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Obavijest o isteku ugovora</title>
    <style>
        body { font-family: Arial, sans-serif; font-size: 14px; color: #333; }
        .container { max-width: 700px; margin: 0 auto; padding: 20px; }
        .header { border-bottom: 2px solid #cc6600; padding-bottom: 10px; margin-bottom: 20px; }
        .footer { border-top: 1px solid #ddd; margin-top: 30px; padding-top: 15px; font-size: 12px; color: #777; }
        table { width: 100%; border-collapse: collapse; margin: 15px 0; }
        th { background: #cc6600; color: white; padding: 8px 10px; text-align: left; }
        td { padding: 7px 10px; border-bottom: 1px solid #eee; }
        tr:nth-child(even) td { background: #fff8f0; }
        .warning { background: #fff3cd; border-left: 4px solid #cc6600; padding: 10px 15px; margin: 15px 0; }
        .danger { background: #fde8e8; border-left: 4px solid #cc0000; padding: 10px 15px; margin: 15px 0; }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h2>Obavijest o isteku ugovora</h2>
    </div>

    <p>Poštovani,</p>
    <p>Šaljemo Vam pregled ugovora koji uskoro ističu ili su već istekli.</p>

    @if(!empty($expire) && count($expire) > 0)
    <div class="warning">
        <strong>Ugovori koji uskoro ističu (u idućih 30 dana): {{ count($expire) }}</strong>
    </div>
    <table>
        <thead>
            <tr>
                <th>Klijent</th>
                <th>Ugovor br.</th>
                <th>Datum početka</th>
                <th>Trajanje</th>
                <th>Datum isteka</th>
            </tr>
        </thead>
        <tbody>
            @foreach($expire as $contract)
            @php
                $startDate = \Carbon\Carbon::parse($contract->contract_start_date);
                $endDate = $startDate->copy()->addMonths($contract->duration);
            @endphp
            <tr>
                <td>{{ $contract->customer_name }}</td>
                <td>{{ $contract->contract_no }}</td>
                <td>{{ $startDate->format('d.m.Y') }}</td>
                <td>{{ $contract->duration }} mj.</td>
                <td>{{ $endDate->format('d.m.Y') }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @endif

    @if(!empty($expired) && count($expired) > 0)
    <div class="danger">
        <strong>Istekli ugovori: {{ count($expired) }}</strong>
    </div>
    <table>
        <thead>
            <tr>
                <th>Klijent</th>
                <th>Ugovor br.</th>
                <th>Datum početka</th>
                <th>Trajanje</th>
                <th>Datum isteka</th>
            </tr>
        </thead>
        <tbody>
            @foreach($expired as $contract)
            @php
                $startDate = \Carbon\Carbon::parse($contract->contract_start_date);
                $endDate = $startDate->copy()->addMonths($contract->duration);
            @endphp
            <tr>
                <td>{{ $contract->customer_name }}</td>
                <td>{{ $contract->contract_no }}</td>
                <td>{{ $startDate->format('d.m.Y') }}</td>
                <td>{{ $contract->duration }} mj.</td>
                <td>{{ $endDate->format('d.m.Y') }}</td>
            </tr>
            @endforeach
        </tbody>
    </table>
    @endif

    @if((empty($expire) || count($expire) === 0) && (empty($expired) || count($expired) === 0))
    <p>Nema ugovora koji uskoro ističu ili su istekli.</p>
    @endif

    <p>S poštovanjem,<br>
    <strong>InOffice sustav</strong></p>

    <div class="footer">
        <p>Ova poruka je automatski generirana. Datum: {{ now()->format('d.m.Y H:i') }}</p>
    </div>
</div>
</body>
</html>
