@extends('client.layouts.dashboard')

@section('title', 'My Profile')

@section('content')
<div class="row g-4">
    <!-- Profile Info -->
    <div class="col-lg-4">
        <div class="table-card">
            <div class="card-body p-4 text-center">
                <div class="rounded-circle bg-primary text-white d-flex align-items-center justify-content-center mx-auto mb-3" style="width: 100px; height: 100px; font-size: 2.5rem;">
                    {{ strtoupper(substr($admin->name, 0, 1)) }}
                </div>
                <h5 class="mb-1">{{ $admin->name }}</h5>
                <p class="text-muted mb-2">{{ $admin->email }}</p>
                <span class="badge bg-{{ $admin->role === 'owner' ? 'danger' : 'primary' }} px-3 py-2">
                    <i class="bi bi-{{ $admin->role === 'owner' ? 'star-fill' : 'person-badge' }} me-1"></i>
                    {{ ucfirst($admin->role) }}
                </span>

                <div class="border-top mt-4 pt-3">
                    <div class="row text-start small">
                        <div class="col-6">
                            <div class="text-muted">Organization</div>
                            <div class="fw-medium">{{ $admin->client->name }}</div>
                        </div>
                        <div class="col-6">
                            <div class="text-muted">Status</div>
                            <div class="fw-medium">
                                @if($admin->is_active)
                                <span class="text-success"><i class="bi bi-check-circle me-1"></i>Active</span>
                                @else
                                <span class="text-secondary"><i class="bi bi-x-circle me-1"></i>Inactive</span>
                                @endif
                            </div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Joined</div>
                            <div class="fw-medium">{{ $admin->created_at->format('M d, Y') }}</div>
                        </div>
                        <div class="col-6 mt-3">
                            <div class="text-muted">Last Login</div>
                            <div class="fw-medium">{{ $admin->last_login_at ? $admin->last_login_at->diffForHumans() : 'N/A' }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Edit Forms -->
    <div class="col-lg-8">
        <!-- Update Profile -->
        <div class="table-card mb-4">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-person me-2"></i>Update Profile</h5>
            </div>
            <div class="card-body p-4">
                <form method="POST" action="{{ route('client.profile.update') }}">
                    @csrf
                    @method('PUT')

                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label">Full Name <span class="text-danger">*</span></label>
                            <input type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name', $admin->name) }}" required>
                            @error('name')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">Email Address <span class="text-danger">*</span></label>
                            <input type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email', $admin->email) }}" required>
                            @error('email')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>
                    </div>

                    <div class="mt-4">
                        <button type="submit" class="btn btn-primary">
                            <i class="bi bi-check-lg me-2"></i>Save Changes
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Change Password -->
        <div class="table-card">
            <div class="card-header">
                <h5 class="mb-0"><i class="bi bi-shield-lock me-2"></i>Change Password</h5>
            </div>
            <div class="card-body p-4">
                <form method="POST" action="{{ route('client.profile.password') }}">
                    @csrf
                    @method('PUT')

                    <div class="row g-3">
                        <div class="col-md-12">
                            <label class="form-label">Current Password <span class="text-danger">*</span></label>
                            <input type="password" class="form-control @error('current_password') is-invalid @enderror" name="current_password" required>
                            @error('current_password')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">New Password <span class="text-danger">*</span></label>
                            <input type="password" class="form-control @error('password') is-invalid @enderror" name="password" required minlength="8">
                            @error('password')
                            <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                            <div class="form-text">Minimum 8 characters</div>
                        </div>

                        <div class="col-md-6">
                            <label class="form-label">Confirm New Password <span class="text-danger">*</span></label>
                            <input type="password" class="form-control" name="password_confirmation" required>
                        </div>
                    </div>

                    <div class="mt-4">
                        <button type="submit" class="btn btn-warning">
                            <i class="bi bi-key me-2"></i>Change Password
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection