<?php
/**
 * @version 7.4
 */
/** @var \Ppb\Db\Table\Row\User $user */
/** @var \Ppb\Db\Table\Row\StoreSubscription $subscription */
$subscription = null;
if ($user['store_subscription_id']) {
    $subscription = $user->findParentRow('\Ppb\Db\Table\StoresSubscriptions');
}

$this->storeSubscription($subscription);
?>

<div class="user-box">
    <div>
        <dl>
            <dd>
                <div class="lead">
                    <?php echo $this->_('Status:'); ?>
                    <?php echo ($user['store_active']) ?
                        '<span class="text-success">' . $this->_('Enabled') . '</span>' :
                        '<span class="text-danger">' . $this->_('Disabled') . '</span>'; ?>

                    <div class="pull-right">
                        <?php if ($user['store_active']) { ?>
                            <?php if ($user['store_subscription_id']) { ?>
                                <a href="<?php echo $this->url(array('module' => 'app', 'controller' => 'payment', 'action' => 'store-subscription')); ?>"
                                   class="btn btn-small btn-primary"><?php echo $this->_('Renew'); ?></a>
                            <?php } ?>
                            <a href="<?php echo $this->url(array('module' => 'members', 'controller' => 'store', 'action' => 'disable')); ?>"
                               class="btn btn-small btn-danger"><?php echo $this->_('Disable'); ?></a>
                        <?php
                        }
                        else if ($user['store_subscription_id']) {
                            ?>
                            <a href="<?php echo $this->url(array('module' => 'app', 'controller' => 'payment', 'action' => 'store-subscription')); ?>"
                               class="btn btn-small btn-success"><?php echo $this->_('Enable'); ?></a>
                        <?php } ?>
                    </div>
                </div>
            </dd>
            <dt><?php echo $this->_('Subscription'); ?></dt>
            <dd>
                <?php if ($user['store_subscription_id']) { ?>
                    <?php echo $this->_($subscription['name']); ?>
                    <?php if ($user['store_next_payment']) { ?>
                        - <?php echo $this->_('expires on'); ?> <?php echo $this->date($user['store_next_payment'], true); ?>

                    <?php } ?>
                <?php
                }
                else {
                    ?>
                    <?php echo ($user['store_active']) ? $this->_('Default Account') : $this->_('none'); ?>
                <?php } ?>

            </dd>
            <?php if ($user['store_subscription_id']) { ?>
                <dd>
                    <?php echo $this->storeSubscription()->description(); ?>
                </dd>
                <dt><?php echo $this->_('Listings'); ?></dt>
                <dd>
                    <?php echo sprintf(
                        $this->_('%s listed, %s remaining'),
                        ($count = $user->countStoreListings()),
                        ((($remaining = ($subscription['listings'] - $count)) > 0) ? $remaining : 0)); ?>
                </dd>
            <?php } ?>

            <?php if ($user['store_active']) { ?>
                <dt><?php echo $this->_('Store URL'); ?></dt>
                <dd>
                    <?php $storeLink = $this->url($user->storeLink()); ?>

                    <a href="<?php echo $storeLink; ?>" target="_blank"><?php echo $storeLink; ?></a>
                </dd>
            <?php } ?>
        </dl>
    </div>
</div>

<div class="clearfix"></div>