<div class="grid grid-cols-1 gap-4 sm:gap-5 lg:gap-6"x-data="{ changePassword: @entangle('changePassword'), tomGReady: false }" x-show="tomGReady">
    <form wire:submit.prevent="submitEditForm">
        @csrf
        <div class="card pb-4">
            <div class="my-3 flex h-8 items-center justify-between px-4 sm:px-5">
                <h2 class="font-medium tracking-wide text-slate-700 line-clamp-1 dark:text-navy-100 lg:text-base">
                    <i class="fa-solid fa-edit text-primary"></i> Edit User
                </h2>
            </div>
            <div class="w-3/4 px-3 space-y-3 m-auto mb-4">
                <div class="flex items-center">
                    <label class="w-2/12 mr-2">
                        <span>Name:</span>
                    </label>
                    <span class="relative flex w-full">
                        <input wire:model.defer="name"
                            class="form-input w-2/4 rounded-lg border border-slate-300 bg-transparent px-3 py-2 text-xs pl-4 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                            placeholder="Name" name="name" type="text" />
                        @error('name')
                            <span class="text-red-500 text-md self-center ml-4">{{ $message }}</span>
                        @enderror
                    </span>
                </div>

                <div class="flex items-center">
                    <label class="w-2/12 mr-2">
                        <span>Email:</span>
                    </label>
                    <span class="relative flex w-full">
                        <input wire:model.defer="email"
                            class="form-input w-2/4 rounded-lg border border-slate-300 bg-transparent px-3 py-2 text-xs pl-4 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                            placeholder="Email" name="email" type="email" />
                        @error('email')
                            <span class="text-red-500 text-md self-center ml-4">{{ $message }}</span>
                        @enderror
                    </span>
                </div>



                <div class="flex items-center " wire:ignore>
                    <span class="w-2/12 mr-2">Add Groups:</span>
                    <span class="relative flex  w-full">
                        <input class="mt-1.5 relative flex w-1/2" wire:ignore x-data="{ groupLists: @entangle('group_lists') }"
                            x-init="groupLists = @js($userGroups);
                            const tempGroup = pages.groupSelect;
                            pages.fetchGroups(tempGroup).then(() => {
                                $el._x_tom = new Tom($el, {
                                    ...tempGroup.group,
                                    onChange: (value) => {
                                        groupLists = value;
                                    }
                                });
                                $el._x_tom.setValue(groupLists);
                                tomGReady = true
                            })" type="text">
                    </span>
                </div>
                <!-- Toggle Button for Change Password -->
                <div class="flex items-center">
                    <button type="button" @click="changePassword = !changePassword"
                        class="btn border bg-gray-300  border-gray-300 font-medium text-gray-800 hover:text-white focus:text-white hover:bg-gray-500 focus:bg-gray-500 active:bg-gray-150/80 dark:border-navy-450 dark:text-navy-50 dark:hover:bg-navy-500 dark:focus:bg-navy-500 dark:active:bg-navy-500/90">
                        Change Password
                    </button>
                </div>

                <!-- Password Fields (Hidden by Default) -->
                <div x-show="changePassword">
                    <div class="flex items-center mt-4">
                        <label class="w-2/12 mr-2">
                            <span>Current Password:</span>
                        </label>
                        <span class="relative flex w-full">
                            <input wire:model.defer="current_password"
                                class="form-input w-2/4 rounded-lg border border-slate-300 bg-transparent px-3 py-2 text-xs pl-4 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                placeholder="Current Password" name="current_password" type="password" />
                            @error('current_password')
                                <span class="text-red-500 text-md self-center ml-4">{{ $message }}</span>
                            @enderror
                        </span>
                    </div>

                    <div class="flex items-center mt-4">
                        <label class="w-2/12 mr-2">
                            <span>New Password:</span>
                        </label>
                        <span class="relative flex w-full">
                            <input wire:model.defer="new_password"
                                class="form-input w-2/4 rounded-lg border border-slate-300 bg-transparent px-3 py-2 text-xs pl-4 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                placeholder="New Password" name="new_password" type="password" />
                            @error('new_password')
                                <span class="text-red-500 text-md self-center ml-4">{{ $message }}</span>
                            @enderror
                        </span>
                    </div>

                    <div class="flex items-center mt-4">
                        <label class="w-2/12 mr-2">
                            <span>Confirm New Password:</span>
                        </label>
                        <span class="relative flex w-full">
                            <input wire:model.defer="new_password_confirmation"
                                class="form-input w-2/4 rounded-lg border border-slate-300 bg-transparent px-3 py-2 text-xs pl-4 placeholder:text-slate-400/70 hover:border-slate-400 focus:border-primary dark:border-navy-450 dark:hover:border-navy-400 dark:focus:border-accent"
                                placeholder="Confirm New Password" name="new_password_confirmation" type="password" />
                            @error('new_password_confirmation')
                                <span class="text-red-500 text-md self-center ml-4">{{ $message }}</span>
                            @enderror
                        </span>
                    </div>
                </div>
            </div>
            <div class="grid grid-cols-12 justify-center space-x-2 pt-4">
                <span wire:click="goBack"
                    class="col-start-4 btn border border-slate-300 font-medium text-slate-800 hover:bg-slate-150 focus:bg-slate-150 active:bg-slate-150/80 dark:border-navy-450 dark:text-navy-50 dark:hover:bg-navy-500 dark:focus:bg-navy-500 dark:active:bg-navy-500/90">
                    Cancel
                </span>
                <button type="submit"
                    class="btn ml-3 bg-primary font-medium text-white hover:bg-primary-focus focus:bg-primary-focus active:bg-primary-focus/90 dark:bg-accent dark:hover:bg-accent-focus dark:focus:bg-accent-focus dark:active:bg-accent/90">
                    Save
                </button>
            </div>
        </div>
    </form>
</div>
