@extends('layouts.app')

@section('content')
    <div class="row g-4">
        <div class="col-lg-4">
            <div class="card shadow-sm">
                <div class="card-header fw-bold">Add Continent</div>
                <div class="card-body">
                    <form method="POST" action="{{ route('continents.store') }}" class="row g-2">
                        @csrf
                        <div class="col-12">
                            <label class="form-label">Name <span class="text-danger">*</span></label>
                            <input name="name" class="form-control" required maxlength="100" value="{{ old('name') }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Code <span class="text-danger">*</span></label>
                            <input name="code" class="form-control" required maxlength="10" placeholder="e.g. AS, EU" value="{{ old('code') }}">
                        </div>
                        <div class="col-12">
                            <label class="form-label">Status</label>
                            <select name="status" class="form-select">
                                <option value="1" {{ old('status', '1') == '1' ? 'selected' : '' }}>Active</option>
                                <option value="0" {{ old('status') === '0' ? 'selected' : '' }}>Inactive</option>
                            </select>
                        </div>
                        <div class="col-12 d-grid">
                            <button class="btn btn-success">Save</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-8">
            <div class="card shadow-sm">
                <div class="card-header fw-bold">Continents</div>
                <div class="card-body p-0">
                    <table class="table table-sm mb-0">
                        <thead>
                        <tr>
                            <th>Name</th>
                            <th>Code</th>
                            <th>Status</th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        @forelse($continents as $row)
                            <tr>
                                <td>{{ $row->name }}</td>
                                <td>{{ $row->code }}</td>
                                <td>{{ $row->status ? 'Active' : 'Inactive' }}</td>
                                <td class="text-end">
                                    <a href="{{ route('continents.edit', $row) }}" class="btn btn-sm btn-outline-secondary">Edit</a>
                                    <form method="POST" action="{{ route('continents.destroy', $row) }}" class="d-inline" onsubmit="return confirm('Delete? Countries in this continent will be removed.');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr><td colspan="4" class="text-center text-muted py-3">No continents yet.</td></tr>
                        @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
