
<?php $__env->startSection('title', __('messages.users')); ?>
<?php $__env->startSection('content'); ?>
    <div class="add-new-button-hidden">
        <button class="btn add_new_btn" data-bs-toggle="modal" data-bs-target="#userCreateModal"
        ><i class="plus-ico"></i> <?php echo e(__('messages.add_user')); ?>

        </button>
    </div>
    <h2 class="ms-2 mb-3 card-title"><?php echo e(__('messages.user_list')); ?></h2>
    <div class="card mt-3 m-lg-2">
        <div class="card-body mt-2 table_card">
            <table id="myTable" class="display table table-bordered table-sm" style="width:100%">
                <thead>
                <tr>
                    <th><?php echo e(__('messages.sl')); ?></th>
                    <th><?php echo e(__('messages.name')); ?></th>
                    <th><?php echo e(__('messages.email')); ?></th>
                    <th><?php echo e(__('messages.address')); ?></th>
                    <th><?php echo e(__('messages.phone')); ?></th>
                    <th><?php echo e(__('messages.status')); ?></th>
                    <th><?php echo e(__('messages.action')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=>$item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e(++$key); ?></td>
                        <td><?php echo e($item->name); ?></td>
                        <td><?php echo e($item->email); ?></td>
                        <td><?php echo e(($item->address) ?? 'N/A'); ?></td>
                        <td><?php echo e(($item->phone) ?? 'N/A'); ?></td>
                        <td>
                            <span
                                class="badge badge-pill badge-soft-<?php echo e(($item->status === 'active') ? 'success' : 'danger'); ?> font-size-11"><?php echo e(($item->status === 'active') ? 'Active' : 'Inactive'); ?></span>
                        </td>
                        <td class="center" style="width: 11%!important;">
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('user.show')): ?>
                                <a data-id="<?php echo e($item->id); ?>" class="btn view_details" data-bs-toggle="offcanvas"
                                   data-bs-target="#offcanvasRight" aria-controls="offcanvasRight">
                                    <i class="eye-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('user.edit')): ?>
                                <a data-edit="<?php echo e($item->id); ?>" class="btn btn-sm user_edit_btn" data-bs-toggle="modal"
                                   data-bs-target="#user_edit_modal">
                                    <i class="edit-ico"></i>
                                </a>
                            <?php endif; ?>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('user.delete')): ?>
                                <a href="#" class="btn btn-sm" onclick="deletePost(<?php echo e($item->id); ?>)">
                                    <i class="delete-ico"></i>
                                    <form id="delete-form-<?php echo e($item->id); ?>"
                                          action="<?php echo e(route('super-admin.users.destroy', $item->id)); ?>" method="POST"
                                          style="display: none;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                    </form>
                                </a>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight"
         aria-labelledby="offcanvasRightLabel">
        <div class="offcanvas-header">
            <button type="button" class="me-4" data-bs-dismiss="offcanvas" aria-label="Close"
                    style=" border: none;">
                <svg xmlns="http://www.w3.org/2000/svg" width="24"
                     height="24" viewBox="0 0 24 24" fill="none">
                    <path d="M20 11H7.83L13.42 5.41L12 4L4 12L12 20L13.41 18.59L7.83 13H20V11Z" fill="black"/>
                </svg>
            </button>
            <h5 class="offcanvas-title" id="offcanvasRightLabel"><?php echo e(__('messages.user_details')); ?></h5>
        </div>
        <div class="offcanvas-body me-2 offcanva_data_view" style="width: 20rem;"></div>
    </div>
    
    <div class="modal fade" id="userCreateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg ">
            <div class="modal-content p-5">
                <h4 class="card-title"><?php echo e(__('messages.user_info')); ?></h4>
                <p class="card-title-desc"><?php echo e(__('messages.fill_all_information_below')); ?></p>
                <div class="modal-body p-0 mt-3">
                    <form action="<?php echo e(route('super-admin.users.store')); ?>" method="POST" role="form" id="form1"
                          enctype="multipart/form-data" autocomplete="off">
                        <?php echo csrf_field(); ?>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="name"><?php echo e(__('messages.name')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="text" class="form-control <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           value="<?php echo e(old('name')); ?>" name="name" id="name"
                                           placeholder="<?php echo e(__('messages.name')); ?>"
                                           autocomplete="off" readonly onfocus="this.removeAttribute('readonly');"
                                           required/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="email"><?php echo e(__('messages.email')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="email" class="form-control <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           value="<?php echo e(old('email')); ?>" name="email" id="email"
                                           placeholder="<?php echo e(__('messages.email')); ?>"
                                           autocomplete="off" readonly onfocus="this.removeAttribute('readonly');"
                                           required/>
                                </div>
                            </div>
                        </div>

                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="password"><?php echo e(__('messages.password')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="password" class="form-control <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           value="<?php echo e(old('password')); ?>" name="password" id="password" minlength="6"
                                           placeholder="Enter password" autocomplete="off" readonly
                                           onfocus="this.removeAttribute('readonly');" required/>
                                </div>
                                <span class="text-danger password-validation password"></span>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label"
                                           for="password_confirmation"><?php echo e(__('messages.confirm_password')); ?> <span
                                            class="text-danger">*</span></label>
                                    <input type="password"
                                           class="form-control <?php $__errorArgs = ['password_confirmation'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                           value="<?php echo e(old('password_confirmation')); ?>" name="password_confirmation"
                                           minlength="6"
                                           id="password_confirmation"
                                           placeholder="Re-enter password" autocomplete="off" readonly
                                           onfocus="this.removeAttribute('readonly');" required/>
                                    <span class="text-danger password-validation confirm-password"></span>
                                </div>
                            </div>
                        </div>

                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="address"><?php echo e(__('messages.address')); ?></label>
                                    <input type="text" class="form-control" name="address" id="address"
                                           value="<?php echo e(old('address')); ?>"
                                           placeholder="Enter address" autocomplete="off" readonly
                                           onfocus="this.removeAttribute('readonly');"/>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="phone"><?php echo e(__('messages.phone')); ?></label>
                                    <input type="text" class="form-control" name="phone" id="phone"
                                           value="<?php echo e(old('phone')); ?>"
                                           placeholder="ex: 017XXXXXXXX" autocomplete="off" readonly
                                           onfocus="this.removeAttribute('readonly');"/>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="gender"><?php echo e(__('messages.gender')); ?> <span
                                            class="text-danger">*</span></label>
                                    <select class="form-control" name="gender" id="gender" required>
                                        <option value="">Select Gender</option>
                                        <option value="male">Male</option>
                                        <option value="female">Female</option>
                                        <option value="other">Other</option>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="assign_roles"><?php echo e(__('messages.assign_roles')); ?><span
                                            class="text-danger">*</span></label>
                                    <select
                                        class="form-control <?php $__errorArgs = ['assign_roles'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        name="assign_roles" id="assign_roles" required>
                                        <option value="">Select Roles</option>
                                        <?php $__currentLoopData = $roles; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($item->id); ?>"><?php echo e($item->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="farm"><?php echo e(__('messages.farm_name')); ?><span
                                            class="text-danger">*</span></label>
                                    <select
                                        class="form-select js-example-basic-multiple <?php $__errorArgs = ['farms'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        onChange="getHerd(this);"
                                        name="farms[]" id="farm" multiple="multiple" required>
                                        <?php $__currentLoopData = $farms; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($item->id); ?>"><?php echo e($item->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label class="form-label" for="herd"><?php echo e(__('messages.herd_name')); ?></label>
                                    <select
                                        class="form-control js-example-basic-multiple  <?php $__errorArgs = ['herd'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        name="herds[]" id="herd" multiple="multiple" onChange="getLot(this);">
                                        <option value="">Select Herd</option>
                                        <?php $__currentLoopData = $herds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $herd): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($herd->id); ?>"><?php echo e($herd->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-md-6">
                                <div class="form-group mt-2">
                                    <label class="form-label" for="lot"><?php echo e(__('messages.lot_name')); ?></label>
                                    <select
                                        class="form-control js-example-basic-multiple <?php $__errorArgs = ['lots'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                        name="lots[]" id="lot" multiple="multiple">
                                        <option value="">Select Lot</option>
                                        <?php $__currentLoopData = $lots; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lot): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($lot->id); ?>"><?php echo e($lot->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-6">
                                <div class="form-group mt-2">
                                    <label class="form-label"><?php echo e(__('messages.profile_photo')); ?></label>
                                    <input type="file" class="form-control" name="profile_photo" accept="image/*">
                                </div>
                            </div>
                        </div>
                        <div class="row mt-3" style="height: 70px;">
                            <div class="col-md-4">
                                <div class="form-group mt-2">
                                    <label class="form-label"><?php echo e(__('messages.status')); ?></label><br>
                                    <label>
                                        <input type="radio" class="form-check-input" name="status" value="active"
                                               checked/> Active
                                    </label>
                                    <label>
                                        <input type="radio" class="form-check-input ms-3" name="status"
                                               value="inactive"/> Inactive
                                    </label>

                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group mt-2">
                                    <label class="form-label"><?php echo e(__('messages.user_type')); ?></label><br>
                                    <label>
                                        <input type="radio" class="form-check-input"  name="usertype" id="other_check"
                                               checked/> Other
                                    </label>
                                    <label>
                                        <input type="radio" class="form-check-input ms-3" name="usertype" id="doctor_check"/> Doctor
                                    </label>

                                </div>
                            </div>
                            <div class="col-md-4 ">
                                <div class="form-group doctorType_section d-none">
                                    <label class="form-label" for="doctor_id"><?php echo e(__('messages.doctor_id')); ?></label>
                                    <input type="text" class="form-control" name="doctor_id" id="doctor_id"
                                           value="<?php echo e(old('doctor_id')); ?>"
                                           placeholder="ex: 12345" autocomplete="off" />
                                </div>
                            </div>
                        </div>
                        <div class="mt-3 d-flex justify-content-end">
                            <button type="button" class="btn  me-2" data-bs-dismiss="modal"
                                    style="background: #EAECF0;">
                                <?php echo e(__('messages.close')); ?>

                            </button>
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('user.create')): ?>
                                <button type="submit" class="btn btn-primary"><?php echo e(__('messages.save')); ?>

                                </button>
                            <?php endif; ?>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    

    
    <div class="modal fade" id="user_edit_modal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content p-5">
                <h4 class="card-title"><?php echo e(__('messages.user_info')); ?></h4>
                <p class="card-title-desc"><?php echo e(__('messages.fill_all_information_below')); ?></p>
                <div class="modal-body p-0 mt-3 edit-body"></div>
            </div>
        </div>
    </div>
    
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script type="text/javascript">
        $('#password').keyup(function () {
            let value = $(this).val(), confirmPassword = $('#password_confirmation');
            if (value.length < 6) {
                $(this).addClass('is-invalid').removeClass('is-valid');
                $('.password').show().text('Password must be at least 6 characters');
                $('button[type="submit"]').prop('disabled', true);
            } else {
                $(this).addClass('is-valid').removeClass('is-invalid');
                $('.password').hide()
                $('button[type="submit"]').prop('disabled', false);
            }
            if ($(confirmPassword).val().length > 0 && value === $(confirmPassword).val()) {
                if ($(confirmPassword).val().length >= 6) {
                    $(confirmPassword).addClass('is-valid').removeClass('is-invalid');
                    $('.confirm-password').hide()
                    $('button[type="submit"]').prop('disabled', false);
                } else {
                    $(confirmPassword).addClass('is-invalid').removeClass('is-valid');
                    $('.confirm-password').show().text('Password and confirmation password must be same');
                    $('button[type="submit"]').prop('disabled', true);
                }
            } else if ($(confirmPassword).val().length > 0 && value !== $(confirmPassword).val()) {
                $(confirmPassword).addClass('is-invalid').removeClass('is-valid');
                $('.confirm-password').show().text('Password and confirmation password must be same');
                $('button[type="submit"]').prop('disabled', true);
            }
        })

        $('#password_confirmation').keyup(function () {
            let value = $(this).val(), password = $('#password').val();
            if (value.length < 6 || value !== password) {
                $(this).addClass('is-invalid').removeClass('is-valid');
                $('.confirm-password').show().text('Password and confirmation password must be same');
                $('button[type="submit"]').prop('disabled', true);
            } else {
                $(this).addClass('is-valid').removeClass('is-invalid');
                $('.confirm-password').hide()
                $('button[type="submit"]').prop('disabled', false);
            }
        })

        $(document).on('click', '.view_details', function () {
            let id = $(this).attr('data-id');
            $('.offcanva_data_view').empty();
            axios.post('<?php echo e(route('super-admin.users.show')); ?>', {
                id: id,
            }).then(function (response) {
                $('.offcanva_data_view').append('<table class="table table-borderless w-100" style="border: none;">' +
                    ' <tr><th style="width: 100%;"><?php echo e(__('messages.name')); ?></th><td>' + response.data.name + '</td></tr>' +
                    ' <tr><th style="width: 100%;"><?php echo e(__('messages.email')); ?></th><td>' + response.data.email + '</td></tr>' +
                    ' <tr><th style="width: 100%;"><?php echo e(__('messages.address')); ?></th><td>' + response.data.address + '</td></tr>' +
                    ' <tr><th style="width: 100%;"><?php echo e(__('messages.phone')); ?></th><td>' + response.data.phone + '</td></tr>' +
                    ' <tr><th style="width: 100%;"><?php echo e(__('messages.gender')); ?></th><td>' + response.data.gender + '</td></tr>' +
                    '<tr><th style="width: 100%;"><?php echo e(__('messages.profile_photo')); ?></th><td> <img src="<?php echo e(asset("storage/")); ?>/' + response.data.profile_photo + '" style="max-height: 60px"></td></tr>' + '</table>')
            }).catch(function (error) {
                console.log(error);
            });
        });
        // edit section
        $(document).on('click', '.user_edit_btn', function () {
            let id = $(this).attr('data-edit');
            $('.edit-body').append();
            axios.post('<?php echo e(route("super-admin.users.edit")); ?>', {
                id: id,
            }).then(function (response) {
                console.log(response.data);
                $('.edit-body').html(response.data)
                $(".js-example-basic-multiple").select2();
            }).catch(function (error) {
                console.log(error);
            });
        });

        //end edit section
        function getHerd(element) {
            var str = '';
            var val = $(element).val();

            for (i = 0; i < val.length; i++) {
                if (val[i]) {
                    str += val[i] + ',';
                }
            }
            var str = str.slice(0, str.length - 1);
            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/users/get-herd-list')); ?>",
                data: 'farm_id=' + str,
                success: function (res) {
                    if (res) {
                        $("#herd, #herdEdit").empty().html(res);
                    } else {
                        $("#herd").empty();
                    }
                }
            });
        }

        function getLot(element) {
            var str = '';
            var val = $(element).val();

            for (i = 0; i < val.length; i++) {
                if (val[i]) {
                    str += val[i] + ',';
                }
            }
            var str = str.slice(0, str.length - 1);

            $.ajax({
                type: "GET",
                url: "<?php echo e(url('system/users/get-lot-list')); ?>",
                data: 'herd_id=' + str,
                success: function (res) {
                    if (res) {
                        $("#lot,#lotEdit").empty().html(res);
                    } else {
                        $("#lot").empty();
                    }
                }
            });
        }

        $('#doctor_check').change(function() {
            if($(this).is(':checked')) {
                console.log('Checkbox is checked');
                $('.doctorType_section').removeClass('d-none');
            }
        });
        $('#other_check').change(function() {
            if($(this).is(':checked')) {
                console.log('Checkbox is other');
                $('.doctorType_section').addClass('d-none');
            }
        });


    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\practice\ml_firm\resources\views/backend/user/index.blade.php ENDPATH**/ ?>