<?php $__env->startSection('title'); ?>
    <?php echo app('translator')->getFromJson('SMS Settings'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-header-title'); ?>
    <?php echo app('translator')->getFromJson('Save Settings'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page-header-description'); ?>
    <?php echo app('translator')->getFromJson('View and Update Settings'); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
    <?php if(config('settings.toast_notifications_enable')): ?>
    <script>
        toastr.options.closeButton = true;
        <?php if(session()->has('settings_saved')): ?>
            toastr.success("<?php echo e(session('settings_saved')); ?>");
        <?php endif; ?>
        <?php if(session()->has('settings_not_saved')): ?>
            toastr.error("<?php echo e(session('settings_not_saved')); ?>");
        <?php endif; ?>
    </script>
    <?php endif; ?>
    <script>
        var msgclub = $('.msgclub');
        var pointsms = $('.pointsms');
        var nexmo = $('.nexmo');
        var textlocal = $('.textlocal');
        var twilio = $('.twilio');
        var ebulk = $('.ebulk');

        pointsms.hide();
        msgclub.hide();
        nexmo.hide();
        textlocal.hide();
        twilio.hide();
        ebulk.hide();

        <?php if(config('sms.carrier') == 'msgclub'): ?>
            msgclub.show();
        <?php elseif(config('sms.carrier') == 'pointsms'): ?>
            pointsms.show();
        <?php elseif(config('sms.carrier') == 'nexmo'): ?>
            nexmo.show();
        <?php elseif(config('sms.carrier') == 'textlocal'): ?>
            textlocal.show();
        <?php elseif(config('sms.carrier') == 'twilio'): ?>
            twilio.show();
        <?php elseif(config('sms.carrier') == 'ebulk'): ?>
            ebulk.show();
        <?php endif; ?>

        $(document).ready(function() {
            $('#select-driver').on('change', function() {
                if(this.value == 'msgclub') {
                    nexmo.hide();
                    textlocal.hide();
                    twilio.hide();
                    ebulk.hide();
                    pointsms.hide();
                    msgclub.show();
                } else if(this.value == 'pointsms') {
                    msgclub.hide();
                    textlocal.hide();
                    twilio.hide();
                    ebulk.hide();
                    nexmo.hide();
                    pointsms.show();
                } else if(this.value == 'nexmo') {
                    msgclub.hide();
                    textlocal.hide();
                    twilio.hide();
                    ebulk.hide();
                    pointsms.hide();
                    nexmo.show();
                } else if(this.value == 'textlocal') {
                    msgclub.hide();
                    nexmo.hide();
                    twilio.hide();
                    ebulk.hide();
                    pointsms.hide();
                    textlocal.show();
                }else if(this.value == 'twilio') {
                    msgclub.hide();
                    nexmo.hide();
                    textlocal.hide();
                    ebulk.hide();
                    pointsms.hide();
                    twilio.show();
                }else if(this.value == 'ebulk') {
                    msgclub.hide();
                    nexmo.hide();
                    textlocal.hide();
                    twilio.hide();
                    pointsms.hide();
                    ebulk.show();
                }
            });
        });
    </script>
    <script>
        var orderPlaced = $('.order-placed');
        var orderProcessed = $('.order-processed');
        var orderPackaged = $('.order-packaged');

        orderProcessed.hide();
        orderPackaged.hide();

        $(document).ready(function() {
            $('#select-template').on('change', function() {
                if(this.value == 'order_placed') {
                    orderPlaced.show();
                    orderProcessed.hide();
                    orderPackaged.hide();
                } else if(this.value == 'order_processed') {
                    orderProcessed.show();
                    orderPlaced.hide();
                    orderPackaged.hide();
                } else if(this.value == 'order_packaged') {
                    orderProcessed.hide();
                    orderPlaced.hide();
                    orderPackaged.show();
                }
            });
        });
    </script>
    <script>
        var sendSMSBtn = $('#send-sms');
        var feedback = $('.feedback');
        var feedbackAlert = $('.feedback-alert');
        feedbackAlert.hide();
        $(document).on('submit', '#send-test-sms-form', function(e) {
            e.preventDefault();
            var data = $(this).serialize();
            var url = $(this).attr('action');

            sendSMSBtn.attr('value', '<?php echo app('translator')->getFromJson('Please Wait...'); ?>');
            sendSMSBtn.attr("disabled", "disabled");

            $.post(url, data, function(receivedData) {
                if(!receivedData.error) {

                    if(!receivedData.permission) {
                        feedback.html('<?php echo app('translator')->getFromJson('There is no permission to use this feature.'); ?>');
                    } else if(receivedData.invalid_api) {
                        feedback.html('<?php echo app('translator')->getFromJson('Incorrect API keys or Exception occurred.'); ?>');
                    }
                    else if(!receivedData.sent) {
                        feedback.html('<?php echo app('translator')->getFromJson('SMS carrier is not set.'); ?>');
                    } else if(receivedData.sent) {
                        feedback.html('<?php echo app('translator')->getFromJson('SMS was sent to '); ?>' + receivedData.mobile);
                    } else {
                        feedback.html('<?php echo app('translator')->getFromJson('Unknown error occurred.'); ?>');
                    }

                    feedbackAlert.show();
                } else {
                    feedbackAlert.show();
                    feedback.html('<?php echo app('translator')->getFromJson('Something went wrong.'); ?>');
                }

                sendSMSBtn.attr('value', '<?php echo app('translator')->getFromJson('Send SMS'); ?>');
                sendSMSBtn.removeAttr("disabled");
            });

        });
    </script>
    <?php echo $__env->make('includes.tab_system_scripts', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <?php echo $__env->make('partials.manage.settings.sms', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.manage', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>