<div class="container-fluid">
    <div>
        <h3>Setup Live Streaming</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Settings</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">Setup Live Streaming</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Live Streaming Settings</h6>
                    <div class="email-settings-alert"></div>
                    <form class="email-settings" method="POST">
						<div>
							<div class="float-left">
								<label for="live_video" class="main-label">Live Streaming</label>
								<br><small class="admin-info">Enable this feature, and users can go live instantly.</small>
							</div>
							<div class="form-group float-right switcher">
								<input type="hidden" name="live_video" value="0">
								<input type="checkbox" name="live_video" id="live_video-enabled" value="1" <?php echo ($wo['config']['live_video'] == '1') ? 'checked': '';?>>
								<label for="live_video-enabled" class="check-trail"><span class="check-handler"></span></label>
							</div>
							<div class="clearfix"></div>
						</div>
						
                        <!-- <label for="live_video_save">Save user live streams?</label>
                        <div class="form-group">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="live_video_save" id="live_video_save-enabled" value="1" <?php echo ($wo['config']['live_video_save'] == 1) ? 'checked': '';?>>
                                <label class="form-check-label" for="live_video_save-enabled">Enabled</label>
                            </div>
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="live_video_save" id="live_video_save-disabled" value="0" <?php echo ($wo['config']['live_video_save'] == 0) ? 'checked': '';?>>
                                <label class="form-check-label" for="live_video_save-disabled" class="m-l-20">Disabled</label>
                            </div>
                        </div> -->
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                    </form>
                </div>
            </div>
             <div class="card">
                <div class="card-body">
                    <h6 class="card-title">Agora API Configuration</h6>
                    <div class="agora-settings-alert"></div>
                    <form class="agora-settings" method="POST">
                        <div class="alert-info alert">To start using this feature, you'll need to create an account in <a href="https://www.agora.io/en/">Agora</a>.</div>
                        
                        <div>
                            <div class="float-left">
                                <label for="agora_live_video" class="main-label">Agora Live Streaming</label>
                                <br><small class="admin-info">Users can go live instantly using Agora. <br> Note you can only choose one provider at the same time.</small>
                            </div>
                            <div class="form-group float-right switcher">
                                <input type="hidden" name="agora_live_video" value="0">
                                <input type="checkbox" name="agora_live_video" id="agora_live_video-enabled" value="1" <?php echo ($wo['config']['agora_live_video'] == '1') ? 'checked': '';?>>
                                <label for="agora_live_video-enabled" class="check-trail"><span class="check-handler"></span></label>
                            </div>
                            <div class="clearfix"></div>
                            <hr>
                        </div>

                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">App ID</label>
                                <input type="text" id="agora_app_id" name="agora_app_id" class="form-control" value="<?php echo $wo['config']['agora_app_id'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">App Certificate</label>
                                <input type="text" id="agora_app_certificate" name="agora_app_certificate" class="form-control" value="<?php echo $wo['config']['agora_app_certificate'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Customer ID</label>
                                <input type="text" id="agora_customer_id" name="agora_customer_id" class="form-control" value="<?php echo $wo['config']['agora_customer_id'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Customer Certificate</label>
                                <input type="text" id="agora_customer_certificate" name="agora_customer_certificate" class="form-control" value="<?php echo $wo['config']['agora_customer_certificate'];?>">
                            </div>
                        </div>
                        <!-- <br>
                        <br>
                        <label for="amazone_s3_2">Amazon S3 Storage <small> (To Save Live Videos On Amazon)</small></label>
                        <div class="form-group">
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="amazone_s3_2" id="amazone_s3_2-enabled" value="1" <?php echo ($wo['config']['amazone_s3_2'] == 1) ? 'checked': '';?>>
                                <label class="form-check-label" for="amazone_s3_2-enabled">Enabled</label>
                            </div>
                            <div class="form-check form-check-inline">
                                <input class="form-check-input" type="radio" name="amazone_s3_2" id="amazone_s3_2-disabled" value="0" <?php echo ($wo['config']['amazone_s3_2'] == 0) ? 'checked': '';?>>
                                <label class="form-check-label" for="amazone_s3_2-disabled" class="m-l-20">Disabled</label>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Amazon Bucket Name</label>
                                <input type="text" id="bucket_name_2" name="bucket_name_2" class="form-control" value="<?php echo $wo['config']['bucket_name_2']?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Amazon S3 Key</label>
                                <input type="text" id="amazone_s3_key_2" name="amazone_s3_key_2" class="form-control" value="<?php echo $wo['config']['amazone_s3_key_2']?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Amazon S3 Secret Key</label>
                                <input type="text" id="amazone_s3_s_key_2" name="amazone_s3_s_key_2" class="form-control" value="<?php echo $wo['config']['amazone_s3_s_key_2']?>">
                            </div>
                        </div>
                        <label for="region_2">Amazon S3 bucket Region</label>
                        <select class="form-control show-tick" id="region_2" name="region_2">
                          <option value="us-east-1" <?php echo ($wo['config']['region_2'] == 'us-east-1')   ? ' selected' : '';?> >US East (N. Virginia)</option>
                          <option value="us-east-2" <?php echo ($wo['config']['region_2'] == 'us-east-2')   ? ' selected' : '';?> >US East (Ohio)</option>
                          <option value="us-west-1" <?php echo ($wo['config']['region_2'] == 'us-west-1')   ? ' selected' : '';?> >US West (N. California)</option>
                          <option value="us-west-2" <?php echo ($wo['config']['region_2'] == 'us-west-2')   ? ' selected' : '';?> >US West (Oregon)</option>
                          <option value="ap-northeast-2" <?php echo ($wo['config']['region_2'] == 'ap-northeast-2')   ? ' selected' : '';?> >Asia Pacific (Seoul)</option>
                          <option value="ap-south-1" <?php echo ($wo['config']['region_2'] == 'ap-south-1')   ? ' selected' : '';?> >Asia Pacific (Mumbai)</option>
                          <option value="ap-southeast-1" <?php echo ($wo['config']['region_2'] == 'ap-southeast-1')   ? ' selected' : '';?> >Asia Pacific (Singapore)</option>
                          <option value="ap-southeast-2" <?php echo ($wo['config']['region_2'] == 'ap-southeast-2')   ? ' selected' : '';?> >Asia Pacific (Sydney)</option>
                          <option value="ap-northeast-1" <?php echo ($wo['config']['region_2'] == 'ap-northeast-1')   ? ' selected' : '';?> >Asia Pacific (Tokyo)</option>
                          <option value="ca-central-1" <?php echo ($wo['config']['region_2'] == 'ca-central-1')   ? ' selected' : '';?> >Canada (Central)</option>
                          <option value="eu-central-1" <?php echo ($wo['config']['region_2'] == 'eu-central-1')   ? ' selected' : '';?> >EU (Frankfurt)</option>
                          <option value="eu-west-1" <?php echo ($wo['config']['region_2'] == 'eu-west-1')   ? ' selected' : '';?> >EU (Ireland)</option>
                          <option value="eu-west-2" <?php echo ($wo['config']['region_2'] == 'eu-west-2')   ? ' selected' : '';?> >EU (London)</option>
                          <option value="sa-east-1" <?php echo ($wo['config']['region_2'] == 'sa-east-1')   ? ' selected' : '';?> >South America (São Paulo)</option>
                        </select>
                        <div class="clearfix"></div>
                        <br><br>
                        <p class="help-block ">1. Before enabling Amazon S3, make sure you upload the whole "upload/" folder to your bucket.</p>
                        <p class="help-block ">2. Before disabling Amazon S3, make sure you download the whole "upload/" folder to your server.</p>
                        <p class="help-block ">3. We recommend to upload the folder and files via <a href="http://s3tools.org/s3cmd">S3cmd</a>.</p>
                        <p class="help-block ">4. If your site is still brand new, you can escape the upload step, but make sure to click on "Test Connection".</p> -->
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <!-- <button type="button" class="btn btn-warning m-t-15" onclick="Wo_TestS3()">Test Connection</button> -->
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>

function Wo_TestS3() {
    $('form.agora-settings').find('.btn-warning').text('Please wait..');
    $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s: 'test_s3_2'}, function (data) {
        if (data.status == 200) {
            $('.agora-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Connection established!</div>');
            setTimeout(function () {
                $('.agora-settings-alert').empty();
            }, 2000);
        } else if (data.status == 300) {
            $('.agora-settings-alert').html('<div class="alert alert-danger">Bucket doesn\'t exists</div>');
            setTimeout(function () {
                $('.agora-settings-alert').empty();
            }, 2000);
        } else if (data.status == 500) {
            $('.agora-settings-alert').html('<div class="alert alert-danger">Your s3 account doesn\'t have any buckets, please create one.</div>');
            setTimeout(function () {
                $('.agora-settings-alert').empty();
            }, 2000);
        } else if (data.status == 400) {
            $('.agora-settings-alert').html('<div class="alert alert-danger">'+data.message+'</div>');
            setTimeout(function () {
                $('.agora-settings-alert').empty();
            }, 2000);
        } else  {
            $('.agora-settings-alert').html('<div class="alert alert-danger">Error while connecting to amazone, please check your details</div>');
            setTimeout(function () {
                $('.agora-settings-alert').empty();
            }, 2000);
        }
        $('form.agora-settings').find('.btn-warning').text('Test Connection');
    });
}

$(function() {
    $('.switcher input[type=checkbox]').click(function () {
        var configName = $(this).attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        if ($(this).is(":checked") === true) {
            objData[configName] = $(this).val();
        }
        else{
            if ($('input[name='+configName+']')[0]) {
                objData[configName] = $($('input[name='+configName+']')[0]).val();
            }
        }
        objData['hash_id'] = hash_id;
        $.post(Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData);
    });

    var setTimeOutColor = setTimeout(function (){});
    $('select').on('change', function() {
         clearTimeout(setTimeOutColor);
        var thisElement = $(this);
        var configName = thisElement.attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        objData[configName] = this.value;
        objData['hash_id'] = hash_id;
        thisElement.addClass('warning');
        $.post(Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData, function (data) {
            if (data.status == 200) {
                thisElement.removeClass('warning');
                thisElement.addClass('success');
            } else {
                thisElement.addClass('error');
            }
            var setTimeOutColor = setTimeout(function () {
                thisElement.removeClass('success');
                thisElement.removeClass('warning');
                thisElement.removeClass('error');
            }, 2000);
        });
    });
    $('input[type=text], input[type=number], input[type=password], textarea').on('input', delay(function() {
            clearTimeout(setTimeOutColor);
            var thisElement = $(this);
            var configName = thisElement.attr('name');
            var hash_id = $('input[name=hash_id]').val();
            var objData = {};
            objData[configName] = this.value;
            objData['hash_id'] = hash_id;
            thisElement.addClass('warning');
            $.post(Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData, function (data) {
                if (data.status == 200) {
                    thisElement.removeClass('warning');
                    thisElement.addClass('success');
                } else {
                    thisElement.addClass('error');
                }
                var setTimeOutColor = setTimeout(function () {
                    thisElement.removeClass('success');
                    thisElement.removeClass('warning');
                    thisElement.removeClass('error');
                }, 2000);
                //thisElement.focus();
            });
    }, 500));
});
</script>