<div class="table-responsive">
    <% if (!products.length) { %>
        <%- include('../includes/notFound.ejs') %>
            <% } else { %>
                <table class="table data-list-view">
                    <thead>
                        <tr>
                            <th>
                                <%= i18n.__('common.date') %>
                            </th>
                            <th>
                                <%= i18n.__('common.image') %>
                            </th>
                            <th>
                                <%= i18n.__('common.name') %>
                            </th>
                            <th>
                                <%= i18n.__('products.provider') %>
                            </th>
                            <th>
                                <%= i18n.__('advertisement.price') %>
                            </th>
                            <th>
                                <%= i18n.__('common.region') %>
                            </th>
                            <th>
                                <%= i18n.__('products.count') %>
                            </th>
                            <th>
                                <%= i18n.__('common.status') %>
                            </th>
                            <th>
                                <%= i18n.__('products.goldStatus') %>
                            </th>
                            <th>
                                <%= i18n.__('common.control') %>
                            </th>
                        </tr>
                    </thead>
                    <tbody id="filteredDataContainer">
                        <% products.forEach(function(product) { %>
                            <tr id="tr<%= product._id %>">
                                <td>
                                    <span class="text-muted">
                                        <i class="ti ti-calendar me-1"></i>
                                        <%= moment(product.createdAt).locale(lang).format('YYYY/MM/DD') %>
                                    </span>
                                </td>

                                <td>
                                    <div class="avatar avatar-sm">
                                        <img src="<%= product.imageUrl || '/admin/app-assets/images/pages/404.png' %>"
                                            alt="<%= product.name || 'Product' %>" class="rounded"
                                            style="width: 45px; height: 45px; object-fit: cover;" loading="lazy">
                                    </div>
                                </td>

                                <td>
                                    <div class="d-flex flex-column">
                                        <span class="fw-semibold text-heading">
                                            <%= product.name ? (product.name.length> 30 ? product.name.substring(0, 30)
                                                + '...' : product.name) : '—' %>
                                        </span>
                                        <% if (product.number) { %>
                                            <small class="text-muted">#<%= product.number %></small>
                                            <% } %>
                                    </div>
                                </td>

                                <td>
                                    <% if (product.provider && typeof product.provider==='object' ) { %>
                                        <div class="d-flex align-items-center">
                                            <i class="ti ti-store text-primary me-1"></i>
                                            <span>
                                                <%= product.provider.name || '—' %>
                                            </span>
                                        </div>
                                        <% } else { %>
                                            <span class="text-muted">—</span>
                                            <% } %>
                                </td>

                                <td>
                                    <span class="fw-semibold">
                                        <%= product.price ? product.price.toLocaleString() : '—' %>
                                            <%= i18n.__('common.currency') %>
                                    </span>
                                </td>

                                <td>
                                    <% if (product.region && typeof product.region==='object' ) { %>
                                        <div class="d-flex align-items-center">
                                            <i class="ti ti-map-pin text-info me-1"></i>
                                            <span>
                                                <%= product.region.name?.[lang] || product.region.name || '—' %>
                                            </span>
                                        </div>
                                        <% } else { %>
                                            <span class="text-muted">—</span>
                                            <% } %>
                                </td>

                                <td>
                                    <span
                                        class="badge <%= product.count > 0 ? 'bg-label-success' : 'bg-label-danger' %>">
                                        <i class="ti ti-package me-1"></i>
                                        <%= product.count || 0 %>
                                    </span>
                                </td>

                                <td>
                                    <span class="badge <%= product.presentation.productStatusBadgeClass %>">
                                        <% if (product.presentation.productStatusIcon) { %>
                                            <i class="ti <%= product.presentation.productStatusIcon %> me-1"></i>
                                        <% } %>
                                        <%= product.presentation.productStatusLabelKey
                                            ? i18n.__(product.presentation.productStatusLabelKey)
                                            : (product.status || '—') %>
                                    </span>
                                </td>

                                <td>
                                    <span class="badge <%= product.presentation.goldStatusBadgeClass %>">
                                        <% if (product.presentation.goldStatusIcon) { %>
                                            <i class="ti <%= product.presentation.goldStatusIcon %> me-1"></i>
                                        <% } %>
                                        <%= i18n.__(product.presentation.goldStatusLabelKey) %>
                                    </span>
                                </td>

                                <td>
                                    <div class="d-inline-block text-nowrap">
                                        <a href="/dashboard/products/goldRequests/show/<%= product._id %>"
                                            class="btn btn-sm btn-icon" title="<%= i18n.__('common.view') %>"
                                            data-bs-toggle="tooltip">
                                            <i class="text-info ti ti-eye"></i>
                                        </a>
                                    </div>
                                </td>
                            </tr>
                            <% }); %>
                    </tbody>
                </table>
                <div class="d-flex justify-content-center mt-3">
                    <nav aria-label="Page navigation"><%- paginationHtml %></nav>
                </div>
                <% } %>
</div>
