<div>
    <div class="card-header">
        <div class="d-flex justify-content-between align-items-center">
            <strong>Ürünler</strong>

            <div class="d-flex align-items-center gap-2">
                <div class="input-group w-50 position-relative">
                    <select class="form-select" wire:model.live="paginate" id="paginate">
                        <option value="10">10</option>
                        <option value="25">25</option>
                        <option value="50">50</option>
                        <option value="100">100</option>
                        <option value="250">250</option>
                        <option value="500">500</option>
                    </select>
                </div>

                <div class="input-group w-100 position-relative">
                    <input type="text" class="form-control" placeholder="Ara..." wire:model.live.debounce.150ms="search">
                    <div class="position-relative top-0 end-0 mt-1 me-2" wire:loading>
                        <div class="spinner-border" role="status" style="margin-left:10px;">
                            <span class="visually-hidden">Yükleniyor...</span>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <div class="card-body">
        <div class="example">
            <div class="tab-content rounded-bottom">
                <div class="tab-pane active preview" role="tabpanel" id="preview-1005">
                    <table class="table table-condensed table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th scope="col">Başlık</th>
                                <th scope="col">Figure</th>
                                <th class="text-center">Kategori</th>
                                <th>Materyal</th>
                                <th>End</th>
                                @canany(['product.update', 'product.delete'])
                                    <th scope="col">İşlem</th>
                                @endcanany
                            </tr>
                        </thead>
                        <tbody wire:sortable="updateOrder">
                            @foreach ($this->products as $product)
                                <tr wire:sortable.item="{{ $product->id }}" wire:key="item-{{ $product->id }}">
                                    <td wire:sortable.handle style="cursor:move;">
                                        {{ $product->title }}
                                    </td>
                                    <td>
                                        {{ $product->dikkan_figure }}
                                    </td>
                                    <td class="text-center">
                                        @php
                                            $specificCategory = $product->taxonomies->firstWhere(function($taxonomy) {
                                                return in_array($taxonomy->parent_id, [
                                                    \App\Enums\ProductCategories::MARINE->value,
                                                    \App\Enums\ProductCategories::WATERWORKS->value,
                                                    \App\Enums\ProductCategories::MARITIME->value,
                                                    \App\Enums\ProductCategories::REMOTE->value
                                                ]);
                                            });
                                        @endphp

                                        @if($specificCategory)
                                            {{ $specificCategory->parent->name }} -
                                            {{ ucwords(strtolower($specificCategory->name)) }}
                                        @else
                                            -
                                        @endif
                                    </td>
                                    <td>
                                        @foreach ($product->taxonomiesByCategory(\App\Enums\ProductCategories::MATERIAL) as $taxonomy)
                                            {{ $taxonomy->name }}
                                        @endforeach
                                    </td>
                                    <td>
                                        @foreach ($product->taxonomiesByCategory(\App\Enums\ProductCategories::END) as $taxonomy)
                                            {{ $taxonomy->name }}
                                        @endforeach
                                    </td>
                                    @canany(['product.update', 'product.delete'])
                                        <td>
                                            @can('product.update')
                                                <a href="{{ route('admin.products.edit', $product->id) }}" class="btn btn-sm btn-outline-primary">
                                                    <span class="cil-pencil"></span>
                                                </a>
                                            @endcan

                                            @can('product.delete')
                                                <button type="button" wire:click="deleteConfirm({{ $product->id }})" wire:loading.attr="disabled" class="btn btn-sm btn-outline-secondary text-secondary">
                                                    <span class="cil-trash"></span>
                                                </button>
                                            @endcan
                                        </td>
                                    @endcanany
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="px-4">
        {{ $this->products->links() }}
    </div>
</div>
