<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>ViZuTrade Trades Export</title>
        <style>
            body {
                color: #0f172a;
                font-family: DejaVu Sans, sans-serif;
                font-size: 12px;
                line-height: 1.4;
            }

            h1, h2, p {
                margin: 0;
            }

            .header {
                border-bottom: 2px solid #2563eb;
                margin-bottom: 18px;
                padding-bottom: 12px;
            }

            .brand {
                color: #1d4ed8;
                font-size: 24px;
                font-weight: bold;
            }

            .meta {
                color: #475569;
                margin-top: 4px;
            }

            .stats {
                margin-bottom: 18px;
                width: 100%;
            }

            .stats td {
                background: #eff6ff;
                border: 1px solid #bfdbfe;
                padding: 10px;
            }

            .stat-label {
                color: #475569;
                font-size: 10px;
                text-transform: uppercase;
            }

            .stat-value {
                color: #0f172a;
                font-size: 18px;
                font-weight: bold;
                margin-top: 4px;
            }

            table {
                border-collapse: collapse;
                width: 100%;
            }

            th {
                background: #2563eb;
                color: #ffffff;
                font-size: 10px;
                padding: 8px;
                text-align: left;
                text-transform: uppercase;
            }

            td {
                border-bottom: 1px solid #dbeafe;
                padding: 8px;
                vertical-align: top;
            }

            .profit {
                color: #1d4ed8;
                font-weight: bold;
            }

            .loss {
                color: #dc2626;
                font-weight: bold;
            }
        </style>
    </head>
    <body>
        <div class="header">
            <h1 class="brand">ViZuTrade</h1>
            <p class="meta">Trades export for {{ $user->name }} &middot; Generated {{ $generatedAt->format('M d, Y H:i') }}</p>
        </div>

        <table class="stats">
            <tr>
                <td>
                    <p class="stat-label">Total Trades</p>
                    <p class="stat-value">{{ $totals['total_trades'] }}</p>
                </td>
                <td>
                    <p class="stat-label">Wins</p>
                    <p class="stat-value">{{ $totals['wins'] }}</p>
                </td>
                <td>
                    <p class="stat-label">Losses</p>
                    <p class="stat-value">{{ $totals['losses'] }}</p>
                </td>
                <td>
                    <p class="stat-label">Total Profit/Loss</p>
                    <p class="stat-value">{{ number_format($totals['profit_loss'], 2) }}</p>
                </td>
            </tr>
        </table>

        <table>
            <thead>
                <tr>
                    <th>Symbol</th>
                    <th>Type</th>
                    <th>Status</th>
                    <th>Entry</th>
                    <th>Exit</th>
                    <th>Quantity</th>
                    <th>Profit/Loss</th>
                    <th>Opened</th>
                    <th>Notes</th>
                </tr>
            </thead>
            <tbody>
                @forelse ($trades as $trade)
                    <tr>
                        <td>{{ $trade->symbol }}</td>
                        <td>{{ ucfirst($trade->type) }}</td>
                        <td>{{ ucfirst($trade->status) }}</td>
                        <td>{{ $trade->entry_price }}</td>
                        <td>{{ $trade->exit_price ?? 'N/A' }}</td>
                        <td>{{ $trade->quantity }}</td>
                        <td class="{{ (float) $trade->profit_loss >= 0 ? 'profit' : 'loss' }}">
                            {{ $trade->profit_loss ?? 'N/A' }}
                        </td>
                        <td>{{ $trade->opened_at?->format('M d, Y') ?? $trade->created_at->format('M d, Y') }}</td>
                        <td>{{ $trade->notes ? str($trade->notes)->limit(90) : 'N/A' }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="9">No trades found.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </body>
</html>
