@extends('layouts.dashboard')

@section('title', 'Edit Admin')
@section('page-title', 'Edit Admin')

@section('content')
<div class="row justify-content-center">
    <div class="col-md-8 col-lg-6">
        <div class="table-container">
            <div class="mb-4">
                <h5 class="mb-1">Edit Administrator</h5>
                <p class="text-muted mb-0">Update admin account details</p>
            </div>

            <!-- Current Role Badge -->
            <div class="mb-4">
                @if($adminToEdit->isSuperAdmin())
                    <span class="badge badge-superadmin">
                        <i class="bi bi-shield-check me-1"></i>Current Role: Super Admin
                    </span>
                @else
                    <span class="badge badge-admin-role">
                        <i class="bi bi-person-badge me-1"></i>Current Role: Admin
                    </span>
                @endif
            </div>

            <form action="{{ route('dashboard.admins.update', $adminToEdit->id) }}" method="POST">
                @csrf
                @method('PUT')

                <div class="mb-4">
                    <label for="name" class="form-label fw-semibold">Full Name</label>
                    <input type="text" class="form-control @error('name') is-invalid @enderror" 
                           id="name" name="name" value="{{ old('name', $adminToEdit->name) }}" required>
                    @error('name')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="mb-4">
                    <label for="email" class="form-label fw-semibold">Email Address</label>
                    <input type="email" class="form-control @error('email') is-invalid @enderror" 
                           id="email" name="email" value="{{ old('email', $adminToEdit->email) }}" required>
                    @error('email')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="mb-4">
                    <label for="password" class="form-label fw-semibold">New Password</label>
                    <input type="password" class="form-control @error('password') is-invalid @enderror" 
                           id="password" name="password" minlength="8">
                    <div class="form-text">Leave blank to keep current password</div>
                    @error('password')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="mb-4">
                    <label for="role" class="form-label fw-semibold">Role</label>
                    <select class="form-select @error('role') is-invalid @enderror" id="role" name="role" required>
                        <option value="admin" {{ old('role', $adminToEdit->role) === 'admin' ? 'selected' : '' }}>Admin (Limited Access)</option>
                        <option value="superadmin" {{ old('role', $adminToEdit->role) === 'superadmin' ? 'selected' : '' }}>Super Admin (Full Access)</option>
                    </select>
                    @error('role')
                        <div class="invalid-feedback">{{ $message }}</div>
                    @enderror
                </div>

                <div class="alert alert-warning">
                    <i class="bi bi-exclamation-triangle me-2"></i>
                    <strong>Note:</strong> Changing the role will affect this admin's permissions immediately.
                </div>

                <div class="d-flex gap-3">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-check-lg me-2"></i>Update Admin
                    </button>
                    <a href="{{ route('dashboard.admins') }}" class="btn btn-outline-secondary">
                        Cancel
                    </a>
                </div>
            </form>

            <!-- Quick Links for Non-SuperAdmins -->
            @if(!$adminToEdit->isSuperAdmin())
            <hr class="my-4">
            <div class="d-flex gap-3">
                <a href="{{ route('dashboard.admins.permissions', $adminToEdit->id) }}" class="btn btn-outline-primary">
                    <i class="bi bi-key me-2"></i>Manage Permissions
                </a>
                <a href="{{ route('dashboard.admins.limits', $adminToEdit->id) }}" class="btn btn-outline-primary">
                    <i class="bi bi-sliders me-2"></i>Manage Limits
                </a>
            </div>
            @endif
        </div>
    </div>
</div>
@endsection
