<x-admin.layout title="Clients">
    <div class="grid two">
        <div class="card">
            <h2>Create Client</h2>
            <form method="post" action="{{ route('admin.clients.store') }}">
                @csrf
                <label>Name</label><input name="name" required>
                <label>Email</label><input name="email" type="email">
                <label>Domains</label><input name="domains" placeholder="example.com, app.example.com">
                <label>Status</label><select name="status"><option>active</option><option>inactive</option><option>suspended</option></select>
                <button type="submit">Create</button>
            </form>
        </div>
        <div class="card">
            <h2>Clients</h2>
            <div class="table-wrap">
                <table><thead><tr><th>Client</th><th>Email</th><th>Domains</th><th>Status</th><th>Actions</th></tr></thead><tbody>
                    @foreach ($clients as $client)
                        <tr>
                            <td colspan="5">
                                <form method="post" action="{{ route('admin.clients.update', $client) }}" class="admin-inline-form">
                                    @csrf
                                    @method('PATCH')
                                    <input name="name" value="{{ $client->name }}" required>
                                    <input name="email" type="email" value="{{ $client->email }}">
                                    <input name="domains" value="{{ implode(', ', $client->domains ?? []) }}">
                                    <select name="status">
                                        @foreach (['active', 'inactive', 'suspended'] as $status)
                                            <option value="{{ $status }}" @selected($client->status === $status)>{{ $status }}</option>
                                        @endforeach
                                    </select>
                                    <button type="submit">Save</button>
                                </form>
                                <form method="post" action="{{ route('admin.clients.destroy', $client) }}" onsubmit="return confirm('Delete client?')">
                                    @csrf
                                    @method('DELETE')
                                    <button class="button danger" type="submit">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @endforeach
                </tbody></table>
            </div>
            {{ $clients->links() }}
        </div>
    </div>
</x-admin.layout>
