<?php
$user_id = get_current_user_id();
$user_vip = yascode_vip::get_user_vip_status($user_id);
$days_left = (!empty($user_vip['days_left'])) ? $user_vip['days_left'] . ' روز' : 'نامحدود';
$count_watchlist = yascode_watchlist::get_user_count_watchlist($user_id); ?>
<div class="dashboard rt">
    <div class="main">
        <div class="top-items rt">
            <div class="item right rt-10px rt-bg rt-overflow item-1">
                <div class="titles rt-fff rt-14 rt-bold rt-align rt">اشتراک ویژه</div>
                <div class="ins rt">
                    <div class="tits right">
                        <span class="rt rt-bold rt-16 rang"><?php echo ($user_vip['status'] == true) ? 'فعال' : 'غیرفعال'; ?> <i class="blue-check"></i></span>
                        <span class="rt rt-13 rt-777">مشترک ویژه <?php echo ($user_vip['status'] == true) ? 'هستید' : 'نیستید'; ?></span>
                    </div>
                    <i class="fa fa-star left rt-27 rt-999 icon"></i>
                </div>
            </div>
            <div class="item right rt-10px rt-bg rt-overflow item-2">
                <div class="titles rt-fff rt-14 rt-bold rt-align rt">تاریخ سر رسید</div>
                <div class="ins rt">
                    <div class="tits right">
                        <span class="rt rt-bold rt-16 rang"><?php echo ($user_vip['status']) ? $days_left : "0" ?></span>
                        <span class="rt rt-13 rt-777"><?php echo ($user_vip['status']) ? 'دیگر منقضی میشود' : "فاقد اشتراک" ?></span>
                    </div>
                    <i class="fa fa-calendar left rt-27 rt-999 icon"></i>
                </div>
            </div>
            <div class="item right rt-10px rt-bg rt-overflow item-3">
                <div class="titles rt-fff rt-14 rt-bold rt-align rt">نوع اشتراک</div>
                <div class="ins rt">
                    <div class="tits right">
                        <span class="rt rt-bold rt-16 rang">
                            VIP</span>
                        <span class="rt rt-13 rt-777"><?php echo ($user_vip['status'] == true) ? 'فعال' : 'غیرفعال'; ?> است</span>
                    </div>
                    <i class="fa fa-info-circle left rt-27 rt-999 icon"></i>
                </div>
            </div>
            <div class="item right rt-10px rt-bg rt-overflow item-4">
                <div class="titles rt-fff rt-14 rt-bold rt-align rt">ذخیره شده ها</div>
                <div class="ins rt">
                    <div class="tits right">
                        <span class="rt rt-bold rt-16 rang"><?php echo $count_watchlist . " آیتم"; ?></span>
                        <span class="rt rt-13 rt-777">در لیست علاقه مندی</span>
                    </div>
                    <i class="fa fa-bookmark left rt-27 rt-999 icon"></i>
                </div>
            </div>
        </div>

        <?php
        $vip_active = yascode_vip::is_active();
        if ($vip_active) :
            $per_page = 10;
            $paged = (!empty($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;
            $transactions = yascode_vip::get_user_transactions($user_id, $per_page, $paged); ?>
            <?php if (!empty($transactions['items'])) { ?>
                <div class="list-of-orders rt rt-bg rt-shadow rt-444 rt-15 rt-10px">
                    <h4 class="rt rt-bold rt-18 rt-999">لیست سفارشات</h4>
                    <table class="rcp-table">
                        <thead>
                            <tr>
                                <th>شناسه</th>
                                <th>مبلغ</th>
                                <th>شناسه پیگیری</th>
                                <th>اشتراک</th>
                                <th>تاریخ</th>
                                <th>وضعیت</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($transactions['items'] as $transaction) :
                                $ID = (!empty($transaction->ID)) ? $transaction->ID : '';
                                $trans = (!empty($transaction->transaction)) ? $transaction->transaction : '';
                                $price = (!empty($transaction->price)) ? number_format($transaction->price) : 0;
                                $stats = (!empty($transaction->status)) ? yascode_vip::get_payment_status_info($transaction->status) : array();
                                $days = (!empty($transaction->days)) ? change_days_to_human($transaction->days) : '';
                                $created_at = (!empty($transaction->created_at)) ? jdate('H:i:s - Y/m/d', strtotime($transaction->created_at)) : ''; ?>
                                <tr>
                                    <td><?php echo "#" . $ID; ?></td>
                                    <td><?php echo $price . ' تومان'; ?></td>
                                    <td><?php echo $trans; ?></td>
                                    <td><?php echo (!empty($days) && is_array($days)) ? $days['number'] . ' ' . $days['type'] . 'ه' : 'نامشخص'; ?></td>
                                    <td><?php echo $created_at; ?></td>
                                    <td class="<?php echo $stats['class']; ?>"><?php echo $stats['name']; ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                    <?php if (!empty($transactions['total_pages']) && $transactions['total_pages'] > 1) { ?>
                        <div class="paginate rt rt-align rt-15">
                            <?php
                            $big = 999999999;
                            echo paginate_links(array(
                                'base' => remove_query_arg('page', get_pagenum_link(1)) . '%_%',
                                'format' => '?page=%#%',
                                'current' => max(1, $paged),
                                'total' => $transactions['total_pages'],
                                'prev_text' => 'صفحه پیشین',
                                'next_text' => 'صفحه بعد',
                                'type' => 'link',
                                'show_all' => false,
                                'end_size' => 7,
                                'mid_size' => 1
                            )); ?>
                        </div>
                    <?php } ?>
                </div>
            <?php } ?>
        <?php endif; ?>

    </div>
</div>