<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">Products</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">Products</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">Products</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 Product" data-append-id="AjaxModelContent"
                                       data-action-url="{{route("admin::add_product")}}">
                                        <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>Category</th>
                                        <th>Varrient</th>
                                        <th>Description</th>
                                        <th>Sale Price</th>
                                        <th>Quantity</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @if(!empty($products))
                                        <?php $i=0; ?>
                                        @foreach($products as $pdts)
                                            <?php $i++; ?>
                                            <tr>
                                                <td>{{$i}}</td>
                                                <td>
                                                    <img src="{{asset($pdts['product_image'])}}" style="width: 120px;height: 120px;">
                                                </td>
                                                <td>
                                                    {{$pdts['product_name']}}
                                                </td>

                                                <!-- <td>
                                                    {{$pdts['cat_id']}}
                                                </td> -->

                                                <td>
                                                {{ $pdts->cat_id ? \App\Helper\admin\Catname::getCategoryName($pdts->cat_id) : 'Unknown Category' }}
                                            </td>

                                            <td>
                                                @if($pdts['product_tag'] == 1)
                                                    Top Sale
                                                @elseif($pdts['product_tag'] == 2)
                                                    Best Sellers
                                                @else
                                                    Unknown Tag
                                                @endif
                                            </td>


                                                <td>
                                                    {{$pdts['product_dec']}}
                                                </td>

                                                <td>
                                                    {{$pdts['product_saleprice']}}
                                                </td>

                                                <td>
                                                    {{$pdts['product_quantity']}}
                                                </td>
                                               
                                                
                                                <td>
                                                    <a href="javascript:void(0);" class="btn btn-warning btn-sm" data-act="ajax-modal" data-title="Edit Product" data-append-id="AjaxModelContent"
                                                       data-action-url="{{route('admin::edit_product',['id'=>$pdts['id']])}}">
                                                        <i class="fa fa-edit"></i>
                                                    </a>
                                                    <a onclick="deleteItem('{{route('admin::delete_product',$pdts['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>Category</th>
                                        <th>Description</th>
                                        <th>Sale Price</th>
                                        <th>Quantity</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_banner(id,status) {
        $.ajax({
            type: "post",
            url: '{{route('admin::status_banner')}}',
            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);
                toastr.success('Status is '+resp.status)
            }
        });
    }
</script>
@endpush
