<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">Solution</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">Solution</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 class="card-header">
                                <h3 class="card-title">Solution</h3>
                                <h3 class="card-title" style="float: right!important;">
                                    <a href="javascript:void(0);" class="btn btn-primary btn-flat" data-act="ajax-modal" data-title="Add Solution" data-append-id="AjaxModelContent"
                                       data-action-url="{{route("admin::add_solution")}}">
                                        <i class="fa fa-plus-circle"></i> Add
                                    </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>Image</th>
                                        <th>Name</th>
                                        <th>Description</th>
                                        <th>Status</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @if(!empty($solutions))
                                        <?php $i=0; ?>
                                        @foreach($solutions as $solution)
                                            <?php $i++; ?>
                                            <tr>
                                                <td>{{$i}}</td>
                                                <td>
                                                    <img src="{{asset($solution['image'])}}" style="width: 120px;height: 120px;">
                                                </td>
                                                <td>
                                                    {{$solution['name']}}
                                                </td>
                                                <td>
                                                    {!! $solution['description'] !!}
                                                </td>
                                                <td>
                                                    <span id="status{{$solution->id}}">
                                                    @if($solution->status == 'Active')
                                                            <a href="javascript:active_inactive_solution('<?php echo $solution->id; ?>','<?php echo $solution->status; ?>');" class="btn btn-success btn-sm"><span class="fa fa-check"></span> </a>&emsp;
                                                        @else
                                                            <a href="javascript:active_inactive_solution('<?php echo $solution->id; ?>','<?php echo $solution->status; ?>');" class="btn btn-warning btn-sm" ><span class="fa fa-ban"></span> </a>&emsp;
                                                        @endif
                                                    </span>
                                                </td>
                                                <td>
                                                    <a href="javascript:void(0);" class="btn btn-warning btn-sm" data-act="ajax-modal" data-title="Edit Solution" data-append-id="AjaxModelContent"
                                                       data-action-url="{{route('admin::edit_solution',['id'=>$solution['id']])}}">
                                                        <i class="fa fa-edit"></i>
                                                    </a>
                                               <a onclick="deleteItem('{{route('admin::delete_solution',$solution['id'])}}')" href="javascript:void(0);" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                                                </td>
                                            </tr>
                                        @endforeach
                                    @endif
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th>Sl.No.</th>
                                        <th>Image</th>
                                        <th>Name</th>
                                        <th>Description</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_solution(id,status) {
            $.ajax({
                type: "post",
                url: '{{route('admin::status_solution')}}',
                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
