@extends('admin.layouts.app')

@section('title', __('dashboard.edit_admin'))

@section('content')
<x-admin.page-header :title="__('dashboard.edit_admin')" :breadcrumbs="[__('models.admins') => route('admin.admins.index'), __('models.edit') => '']" />

<div class="row">
    <div class="col-lg-12">
        <form action="{{ route('admin.admins.update', $admin) }}" method="POST" enctype="multipart/form-data" class="ajax-form">
            @csrf
            @method('PUT')

            <div class="row">
                <!-- Admin Info -->
                <div class="col-lg-8">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="card-title mb-0">{{ __('dashboard.admin_information') }}</h5>
                        </div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-md-6">
                                    <x-admin.form-input
                                        :label="__('dashboard.name')"
                                        name="name"
                                        :value="$admin->name"
                                        :placeholder="__('dashboard.enter_name')"
                                        :required="true"
                                    />
                                </div>
                                <div class="col-md-6">
                                    <x-admin.form-input
                                        :label="__('dashboard.email')"
                                        name="email"
                                        type="email"
                                        :value="$admin->email"
                                        :placeholder="__('dashboard.enter_email')"
                                        :required="true"
                                    />
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <x-admin.form-input
                                        :label="__('dashboard.phone')"
                                        name="phone"
                                        :value="$admin->phone"
                                        :placeholder="__('dashboard.enter_phone')"
                                    />
                                </div>
                                <div class="col-md-6">
                                    <div class="mb-3">
                                        <label class="form-label">{{ __('dashboard.status') }}</label>
                                        <select name="is_active" class="form-select" {{ $admin->id === auth()->guard('admin')->id() ? 'disabled' : '' }}>
                                            <option value="1" {{ $admin->is_active ? 'selected' : '' }}>{{ __('models.active') }}</option>
                                            <option value="0" {{ !$admin->is_active ? 'selected' : '' }}>{{ __('models.inactive') }}</option>
                                        </select>
                                        @if($admin->id === auth()->guard('admin')->id())
                                            <small class="text-muted">{{ __('dashboard.cannot_deactivate_self') }}</small>
                                        @endif
                                    </div>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6">
                                    <x-admin.form-input
                                        :label="__('dashboard.password')"
                                        name="password"
                                        type="password"
                                        :placeholder="__('dashboard.leave_blank_to_keep')"
                                        :helper="__('dashboard.leave_blank_to_keep')"
                                    />
                                </div>
                                <div class="col-md-6">
                                    <x-admin.form-input
                                        :label="__('dashboard.confirm_password')"
                                        name="password_confirmation"
                                        type="password"
                                        :placeholder="__('dashboard.confirm_password')"
                                    />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Image & Role -->
                <div class="col-lg-4">
                    <div class="card">
                        <div class="card-header">
                            <h5 class="card-title mb-0">{{ __('models.image') }}</h5>
                        </div>
                        <div class="card-body">
                            <x-image name="image" :value="$admin->image" />
                        </div>
                    </div>

                    <div class="card">
                        <div class="card-header">
                            <h5 class="card-title mb-0">{{ __('models.roles') }}</h5>
                        </div>
                        <div class="card-body">
                            @foreach($roles as $role)
                                <div class="form-check mb-2">
                                    <input class="form-check-input" type="checkbox" name="roles[]" value="{{ $role->name }}" id="role_{{ $role->id }}"
                                        {{ in_array($role->name, $adminRoles) ? 'checked' : '' }}>
                                    <label class="form-check-label" for="role_{{ $role->id }}">
                                        {{ $role->name }}
                                    </label>
                                </div>
                            @endforeach
                            @if($roles->isEmpty())
                                <p class="text-muted mb-0">{{ __('dashboard.no_roles_available') }}</p>
                            @endif
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-12">
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-success">
                            <i class="ri-save-line align-middle me-1"></i> {{ __('models.save') }}
                        </button>
                        <a href="{{ route('admin.admins.index') }}" class="btn btn-light">{{ __('models.cancel') }}</a>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
