@extends('backEnd.layouts.master')
@section('title','Admin Profile')
@section('content')
<div class="container-fluid">
    
    <!-- start page title -->
    <div class="row">
        <div class="col-12">
            <div class="page-title-box">
                <h4 class="page-title">Change Admin Credentials</h4>
            </div>
        </div>       
    </div>       
    <!-- end page title --> 

   <div class="row">
    <div class="col-lg-8">
        <div class="card card-modern">
            <div class="card-header bg-white py-3">
                <h5 class="card-title mb-0"><i class="fe-user me-1 text-primary"></i> Profile Information</h5>
            </div>
            <div class="card-body">
                <form action="{{route('admin.profile.update')}}" method="POST" class="row" enctype="multipart/form-data">
                    @csrf
                    
                    <div class="col-sm-6">
                        <div class="form-group mb-3">
                            <label for="name" class="form-label">Name *</label>
                            <input type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ $user->name}}" id="name" required="">
                            @error('name')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group mb-3">
                            <label for="email" class="form-label">Email *</label>
                            <input type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ $user->email}}" id="email" required="">
                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group mb-3">
                            <label for="password" class="form-label">New Password (Leave blank to keep current)</label>
                            <input type="password" class="form-control @error('password') is-invalid @enderror" name="password" id="password">
                            @error('password')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group mb-3">
                            <label for="confirm-password" class="form-label">Confirm New Password</label>
                            <input type="password" class="form-control" name="confirm-password" id="confirm-password">
                        </div>
                    </div>

                    <div class="col-sm-12 mb-3">
                        <div class="form-group">
                            <label for="image" class="form-label">Profile Image</label>
                            <input type="file" class="form-control @error('image') is-invalid @enderror" name="image" id="image">
                            
                            @if($user->image)
                            <div class="mt-2">
                                <img src="{{asset($user->image)}}" alt="user" class="rounded-circle border shadow-sm" width="100">
                            </div>
                            @endif

                            @error('image')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>

                    <div class="col-12 mt-2">
                        <button type="submit" class="btn btn-primary px-4 fw-bold">
                            <i class="fe-save me-1"></i> Update Credentials
                        </button>
                    </div>

                </form>

            </div> <!-- end card-body-->
        </div> <!-- end card-->
    </div> <!-- end col-->

    <div class="col-lg-4">
        <div class="card card-modern bg-primary text-white">
            <div class="card-body">
                <div class="d-flex align-items-center mb-3">
                    <img src="{{asset($user->image)}}" alt="user" class="rounded-circle border border-2 border-white shadow-lg" width="60" height="60" onerror="this.src='{{ asset('uploads/default/no-image.png') }}'">
                    <div class="ms-3">
                        <h5 class="text-white mb-0">{{$user->name}}</h5>
                        <p class="text-white-50 mb-0">{{$user->email}}</p>
                    </div>
                </div>
                <hr class="bg-white-50">
                <div class="mt-2">
                    <p class="mb-1"><small class="text-white-50">Assigned Roles:</small></p>
                    @foreach($user->roles as $role)
                        <span class="badge bg-white text-primary me-1">{{$role->name}}</span>
                    @endforeach
                </div>
            </div>
        </div>
    </div>
   </div>
</div>
@endsection
