<%- include('./includes.ejs') %>

    <style>
        :root {
            --muted: #9aa3b2;
        }

        .sub-detail-container {
            max-width: 1100px;
            margin: 0 auto;
            padding: 24px 16px;
        }

        .section-divider {
            display: flex;
            align-items: center;
            gap: 12px;
            margin: 28px 0 18px;
        }

        .section-divider .divider-icon {
            width: 40px;
            height: 40px;
            border-radius: 12px;
            background: linear-gradient(135deg, #0d6efd, #0850c4);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 17px;
            flex-shrink: 0;
            box-shadow: 0 4px 12px rgba(13, 110, 253, .25);
        }

        .section-divider .divider-text {
            font-size: 18px;
            font-weight: 800;
            color: var(--bs-body-color);
            letter-spacing: -.2px;
        }

        .section-divider .divider-line {
            flex: 1;
            height: 2px;
            background: linear-gradient(90deg, var(--bs-border-color), transparent);
            border-radius: 2px;
        }

        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 18px;
            margin-top: 12px;
        }

        .stat-card {
            border-radius: 14px;
            padding: 20px 22px;
            background: var(--bs-card-bg);
            box-shadow: var(--bs-box-shadow);
            border: 1px solid var(--bs-border-color);
            transition: all .3s ease;
            position: relative;
            overflow: hidden;
        }

        .stat-card::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 3px;
            background: linear-gradient(90deg, #0d6efd, #0850c4);
        }

        .stat-card:hover {
            transform: translateY(-2px);
            box-shadow: var(--bs-box-shadow-lg);
        }

        .stat-card .stat-label {
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 700;
            font-size: 13px;
            color: var(--bs-secondary-color);
            margin-bottom: 8px;
            text-transform: uppercase;
            letter-spacing: .3px;
        }

        .stat-card .stat-label i {
            font-size: 15px;
            color: #0d6efd;
        }

        .stat-card .stat-value {
            font-size: 18px;
            font-weight: 800;
            color: var(--bs-body-color);
            letter-spacing: -.2px;
            line-height: 1.4;
        }

        .stat-card .stat-value.text-success-custom {
            color: #16a34a;
        }

        .package-status {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 8px 16px;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 800;
        }

        .package-status.status-active {
            background: #dcfce7;
            color: #166534;
        }

        .package-status.status-expired {
            background: #fee2e2;
            color: #dc2626;
        }

        .package-status.status-cancelled {
            background: #fee2e2;
            color: #991b1b;
        }

        .package-status.status-unknown {
            background: #e5e7eb;
            color: #374151;
        }

        .subscriber-header-card {
            border-radius: 18px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 22px 26px;
            margin-bottom: 8px;
            background: var(--bs-card-bg);
            box-shadow: var(--bs-box-shadow-lg);
            border: 2px solid #0d6efd;
            position: relative;
            overflow: hidden;
            gap: 16px;
            flex-wrap: wrap;
        }

        .subscriber-header-card::before {
            content: "";
            position: absolute;
            inset: -1px;
            border-radius: 18px;
            pointer-events: none;
            background: linear-gradient(135deg, rgba(13, 110, 253, .15), rgba(13, 110, 253, 0) 45%);
        }

        .subscriber-header-card .sub-icon {
            width: 64px;
            height: 64px;
            flex-shrink: 0;
            border-radius: 50%;
            background: radial-gradient(120% 120% at 30% 30%, #49b6f3 0, #2aa6e1 60%, #1e8dc4 100%);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 28px;
            border: 3px solid #eaf6ff;
            box-shadow: 0 8px 20px rgba(41, 167, 225, .35);
            overflow: hidden;
        }

        .subscriber-header-card .sub-icon img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .subscriber-header-card .sub-info {
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 4px;
        }

        .subscriber-header-card .sub-name {
            font-weight: 800;
            font-size: 20px;
            color: var(--bs-body-color);
        }

        .subscriber-header-card .sub-meta {
            font-size: 13px;
            color: var(--bs-secondary-color);
        }

        .subscriber-header-card .badge-cluster {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
        }

        @media (max-width:768px) {
            .subscriber-header-card {
                flex-direction: column;
                text-align: center;
                align-items: center;
            }

            .subscriber-header-card .sub-info {
                align-items: center;
            }

            .stats-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>

    <section id="multiple-column-form">
        <div class="sub-detail-container">
                <!-- Header -->
                <div class="subscriber-header-card">
                    <div class="sub-icon">
                        <% if (productImages && productImages[0]) { %>
                            <img src="<%= productImages[0] %>" alt="<%= product.name || 'Product' %>">
                            <% } else { %>
                                <i class="ti ti-crown"></i>
                                <% } %>
                    </div>
                    <div class="sub-info">
                        <span class="sub-name">
                            <%= product.name || '—' %>
                        </span>
                        <span class="sub-meta">#<%= product.number || '' %></span>
                    </div>
                    <div class="badge-cluster">
                        <% if (product.presentation.goldPending) { %>
                            <span class="badge bg-label-warning"
                                style="padding:8px 12px;font-size:12px;font-weight:700;">
                                <i class="ti ti-clock me-1"></i>
                                <%= i18n.__('products.goldPending') %>
                            </span>
                            <% } else if (product.isGold) { %>
                                <span class="badge bg-label-warning"
                                    style="padding:8px 12px;font-size:12px;font-weight:700;">
                                    <i class="ti ti-crown me-1"></i>
                                    <%= i18n.__('products.gold') %>
                                </span>
                                <% } %>
                                    <span class="package-status <%= product.presentation.productStatusClass %>"
                                        style="font-size:13px;padding:8px 14px;">
                                        <%= product.presentation.productStatusLabelKey
                                            ? i18n.__(product.presentation.productStatusLabelKey)
                                            : (product.status || '—') %>
                                    </span>
                    </div>
                </div>

                <!-- Provider Info -->
                <div class="section-divider">
                    <div class="divider-icon"><i class="ti ti-store"></i></div>
                    <span class="divider-text">
                        <%= i18n.__('products.provider') %>
                    </span>
                    <div class="divider-line"></div>
                </div>
                <div class="stats-grid">
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-user"></i>
                            <%= i18n.__('common.name') %>
                        </div>
                        <div class="stat-value">
                            <%= product.provider?.name || '—' %>
                        </div>
                    </div>
                </div>

                <!-- Product Info -->
                <div class="section-divider">
                    <div class="divider-icon"><i class="ti ti-info-circle"></i></div>
                    <span class="divider-text">
                        <%= i18n.__('products.productDetails') %>
                    </span>
                    <div class="divider-line"></div>
                </div>
                <div class="stats-grid">
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-cash"></i>
                            <%= i18n.__('common.price') %>
                        </div>
                        <div class="stat-value text-success-custom">
                            <%= product.price || 0 %>
                                <%= i18n.__('common.currency') %>
                        </div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-package"></i>
                            <%= i18n.__('products.count') %>
                        </div>
                        <div class="stat-value">
                            <%= product.count || 0 %>
                        </div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-calendar"></i>
                            <%= i18n.__('products.validityPeriod') %>
                        </div>
                        <div class="stat-value">
                            <%= productExpireAt || '—' %>
                        </div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-map-pin"></i>
                            <%= i18n.__('common.region') %>
                        </div>
                        <div class="stat-value">
                            <%= product.region && typeof product.region==='object' ? (product.region.name?.[lang] ||
                                product.region.name || '—' ) : '—' %>
                        </div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-category"></i>
                            <%= i18n.__('products.subDepartment') %>
                        </div>
                        <div class="stat-value">
                            <%= product.subDepartment && typeof product.subDepartment==='object' ?
                                (product.subDepartment.name?.[lang] || product.subDepartment.name?.[lang] || '—' ) : '—'
                                %>
                        </div>
                    </div>
                    <div class="stat-card" style="grid-column: 1 / -1;">
                        <div class="stat-label"><i class="ti ti-notes"></i>
                            <%= i18n.__('products.details') %>
                        </div>
                        <div class="stat-value" style="font-size:14px;font-weight:700;">
                            <%= product.details || '—' %>
                        </div>
                    </div>
                    <div class="stat-card" style="grid-column: 1 / -1;">
                        <div class="stat-label"><i class="ti ti-list-details"></i>
                            <%= i18n.__('products.instructions') %>
                        </div>
                        <div class="stat-value" style="font-size:14px;font-weight:700;">
                            <%= product.instructions || '—' %>
                        </div>
                    </div>
                    <div class="stat-card">
                        <div class="stat-label"><i class="ti ti-crown"></i>
                            <%= i18n.__('products.goldStatus') %>
                        </div>
                        <div class="stat-value">
                            <%= i18n.__(product.presentation.goldStatusLabelKey) %>
                        </div>
                    </div>
                </div>

                <!-- Admin Rate -->
                <div class="section-divider">
                    <div class="divider-icon"><i class="ti ti-star"></i></div>
                    <span class="divider-text">
                        <%= i18n.__('products.adminRateTitle') %>
                    </span>
                    <div class="divider-line"></div>
                </div>

                <div class="stats-grid">
                    <div class="stat-card full-width">
                        <div class="stat-label"><i class="ti ti-star"></i>
                            <%= i18n.__('common.rate') %>
                        </div>

                        <% const currentRate=adminRate?.rate ? parseInt(adminRate.rate, 10) : 0; const
                            currentComment=adminRate?.comment || '' ; %>

                            <div class="d-flex align-items-center gap-2 flex-wrap" style="margin-top:6px;">
                                <div class="d-inline-flex align-items-center gap-1" id="adminRateStars"
                                    data-current="<%= currentRate %>">
                                    <% for (let s=1; s <=5; s++) { %>
                                        <i class="ti <%= s <= currentRate ? 'ti-star-filled text-warning' : 'ti-star text-muted' %> rate-star"
                                            data-value="<%= s %>" style="font-size:22px;cursor:pointer;"></i>
                                        <% } %>
                                </div>
                                <span class="text-muted" style="font-size:12px;">
                                    (<span id="adminRateValue">
                                        <%= currentRate %>
                                    </span>/5)
                                </span>
                            </div>

                            <form id="adminRateForm" class="mt-3" data-product-id="<%= product?._id || '' %>">
                                <input type="hidden" name="_csrf" value="<%= csrfToken %>">
                                <input type="hidden" name="rate" id="adminRateInput" value="<%= currentRate %>">
                                <div class="mb-2">
                                    <label class="form-label">
                                        <%= i18n.__('common.comment') %>
                                    </label>
                                    <textarea class="form-control" name="comment" id="adminRateComment" rows="3"
                                        placeholder="<%= i18n.__('common.{{field}}Placeholder', { field: i18n.__('common.comment') }) %>"><%= currentComment %></textarea>
                                </div>
                                <div class="d-flex justify-content-end">
                                    <button type="submit" class="btn btn-primary"
                                        style="border-radius:12px;font-weight:700;">
                                        <i class="ti ti-device-floppy me-1"></i>
                                        <%= i18n.__('products.saveRate') %>
                                    </button>
                                </div>
                            </form>
                    </div>
                </div>

                <!-- Images -->
                <div class="section-divider">
                    <div class="divider-icon"><i class="ti ti-photo"></i></div>
                    <span class="divider-text">
                        <%= i18n.__('common.images') %>
                    </span>
                    <div class="divider-line"></div>
                </div>
                <div class="stats-grid">
                    <div class="stat-card" style="grid-column: 1 / -1;">
                        <% if (productImages && productImages.length> 0) { %>
                            <div class="d-flex flex-wrap gap-3">
                                <% productImages.forEach(function(img, idx) { %>
                                    <a href="<%= img %>" target="_blank" class="position-relative d-block">
                                        <img src="<%= img %>" alt="<%= product.name || 'Product' %> - <%= idx + 1 %>"
                                            class="rounded shadow-sm border"
                                            style="width: 150px; height: 150px; object-fit: cover; transition: all .3s ease; cursor: pointer;"
                                            loading="lazy">
                                    </a>
                                    <% }); %>
                            </div>
                            <% } else { %>
                                <div class="text-center py-4 text-muted">
                                    <%= i18n.__('common.noImages') %>
                                </div>
                                <% } %>
                    </div>
                </div>

                <!-- Actions -->
                <div class="section-divider">
                    <div class="divider-icon"><i class="ti ti-settings"></i></div>
                    <span class="divider-text">
                        <%= i18n.__('common.control') %>
                    </span>
                    <div class="divider-line"></div>
                </div>
                <div class="stats-grid">
                    <div class="stat-card" style="grid-column: 1 / -1;">
                        <div class="d-flex flex-wrap gap-2">
                            <% if (product.presentation.goldPending) { %>
                                <button class="btn btn-success approve-gold-btn" data-id="<%= product._id %>">
                                    <i class="ti ti-circle-check me-1"></i>
                                    <%= i18n.__('products.approveGold') %>
                                </button>
                                <button class="btn btn-danger reject-gold-btn" data-id="<%= product._id %>">
                                    <i class="ti ti-circle-x me-1"></i>
                                    <%= i18n.__('products.rejectGold') %>
                                </button>
                                <% } %>
                                    <a href="/dashboard/products/goldRequests" class="btn btn-outline-secondary">
                                        <i class="ti ti-arrow-<%= lang === 'ar' ? 'right' : 'left' %> me-1"></i>
                                        <%= i18n.__('common.referer') %>
                                    </a>
                        </div>
                    </div>
                </div>
        </div>
    </section>
