<?php $__env->startSection('styles'); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('title'); ?>
    Add/View Bot Device
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Begin Page Content -->
    <div class="container">

        <!-- Page Heading -->
        
        <div class="d-flex align-items-center p-3 my-3 text-white bg-primary rounded shadow-sm">
            <svg class="bd-placeholder-img flex-shrink-0 me-2 rounded" width="32" height="32"
                xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Placeholder: 32x32"
                preserveAspectRatio="xMidYMid slice" focusable="false">
                <title>Placeholder</title>
                <rect width="100%" height="100%" fill="var(--white)"></rect><text x="50%" y="50%" fill="var(--white)"
                    dy=".3em">32x32</text>
            </svg>

            <div class="ml-2">
                <h1 class="h6 mb-0 text-white lh-1">Add/View Bot Device</h1>
                <small><a class="text-white" href="<?php echo e(url('admin/dashboard')); ?>">dashboard</a> > Add/View Bot Device</small>
            </div>
        </div>
        <!-- Content Row -->
        <div class="row mb-3">
            <div class="col-sm-9"></div>
            <div class="col-sm-3">
                <div>
                    <div class="ring-container" title="Runing">
                        <div class="ringring"></div>
                        <div class="circle"></div>
                    </div>
                    <div class="ring-container-failed" title="Failed" style="display: none">
                        <div class="ringring-failed"></div>
                        <div class="circle-failed"></div>
                    </div>
                    <span style="  margin-top: 10px;margin-left: 50px;">WhatsApp Bot Server</span>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="card mb-4 shadow">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-sm-4"></div>
                            <div class="col-sm-4">
                                <div class="card shadow">
                                    <div class="card-header">
                                        <div class="card-title">Edit Reply Text</div>
                                    </div>
                                    <div class="card-body">
                                        <form action="<?php echo e(url($prefix . 'update')); ?>" method="post">
                                            <input type="hidden" name="id" value="<?php echo e($data['id']); ?>">
                                            <?php echo csrf_field(); ?>
                                            <div class="form-group">
                                                <label class="small">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($data['name']); ?>" name="name"
                                                    aria-describedby="hostnameHelp" id="name"
                                                    placeholder="Enter Text Name (Any)" required>
                                                <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                    <span class="text-danger small"><?php echo e($message); ?></span>
                                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                            </div>
                                            <div class="form-group">
                                                <label class="small">Mesasge <span class="text-danger">*</span> <span
                                                        class="text-muted">(Main message need to show after type 'help'
                                                        keyword)</span></label>
                                                <textarea name="message" id="" cols="30" rows="3"
                                                    class="form-control <?php $__errorArgs = ['message'];
$__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); ?>" placeholder="Enter Message (any)" required><?php echo e($data['message']); ?></textarea>
                                                <?php $__errorArgs = ['message'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                    <span class="text-danger small"><?php echo e($message); ?></span>
                                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                            </div>
                                            <div class="row">
                                                <div class="col-sm-6">
                                                    <span class="text-muted">Options</span>
                                                </div>
                                                <div class="col-sm-6">
                                                    <div class="text-right">
                                                        <button type="button" class="btn btn-primary btn-sm"
                                                            id="add-new-option">
                                                            <svg xmlns="http://www.w3.org/2000/svg" width="16"
                                                                height="16" fill="currentColor" class="bi bi-plus-square"
                                                                viewBox="0 0 16 16">
                                                                <path
                                                                    d="M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z" />
                                                                <path
                                                                    d="M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z" />
                                                            </svg>
                                                            add new option
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                            <hr>
                                            <div id="option-rows-default">
                                                <?php $__currentLoopData = $data['options']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <div class="option-row">
                                                        <div class="text-right">
                                                            <button type="button"
                                                                class="remove-btn btn btn-danger btn-sm">Remove</button>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="small">Option Keywod <span
                                                                    class="text-danger">*</span></label>
                                                            <input type="text"
                                                                class="form-control <?php $__errorArgs = ['keyword'];
$__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($item['keyword']); ?>" name="keyword[]"
                                                                aria-describedby="keywordHelp" id="keyword"
                                                                placeholder="Enter Keyword Ex: help" required>
                                                            <?php $__errorArgs = ['keyword'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                <span class="text-danger small"><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="small">Option Message <span
                                                                    class="text-danger">*</span>
                                                            </label>
                                                            <textarea name="text[]" id="" cols="30" rows="3"
                                                                class="form-control <?php $__errorArgs = ['text'];
$__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); ?>" placeholder="Enter Message (any)" required><?php echo e($item['text']); ?></textarea>
                                                            <?php $__errorArgs = ['text'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                                <span class="text-danger small"><?php echo e($message); ?></span>
                                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                            <span class="small text-muted">Short Codes : [LINK]</span>
                                                        </div>

                                                    </div>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </div>

                                            <div id="option-rows"></div>
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <div class="text-right mt-4">
                                                        <a class="btn btn-secondary text-uppercase font-weight-bold rounded pl-4 pr-4"
                                                            href="<?php echo e(url()->previous()); ?>">Cancel</a>
                                                        <button
                                                            class="btn btn-primary text-uppercase font-weight-bold rounded pl-4 pr-4"
                                                            type="submit">Update Text</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-4"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <small class="d-block text-end mt-3">

        </small>
    </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <script>
        $(document).ready(function() {
            setInterval(() => {
                ping()
            }, 5000);


            function ping() {
                var url = "<?php echo e(url('admin/whatsapp-bot/server-status')); ?>"
                $.ajax({
                    type: "GET",
                    url: url,
                    dataType: "JSON",
                    success: function(response) {
                        console.log(response)
                        if (response === true) {
                            $(".ring-container").show();
                            $(".ring-container-failed").hide();
                        } else {
                            $(".ring-container").hide();
                            $(".ring-container-failed").show();
                        }
                    }
                })
            }
            $('#add-new-option').click(function() {
                // Append the HTML section to the option-rows div
                $('#option-rows').append(`
            <div class="option-row">
                <div class="text-right"><button type="button" class="remove-btn btn btn-danger btn-sm">Remove</button></div>
                <div class="form-group">
                    <label class="small">Option Keyword <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" name="keyword[]" aria-describedby="keywordHelp" placeholder="Enter Keyword Ex: help" required>
                </div>
                <div class="form-group">
                    <label class="small">Option Message <span class="text-danger">*</span> </label>
                    <textarea name="text[]" cols="30" rows="3" class="form-control" placeholder="Enter Message (any)" required></textarea>
                    <span class="small text-muted">Short Codes : [LINK]</span>
                </div>
            </div>
        `);
            });
            // Remove button click event using event delegation
            $('#option-rows').on('click', '.remove-btn', function() {
                $(this).closest('.option-row').remove();
            });
            $('#option-rows-default').on('click', '.remove-btn', function() {
                $(this).closest('.option-row').remove();
            });
        })
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('components.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/theload/kit/resources/views/admin/whatsapp-robot/wsr_replytext_edit.blade.php ENDPATH**/ ?>