<div class="row">
    <div class="col-md-7">
        <form action="#" method="POST" id="blogupdateform">
            <div class="form-group col-sm-12">
                <input type="hidden" name="id" value="<?php echo e($blog->id); ?>">
                <label>BLOG TITLE</label>
                <input type="text" name="title" class="form-control" required value="<?php echo e($blog->title); ?>">
            </div>
            <div class="form-group col-sm-8">
                <label>CATEGORY</label>
                <select class="form-control" name="category" required>
                    <option value="<?php echo e($blog->category); ?>"><?php echo e($blog->category); ?></option>
                    <option value="Sport News">Sport News</option>
                    <option value="Updates">Website Updates</option>
                    <option value="Notification">Notification</option>
                </select>
            </div>

            <div class="form-group col-sm-4">
                <label>PUBLISH STATUS</label>
                <select class="form-control" name="status" required>
                    <option value="<?php echo e($blog->status); ?>"><?php echo e($blog->status); ?></option>
                    <option value="Publish">Publish Now</option>
                    <option value="Draft">Save as Draft</option>
                </select>
            </div>
            <div class="form-group col-sm-12">
                <label for="moreoption">BLOG CONTEXT</label>
                <textarea name="content" id="moreoption" class="form-control"><?php echo $blog->content; ?></textarea>
            </div>

            <?php echo csrf_field(); ?>


            <div id="blogstatus" class="col-xs-6"></div>
            <div class="form-group col-sm-12">
                <hr style="margin: 15px;">
                <button class="btn btn-md btn-success" name="submit" id="blogbtn">SUBMIT UPDATE</button>
            </div>

        </form>
    </div>
    <div class="col-md-5">
        <h5>CHANGE COVER PICTURE</h5>
        <hr>
        <form action="<?php echo e(url('/blogs')); ?>" method="POST" id="uploadfor" enctype="multipart/form-data">
            <input type="hidden" name="id" value="<?php echo e($blog->id); ?>">
            <input type="hidden" name="image" value="<?php echo e($blog->display_image); ?>">
            <div class="col-sm-12">
                <div class="input-field col-md-12">
                    <div class="fileupload fileupload-new" data-provides="fileupload">
                        <div class="fileupload-new thumbnail" style="width: 160px; height: 150px;"><?php if($blog->display_image!=NULL): ?><img src="<?php echo e(asset('images')); ?>/blog/<?php echo e($blog->display_image); ?>" alt="" /><?php else: ?><img src="<?php echo e(asset('images/demoUpload.jpg')); ?>" alt="" /><?php endif; ?></div>
                        <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 160px; max-height: 150px; line-height: 20px;"></div>
                        <div>
                <span class="btn btn-sm btn-file btn-default"><span class="fileupload-new">SELECT DP</span><span class="fileupload-exists">Change</span>
                <input type="file" name="file" required/></span>
                            <a href="#" class="btn btn-sm btn-danger fileupload-exists" data-dismiss="fileupload">Remove</a>
                        </div>
                    </div>
                </div>
            </div>
            <input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
            <div id="upl"></div><br>
            <button class="btn btn-sm btn-success" id="up">UPLOAD</button>
        </form>

    </div>
</div>

<script>
    tinymce.init({
        selector:'textarea',
        setup: function (editor) {
            editor.on('change', function () {
                editor.save();
            });
        },
        forced_root_block : "",
        force_br_newlines : true,
        force_p_newlines : false,
        menubar: false,
        statusbar: false,
        toolbar: 'styleselect | bold italic | link image | alignleft aligncenter alignright | bullist | numlist',
        height : 40

    });

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $(document).ready(function () {
        $('#blogupdateform').submit(function (e) {
            e.preventDefault();
            $('#blogstatus').html('Updating... Please wait');
            $('#blogbtn').prop('disabled', true);

            var dataString = $(this).serialize();
//            alert(dataString);
            $.ajax({
                type: "POST",
                url: "ajaxblogupdate",
                data: dataString,
                dataType: "JSON",
                success: function(data){
                    if (data.status == 1) {
                        $('#blogbtn').prop('disabled', false);
                        $('#blogstatus').html(data.encounters);
                        console.log(data);
                    }
                    else{
//                        $('#settingstatus').html(data.encounters);
                        alert(data.encounters);
                        $('#updateblog').modal('hide');
                    }
                }
            });

        });
    });
</script>