<?php $__env->startSection('title'); ?>
    <?php echo e(__('translations.whatsapp')); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('sub-title'); ?>
    <?php echo e(__('translations.whatsapp-edit')); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="content d-flex flex-column flex-column-fluid" id="kt_content">
        <div class="post d-flex flex-column-fluid" id="kt_post">
            <div id="kt_content_container" class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card card-docs mb-2">
                            <div class="card-header">
                                <div class="card-title m-0">
                                    <h3 class="fw-bolder m-0"><?php echo e(__('translations.whatsapp-edit')); ?></h3>
                                </div>
                            </div>
                            <div class="card-body">


                                <form action="<?php echo e(route('admin.settings.whatsapp.update')); ?>" method="post"
                                    enctype="multipart/form-data">
                                    <?php echo csrf_field(); ?>
                                    <div class="row">
                                        <div class="col-md-12 mb-5">
                                            <label class="form-label"><?php echo e(__('translations.status')); ?> <span
                                                    class="text-danger">*</span></label>
                                            <div class="d-flex align-items-center">
                                                <button type="button"
                                                    class="btn btn-<?php echo e($whatsapp->active == 1 ? 'success' : 'danger'); ?> btn-sm"
                                                    id="toggleActiveBtn">
                                                    <?php echo e($whatsapp->active == 1 ? __('translations.active') : __('translations.inactive')); ?>

                                                </button>
                                            </div>
                                        </div>

                                        <div class="col-md-12 mb-5">
                                            <label class="form-label"><?php echo e(__('translations.whatsapp-domain')); ?> <span
                                                    class="text-danger">*</span></label>
                                            <input type="text" class="form-control" name="domain"
                                                value="<?php echo e($whatsapp->domain); ?>" required />
                                            <?php $__errorArgs = ['domain'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong><?php echo e($message); ?></strong></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>

                                        <div class="col-md-4 mb-5">
                                            <label class="form-label"><?php echo e(__('translations.whatsapp-app_key')); ?> <span
                                                    class="text-danger">*</span></label>
                                            <input type="text" class="form-control" name="app_key"
                                                value="<?php echo e($whatsapp->app_key); ?>" required />
                                            <?php $__errorArgs = ['app_key'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong><?php echo e($message); ?></strong></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>

                                        <div class="col-md-4 mb-5">
                                            <label class="form-label"><?php echo e(__('translations.whatsapp-auth_key')); ?> <span
                                                    class="text-danger">*</span></label>
                                            <input type="text" class="form-control" name="auth_key"
                                                value="<?php echo e($whatsapp->auth_key); ?>" required />
                                            <?php $__errorArgs = ['auth_key'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong><?php echo e($message); ?></strong></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>

                                        <div class="col-md-4 mb-5">
                                            <label class="form-label"><?php echo e(__('translations.Country Code')); ?> <span
                                                    class="text-danger">*</span></label>
                                            <input type="text" class="form-control" name="code"
                                                value="<?php echo e($whatsapp->code); ?>" required />
                                            <?php $__errorArgs = ['code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <div class="fv-plugins-message-container invalid-feedback">
                                                    <strong><?php echo e($message); ?></strong></div>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>



                                        <div class="d-flex pt-5 justify-content-between align-items-center">
                                            <a href="<?php echo e(route('admin.settings')); ?>" class="btn btn-secondary">
                                                <?php echo e(__('translations.back')); ?> <i class="fa fa-undo" aria-hidden="true"></i>
                                            </a>
                                            <button type="submit" class="btn btn-primary">
                                                <?php echo e(__('translations.edit')); ?> <i class="fa fa-check"
                                                    aria-hidden="true"></i>
                                            </button>
                                        </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script>
        document.getElementById('toggleActiveBtn').addEventListener('click', function() {
            var currentStatus = <?php echo e($whatsapp->active); ?>; // Get the current active status
            var newStatus = currentStatus === 1 ? 0 : 1; // Toggle the status

            // Send AJAX request to update the status
            fetch('<?php echo e(route('admin.settings.whatsapp.updateStatus')); ?>', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'X-CSRF-TOKEN': '<?php echo e(csrf_token()); ?>'
                    },
                    body: JSON.stringify({
                        active: newStatus
                    })
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        // Update the button UI after successful status change
                        var button = document.getElementById('toggleActiveBtn');
                        if (newStatus === 1) {
                            button.classList.remove('btn-danger');
                            button.classList.add('btn-success');
                            button.innerText = '<?php echo e(__('translations.active')); ?>';
                        } else {
                            button.classList.remove('btn-success');
                            button.classList.add('btn-danger');
                            button.innerText = '<?php echo e(__('translations.inactive')); ?>';
                        }
                    } else {
                        alert('حدث خطأ أثناء تغيير الحالة.');
                    }
                })
                .catch(error => {
                    console.error('Error:', error);
                });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.main', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/opticsin/public_html/4eye.innovationstars.net/resources/views/admin/whatsapp/index.blade.php ENDPATH**/ ?>