<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap-switch-button@1.1.0/css/bootstrap-switch-button.min.css" rel="stylesheet">
@extends('admin.layout.admin_layout')
@section('content')
    <div class="content-wrapper" style="min-height: 357px;">
        <!-- Content Header (Page header) -->
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0">Blog Comment</h1>
                    </div><!-- /.col -->
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="{{route('admin::dashboard')}}">Dashboard</a> </li>
                            <li class="breadcrumb-item active">Comment</li>
                        </ol>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.container-fluid -->
        </div>

        <!-- /.content-header -->
        @include('admin.layout.message')
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-12">
                        <div class="card">
                            <div>
                            <h3 class="card-title" style="float: right!important;">
                                <a href="{{route('admin::blog')}}" type="submit" value="Submit" class="btn btn-primary"><i class="fa fa-arrow-left" aria-hidden="true"></i></a>
                            </h3>
                        </div>
                            <!-- /.card-header -->
                            <div class="card-body">
                                <table id="example1" class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>Sl.No.</th>
                                        <th>Name</th>
                                        <th>Message</th>
                                        <th>Comment Image</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                            @foreach($coms as $com)
                                            <tr>
                                                <td>{{$com->id}}</td>
                                                <td>
                                                    {{$com['name']}}
                                                </td>
                                                <td>
                                                    {!! $com['message'] !!}
                                                </td>
                                                <td>
                                                    <?php
                                                    $show=\App\Models\Image::where('comments_id',$com['id'])->count();
                                                    ?>
                                                    @if($show > 0)
                                                    <a href="javascript:void(0);" class="btn btn-warning btn-sm" data-act="ajax-modal" data-title="Comment image" data-append-id="AjaxModelContent"
                                                       data-action-url="{{route('admin::com_image',['id'=>$com['id']])}}"><i class="fa fa-picture-o"></i></a>
                                                    @endif
                                                </td>
                                                <td>
                                                    <span id="status{{$com->id}}">
                                                    @if($com->status == 'Active')
                                                            <a href="javascript:active_inactive_comment('<?php echo $com->id; ?>','<?php echo $com->status; ?>');" class="btn btn-success btn-sm"><span class="fa fa-check"></span> </a>&emsp;
                                                        @else
                                                            <a href="javascript:active_inactive_comment('<?php echo $com->id; ?>','<?php echo $com->status; ?>');" class="btn btn-warning btn-sm" ><span class="fa fa-ban"></span> </a>&emsp;
                                                        @endif
                                                    </span>
                                                </td>
                                                <td>

                                                    <a onclick="deleteItem('{{route('admin::delete_com',$com['id'])}}')" href="javascript:void(0);" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>

                                                </td>
                                            </tr>
                                @endforeach
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th>Sl.No.</th>
                                        <th>Name</th>
                                        <th>Message</th>
                                        <th>Comment Image</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                            <!-- /.card-body -->
                        </div>
                        <!-- /.card -->
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
@endsection
@push('scripts')
    <script>
        var Inactive='Inactive';
        var Active='Active';
        function active_inactive_comment(id,status) {
            $.ajax({
                type: "post",
                url: '{{route('admin::status_com')}}',
                data: {
                    _token: '<?php echo csrf_token();?>',
                    id: id,
                    status: status
                },
                success: function (data) {
                    var resp = JSON.parse(data);
                    $('#status' + resp.id).html(resp.html);
                    $(document).find('.child #status' + resp.id).html(resp.html);
                    if(resp.status==Active) {
                        toastr.success('Status is ' + resp.status)
                    }
                    else {
                        toastr.warning('Status is ' + resp.status)
                    }
                }
            });
        }
    </script>
@endpush
