<div class="col-12">
    <div class="card">
        <div class="card-content">
            <form method="post" action="{{ route('dashboard.products.mass.action') }}">
                @csrf
                <div class="table-responsive">
                    <table class="table mb-0">
                        <thead class="thead-dark">
                            <tr>
                                @can('delete', 'products')
                                    <th scope="col" width="50" class="text-right">
                                        <div class="form-group text-right">
                                            <fieldset class="checkbox">
                                                <div class="vs-checkbox-con vs-checkbox-primary">
                                                    <input type="checkbox" name="prod_id[]" class="change-check"
                                                        id="select-all">
                                                    <span class="vs-checkbox">
                                                        <span class="vs-checkbox--check">
                                                            <i class="vs-icon feather icon-check"></i>
                                                        </span>
                                                    </span>
                                                </div>
                                            </fieldset>
                                        </div>
                                    </th>
                                @endcan
                                <th scope="col" width="50">ID</th>
                                <th scope="col" width="50">@lang('admin.products.image')</th>
                                <th scope="col">@lang('admin.products.name')</th>
                                <th scope="col">@lang('admin.products.category')</th>
                                <th scope="col">@lang('admin.products.price')</th>
                                <th scope="col">@lang('admin.orders.count')</th>
                                <th scope="col">@lang('admin.billing.status')</th>
                                <th scope="col" class="text-right">@lang('admin.actions')</th>
                            </tr>
                        </thead>
                        <tbody>
                            @if (count($products) == 0)
                                <tr>
                                    <td class="text-center" colspan="9">
                                        @lang('admin.no_data')
                                    </td>
                                </tr>
                            @endif
                            @foreach ($products as $product)
                                <tr>
                                    @can('delete', 'products')
                                        <td class="text-right">
                                            <div class="form-group">
                                                <fieldset class="checkbox">
                                                    <div class="vs-checkbox-con vs-checkbox-primary">
                                                        <input type="checkbox" value="{{ $product->id }}" name="prod_id[]"
                                                            class="change-check" id="checkbox-{{ $loop->iteration }}">
                                                        <span class="vs-checkbox">
                                                            <span class="vs-checkbox--check">
                                                                <i class="vs-icon feather icon-check"></i>
                                                            </span>
                                                        </span>
                                                    </div>
                                                </fieldset>
                                            </div>
                                        </td>
                                    @endcan
                                    <td>
                                        {{ $product->id }}
                                    </td>

                                    <td>
                                        <img src="{{ $product->getPoster() }}" class="w-100">
                                    </td>

                                    <td>
                                        @if (!$product->isAviable())
                                            <i class="fa fa-info-circle text-danger" data-toggle="tooltip"
                                                data-original-title="@lang('admin.no_publish')"></i>
                                        @endif
                                        {{ Str::limit($product->getName(), 30) }}
                                    </td>

                                    <td>
                                        @foreach ($product->categories as $category)
                                            {{ $category->getName() }}
                                        @endforeach
                                    </td>

                                    <td>
                                        @if ($product->price_discount)
                                            <strike>{{ number_format($product->getPrice(2), 5) }}</strike>
                                            USD
                                            <br>
                                            {{ number_format($product->getDiscountPrice()) }} USD
                                        @else
                                            {{ number_format($product->getPrice(2), 5) }} USD
                                        @endif
                                    </td>

                                    <td>
                                        {{ $product->count }}
                                    </td>

                                    <td>
                                        @if (!$product->isAviable())
                                            @lang('admin.no_publish')
                                        @else
                                            Опубликовано
                                        @endif
                                    </td>

                                    <td class="text-right">
                                        {{--                                            <a href="" class="btn btn-icon btn-info btn-sm" data-toggle="tooltip" data-original-title="@lang('admin.see')"> --}}
                                        {{--                                                <i class="feather icon-link"></i> --}}
                                        {{--                                            </a> --}}

                                        @can('update', 'products')
                                            <a href="{{ route('dashboard.product.update', $product->id) }}"
                                                class="btn btn-icon btn-primary btn-sm" data-toggle="tooltip"
                                                data-original-title="@lang('admin.edit')">
                                                <i class="feather icon-edit"></i>
                                            </a>
                                        @endcan

                                        @can('delete', 'products')
                                            <a href="{{ route('dashboard.product.delete', $product->id) }}"
                                                class="btn btn-icon btn-danger btn-sm" data-toggle="tooltip"
                                                onclick="return confirm('@lang('admin.are_you_sure')')"
                                                data-original-title="@lang('admin.delete')">
                                                <i class="feather icon-trash"></i>
                                            </a>
                                        @endcan
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="card-footer" id="show-action">
                    <button type="submit" name="action" value="delete"
                        class="btn btn-danger">@lang('admin.products.delete_mass')</button>
                        {{-- Product statusini activega o'zgartirish --}}
                    <button type="submit" name="action" value="status-active"
                            class="btn btn-success">@lang('admin.products.status-active')</button>
                    <button type="submit" name="action" value="status-deactivate"
                        class="btn btn-warning">@lang('admin.products.deactivate')</button>
                </div>
            </form>
        </div>
    </div>

    {{ $products->appends(request()->query())->links('pagination::bootstrap-4') }}

</div>
