@extends('layouts.app')

@section('title', 'Domains — TechCorp Manager')

@section('content')
<div data-tc-api-page="domains">
    <div class="tc-page-head-row">
        <div class="tc-page-head">
            <h2>Domains</h2>
            <p>Domain names and renewals. CRUD uses the API.</p>
        </div>
        <button type="button" class="tc-btn-primary" id="tc-add-domain">+ Add domain</button>
    </div>

    <div class="tc-card">
        <div class="tc-table-wrap">
            <table class="tc-table">
                <thead>
                    <tr>
                        <th>Domain</th>
                        <th>Registrar</th>
                        <th>Expires</th>
                        <th>Auto-renew</th>
                        <th>Server</th>
                        <th>Status</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($domains as $domain)
                        @php
                            $rowStyle = '';
                            if ($domain->expiration_date) {
                                if ($domain->expiration_date->isPast()) {
                                    $rowStyle = 'background:#fee2e2;';
                                } elseif ($domain->expiration_date->diffInDays(now()) <= 30) {
                                    $rowStyle = 'background:#fef3c7;';
                                }
                            }
                        @endphp
                        <tr style="{{ $rowStyle }}">
                            <td><strong>{{ $domain->name }}</strong></td>
                            <td>{{ $domain->registrar ?? '—' }}</td>
                            <td>{{ $domain->expiration_date?->format('M j, Y') ?? '—' }}</td>
                            <td>{{ $domain->auto_renew ? 'Yes' : 'No' }}</td>
                            <td>{{ $domain->server?->name ?? '—' }}</td>
                            <td><span class="tc-badge {{ $domain->status }}">{{ $domain->status }}</span></td>
                            <td class="tc-table-actions">
                                <button type="button" class="tc-btn-sm tc-edit-domain" data-id="{{ $domain->id }}">Edit</button>
                                <button type="button" class="tc-btn-sm danger tc-del-domain" data-id="{{ $domain->id }}">Delete</button>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="tc-empty">No domains yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
</div>
@endsection
