<?php 
    $data = array();
    $data['title'] = "Akakce | ".$config->get('site_title');
    $data['links'] = [];
    $data['styles'] = ['/admin/public/assets/css/jstable.css'];
    $data['header']['scripts'] = [];
    $data['version'] = $config->get('version');
    $data['csrf_token'] = $csrf_generator->create();
    $data['sidebar_menu'] = $menu->get(array('position'=>'sidebar'));
    $data['sidebar_active_menu'] = $menu->getActiveMenuItemId(trim($_SERVER['REQUEST_URI']));
    $data['footer']['scripts'] = ['/admin/public/assets/js/jstable.min.js','/admin/public/assets/js/pages/akakce.js'];
    $menu_items = $menu->get(array('position'=>'footer'));
    foreach($menu_items as $item){
        if($item['col'] == "1"){
            $data['menu']['footer']["1"][] = $item;
        }
        if($item['col'] == "2"){
            $data['menu']['footer']["2"][] = $item;
        }
        if($item['col'] == "3"){
            $data['menu']['footer']["3"][] = $item;
        }
        if($item['col'] == "4"){
            $data['menu']['footer']["4"][] = $item;
        }
    }

    $data['breadcrumbs'] = array();

    $data['breadcrumbs'][] = array(
        'text' => "Pano",
        'href' => "/admin",
        'index' => 1
    );
    $data['breadcrumbs'][] = array(
        'text' => "Akakce",
        'href' => "/admin/akakce",
        'index' => 2
    );

    $akakce = new Akakce($db, $utils, $product);

    $products         = $akakce->getProducts();
?>
<?php include DIR_VIEWS."parts/header.php"; ?>
        <main class="content">
            <div class="container-fluid">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title">Ürünler</h5>
                        <button type="button" class="btn btn-success btn-sm me-2" id="update-products"><i class="bi bi-arrow-clockwise"></i> Ürün Güncelle</button>
                        <button type="button" class="btn btn-success btn-sm me-2" id="update-prices"><i class="bi bi-arrow-clockwise"></i> Fiyat Güncelle</button>
                        <button type="button" class="btn btn-success btn-sm px-1" data-action="/admin/akakce/excel" data-report="prices" data-id="" data-export><i class="bi bi-file-earmark-excel"></i> Excel</button>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover table-bordered mb-0" id="product-table">
                                <thead>
                                    <tr>
                                        <th style="width:60px;">Resim</th>
                                        <th style="width:100px;">Durum</th>
                                        <th>Adı</th>
                                        <th>Akakce Satıcı</th>
                                        <th>Akakce Fiyat</th>
                                        <th>Site Fiyat</th>
                                        <th>Son Güncelleme</th>
                                        <th style="width:150px;"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        if(count($products)>0):
                                            foreach($products as $row): ?>
                                                <tr>
                                                    <td class="text-center"><a href="/public/assets/images/products/medium/<?php echo $row['image']; ?>" class="glightbox"> <img src="/public/assets/images/products/thumb/<?php echo $row['image']; ?>"/> </a></td>
                                                    <td style="width: 100px;" class="text-center"><?php echo $row['status_text']; ?></td>
                                                    <td><?php echo $row['title']; ?> <a href="<?php echo $row['akakce_url']; ?>" target="_blank" rel="noopener noreferrer"><i class="bi bi-send"></i></a></td>
                                                    <td><?php echo $row['akakce_seller']; ?></td>
                                                    <td><?php echo $utils->moneyFormatter($row['akakce_price']); ?></td>
                                                    <td><p class="<?php echo $row['selling_price'] <= $row['akakce_price'] ? 'text-success' : 'text-danger'; ?>"><?php echo $utils->moneyFormatter($row['selling_price']); ?></p></td>
                                                    <td><?php echo $row['date_modified']; ?></td>
                                                    <td style="width: 60px;vertical-align: middle;" class="text-center">
                                                        <a class="btn btn-sm btn-primary me-1" href="/admin/product/edit?id=<?php echo $row['product_id']; ?>" target="_blank"><i class="bi bi-pencil-square"></i></a>
                                                        <button type="button" class="btn btn-sm btn-warning" data-url="<?php echo $row['id']; ?>"><i class="bi bi-tags"></i></button>
                                                        <button type="button" class="btn btn-sm btn-danger" data-delete data-href="/admin/akakce/delete?id=<?php echo $row['id']; ?>"><i class="bi bi-trash"></i></button>
                                                    </td>
                                                </tr>
                                        <?php endforeach; ?>
                                    <?php else: 
                                            echo "<tr class=\"text-center\"><td colspan=\"7\">Hiçbir kayıt bulunamadı!</td></tr>";
                                        endif;
                                    ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </main>

        <div class="modal" id="please-wait-modal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered">
                <div class="modal-content">
                    <div class="modal-body">
                        <div class="d-flex justify-content-center">
                            <div class="spinner-border m-5" role="status" style="width: 3rem; height: 3rem;" role="status">
                                <span class="visually-hidden">Loading...</span>
                            </div>
                        </div>
                        <div class="text-center">
                        <h3>İşleminiz devam ediyor. Lütfen bekleyin.</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
<?php include DIR_VIEWS."parts/footer.php"; ?>