<h1 class="title"><?= __('Market') ?></h1>

<ul class="breadcrumber">
    <li><a href="<?= url_to('/') ?>" data-ajax><?= __('Home') ?></a></li>
    <li class="active"><?= __('Account Market') ?></li>
</ul>

<div>
    <form class="form" id="search-account" action="<?= url_to('/market/accounts') ?>" style="display:flex;justify-content:space-between;align-items:center">
        <select name="order" onchange="$('#search-account').submit()">
            <option value=""></option>
            <?php foreach ($orders as $key => $value): ?>
                <option<?= $order === $key ? ' selected' : '' ?> value="<?= $key ?>"><?= $value ?></option>
            <?php endforeach ?>
        </select>

        <div>
            <input type="hidden" name="page" value="<?= $page ?>" />

            <input type="text" name="q" class="input" value="<?= $q ?>" />
            <button type="submit" class="btn"><?= __('Search') ?></button>
        </div>
    </form>
</div>

<hr>

<div class="account-market">
    <?php foreach ($accounts as $acc): ?>
        <?php $account = account($acc['account']) ?>

        <a href="<?= url_to('/market/accounts/' . $acc['id']) ?>" class="account">
            <div class="name"><?= $account->getName() ?></div>

            <div class="info">
                <ul>
                    <?php if (has_vip_system()): ?>
                        <li><strong><?= __('Account type') ?></strong>: <span class="text"><?= util('Account')->vipName($account->getVipType()) ?></span></li>
                        <?php if ($account->getVipType()): ?>
                            <li><strong><?= __('Maturity') ?></strong>: <span class="text"><?= ($account->getVipExpire() ? util('Date')->date($account->getVipExpire()) : '') ?></span></li>
                        <?php endif ?>
                    <?php endif ?>
                    <li><strong><?= __('Credits') ?></strong>: <span class="text"><?= util('Number')->currency($account->getCredit()) ?></span></li>
                    <?php foreach (config('coins', []) as $id => $coin): ?>
                        <li><strong><?= $coin['name'] ?></strong>: <span class="text"><?= util('Number')->format($account->getCoin($coin['id'])) ?></span></li>
                    <?php endforeach ?>
                </ul>
            </div>

            <div class="price">
                <span><?= util('Number')->currency($acc['price']) ?></span>
            </div>

            <div class="account-characters">
                <?php foreach ($account->getCharacters() as $character): ?>
                    <div class="account-character" data-tooltip data-tooltip-url="<?= url_to('/market/account/' . $acc['id'] . '/character/' . $character->getName()) ?>">
                        <img src="<?= util('Character')->avatar($character->getAvatar()) ?>" />
                    </div>
                <?php endforeach ?>
            </div>
        </a>
    <?php endforeach ?>
</div>
<?= $paginator->toHtml() ?>
