<?php
$uid       = Pi::user()->getId();
$userName  = Pi::user()->get($uid, 'name');
$firstName = Pi::user()->get($uid, 'first_name');

if (!isset($groups)) {
    $groups = Pi::registry('display_group', 'user')->read();
}
array_walk($groups, function (&$group, $gid) {
    $action       = $group['compound'] ? 'edit.compound' : 'edit.profile';
    $group['url'] = Pi::service('url')->assemble('user', [
        'module'     => 'user',
        'controller' => 'profile',
        'action'     => $action,
        'group'      => $gid,
    ]);
});
$userConfig = Pi::service('registry')->config->read('user');
$guideConfig = Pi::service('registry')->config->read('guide');

$isPerso = (bool) (
    ($controller == 'dashboard')
    || (isset($sideActive) && $sideActive == 'request')
    || (($module == "guide" && $controller == 'manage' && $action == 'contributions'))
    || ($module == 'favourite')
    || ($module == 'comment')
    || ($module == 'user' && $controller != 'dashboardPro')
);

if (empty($item)) {
    $item = ['id' => 0];
}
?>
<div class="clearfix sticky-top sticky-top-sidebar sticky-top-sidebar-usersection <?php echo $isPerso ? 'sticky-top-sidebar-perso' : 'sticky-top-sidebar-pro' ?>">
    <?php if ($userConfig['dashboard_enable']) { ?>
        <div class="custom-control custom-switch custom-switch-usersection p-4">
            <label class="custom-control-label-perso text-warning" for="switch-pro"><?php _e('Perso') ?></label>
            <input type="checkbox" class="custom-control-input" id="switch-pro" value="1" <?php if(!$isPerso) echo 'checked="checked"' ?> data-toggle="toggle" data-target="#nav-pro">
            <label class="custom-control-label custom-control-label-pro <?php echo $isPerso ? 'text-muted' : 'text-warning' ?>" for="switch-pro"><?php _e('Pro') ?></label>
        </div>
    <?php } ?>

    <!-- PERSO -->
    <div id="nav-perso" class="nav flex-column nav-pills <?php if(!$isPerso) echo 'd-none' ?>">
        <?php if ($userConfig['dashboard_enable']) { ?>
            <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'dashboard'])); ?>"
               class="nav-link rounded-0 <?php echo $controller == 'dashboard' ? 'active' : '' ?>">
                <span class="fa-minimized fas fa-tachometer-alt d-none"></span>
                <span class="label"><?php _e('Personal Dashboard') ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (Pi::service('module')->isActive('guide')) { ?>
            <a href="<?php echo Pi::url($this->url('guide', ['module' => 'guide', 'controller' => 'request', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'request') {echo ' active';} ?>">
                <span class="fa-minimized far fa-calendar-check d-none"></span>
                <span class="label"><?php _e('Bookings'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if ($guideConfig['manage_active'] && $guideConfig['manage_contribution']) { ?>
            <a href="<?php echo Pi::url($this->url('guide', ['module' => 'guide', 'controller' => 'manage', 'action' => 'contributions'])); ?>"
               class="nav-link rounded-0 <?php if ($module == "guide" && $controller == 'manage' && $action == 'contributions') {echo ' active';} ?>">
                <span class="fa-minimized fas fa-puzzle-piece d-none"></span>
                <span class="label"><?php _e('Contributions'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('favourite', $userConfig['side_menu']) && Pi::service('module')->isActive('favourite')) { ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'favourite', 'controller' => 'index', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'favourite') {echo ' active';} ?>">
                <span class="fa-minimized fas fa-heart d-none"></span>
                <span class="label"><?php _e('Favorites'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('comment', $userConfig['side_menu']) && Pi::service('module')->isActive('comment')) { ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'comment', 'controller' => 'my'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'comment') { echo ' active';} ?>">
                <?php _e('Reviews/comments'); ?> <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('media', $userConfig['side_menu']) && Pi::service('module')->isActive('media')) { ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'media', 'controller' => 'list', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'media') { echo ' active'; } ?>">
                <span class="fa-minimized far fa-images d-none"></span>
                <span class="label"><?php _e('My Media'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('video', $userConfig['side_menu']) && Pi::service('module')->isActive('video')) { ?>
            <a href="<?php echo Pi::url($this->url('video', ['module' => 'video', 'controller' => 'dashboard', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'videoDashboard') { echo ' active'; } ?>">
                <?php _e('Manage Videos'); ?> <span class='fas fa-angle-right'></span>
            </a>
            <a href="<?php echo Pi::url($this->url('video', ['module' => 'video', 'controller' => 'dashboard', 'action' => 'purchased'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'videoPurchased') { echo ' active'; } ?>">
                <?php _e('Purchased Videos'); ?> <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <div class="position-relative">
            <a class="nav-link rounded-0 collapsed" role="button" data-toggle="collapse"
               href="#collapseItemPerso">
                <span class="fa-minimized fas fa-user d-none"></span>
                <span class="label"><?php echo __('My account') ?></span>
                <span class='fa fa-caret-down float-right mt-1'></span>
            </a>
            <div id="collapseItemPerso" class="panel-collapse collapse <?php if ($module == 'user' && $controller != 'dashboard') echo 'show' ?>" role="tabpanel">
                <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'profile'])); ?>"
                   class="nav-link rounded-0 pl-5 <?php if ($controller == 'profile') {echo ' active';} ?>">
                    <?php echo _e('Manage account'); ?> <span class='fas fa-angle-right'></span>
                </a>

                <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'account'])); ?>"
                   class="nav-link rounded-0 pl-5 <?php if ($controller == 'account') {echo ' active';} ?>">
                    <?php _e('Account settings') ?> <span class='fas fa-angle-right'></span>
                </a>
                <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'password'])); ?>"
                   class="nav-link rounded-0 pl-5 <?php if ($controller == 'password') {echo ' active';} ?>">
                    <?php _e('Change password'); ?> <span class='fas fa-angle-right'></span>
                </a>
                <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'avatar'])); ?>"
                   class="nav-link rounded-0 pl-5 <?php if ($controller == 'avatar') {echo ' active';} ?>">
                    <?php _e('Change avatar'); ?> <span class='fas fa-angle-right'></span>
                </a>
                <?php foreach ($groups as $key => $group) { ?>
                    <a href="<?php echo $group['url']; ?>"
                       class="nav-link rounded-0 pl-5 <?php if (isset($group_id)) {echo $group_id == $key ? ' active' : '';} ?>">
                        <?php echo _escape($group['title']); ?> <span class='fas fa-angle-right'></span>
                    </a>
                <?php } ?>
                <?php if (!$userConfig['disable_front']) { ?>
                    <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'privacy'])); ?>"
                       class="nav-link rounded-0 pl-5 <?php if ($controller == 'privacy') {echo ' active';} ?>">
                        <?php _e('Privacy'); ?> <span class='fas fa-angle-right'></span>
                    </a>
                <?php } ?>
            </div>
        </div>
    </div>

    <!-- PRO -->
    <div id="nav-pro" class="nav flex-column nav-pills <?php if($isPerso) echo 'd-none' ?>">
        <a href="<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'dashboardPro'])); ?>"
           class="nav-link rounded-0 <?php echo $controller == 'dashboardPro' ? 'active' : '' ?>">
            <span class="fa-minimized fas fa-tachometer-alt d-none"></span>
            <span class="label"><?php _e('Pro Dashboard') ?></span>
            <span class='fas fa-angle-right'></span>
        </a>

        <?php if (Pi::service('module')->isActive('guide')) { ?>
            <a href="<?php echo Pi::url($this->url('guide', ['module' => 'guide', 'controller' => 'manage', 'action' => 'dashboard'])); ?>"
               class="nav-link nav-link-all-activities rounded-0 <?php if (($module == 'guide' && $action == 'dashboard') || (isset($item['id']) && $item['id'])) {echo ' active';} ?>">
                <span class="fa-minimized fas fa-project-diagram d-none"></span>
                <span class="label"><?php echo __('Manage my activities') ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if ($module == 'guide' && Pi::service('module')->isActive('guide')) : ?>
            <div class="item-section <?php if (($module == 'guide' && $action == 'dashboard') || isset($item['id'])) {echo ' active';} ?>">
                <?php if ($guideConfig['manage_active'] && isset($navigationItemList) && (count($navigationItemList) || isset($currentTitle))) { ?>
                    <div class="position-relative">
                        <a class="d-flex nav-link nav-link-choose rounded-0 collapsed <?php echo isset($item['id']) ? 'nav-link-choosen' : '' ?>" role="button" data-toggle="collapse"
                           href="#collapseItem">
                            <div class="align-self-center">
                                <img class="d-block" width="30" src="<?php echo $this->assetModule('front/img/concierge.svg', 'user') ?>" alt="" />
                            </div>
                            <span class="text-left d-block align-self-center ml-2 mr-2">
                                <?php echo (isset($currentTitle) && $currentTitle) ? $currentTitle : __('Choose an activity') ?>
                            </span>
                            <span class='d-block align-self-center fa fa-caret-down'></span>
                        </a>
                        <div id="collapseItem" class="panel-collapse collapse <?php if ($module == 'user' && $controller != 'dashboard') echo 'show' ?>" role="tabpanel">
                            <?php foreach ($navigationItemList as $itemId => $itemTitle) : ?>
                                <?php if ($action == 'dashboard') { ?>
                                    <a href="<?php echo $this->url(null, ['module' => 'guide', 'controller' => 'manage', 'action' => 'planning', 'item' => $itemId], null, true) ?>"
                                       class="nav-link rounded-0 pl-5">
                                        <?php echo $itemTitle ?> <span class='fas fa-angle-right'></span>
                                    </a>
                                <?php } else { ?>
                                    <a href="<?php echo $this->url(null, array('item' => $itemId), null, true) ?>"
                                       class="nav-link rounded-0 pl-5">
                                        <?php echo $itemTitle ?> <span class='fas fa-angle-right'></span>
                                    </a>
                                <?php } ?>
                            <?php endforeach; ?>
                        </div>
                    </div>
                <?php } ?>

                <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial') || (isset($item_type) && $item_type == 'commercial') && $guideConfig['manage_active']) { ?>
                    <a href="<?php echo Pi::url($this->url('guide', ['module' => 'guide', 'controller' => 'manage', 'action' => 'planning', 'item' => $item['id']])); ?>"
                       class="nav-link nav-link-summary rounded-0 <?php if ($module == "guide" && $controller == 'planning' && $action == 'index') { echo ' active'; } ?>">
                        <?php _e('Summary'); ?> <span class='fas fa-angle-right'></span>
                    </a>
                <?php } ?>

                <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial')
                    || (isset($item_type) && $item_type == 'commercial')
                    || (isset($item['item_type']) && $item['item_type'] == 'commercial')
                    || (isset($item_type) && $item_type == 'commercial')) { ?>

                    <br class="minimized-no-display" />
                    <div class="position-relative">
                        <a class="nav-link collapsed nav-link-collapse" data-toggle="collapse" href="#collapseFastAction">
                            <span class="fa-minimized fas fa-tachometer-alt d-none"></span>
                            <div></div>
                            <strong><?php _e('FAST ACTIONS') ?></strong>
                            <hr/>
                        </a>
                        <div id="collapseFastAction" class="panel-collapse collapse collapse-minimized-only" role="tabpanel">
                            <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial') || (isset($item_type) && $item_type == 'commercial')) { ?>
                                <?php if ($config['manage_service']) { ?>
                                    <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'sales', 'item' => $item['id'])); ?>"
                                       class="nav-link rounded-0 <?php echo $action == "sales" || $action == "sales-calendars" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                        <?php _e('Management Grids'); ?> <span class='fas fa-angle-right'></span>
                                    </a>
                                <?php } ?>
                                <?php if ($config['calendar_active']) { ?>
                                    <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'calendar', 'item' => $item['id'])); ?>"
                                       class="nav-link rounded-0 <?php echo $action == "calendar" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                        <?php _e('Bookings/Closings'); ?> <span class='fas fa-angle-right'></span>
                                    </a>
                                <?php } ?>
                            <?php } ?>
                            <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial') || (isset($item_type) && $item_type == 'commercial')) { ?>
                                <?php if ($config['manage_service']) { ?>
                                    <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'boost', 'item' => $item['id'])); ?>"
                                       class="nav-link rounded-0 <?php echo $action == "boost" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                        <?php _e('Boost'); ?> <span class='fas fa-angle-right'></span>
                                    </a>
                                <?php } ?>
                            <?php } ?>

                            <?php if (Pi::service('module')->isActive('guide')) { ?>
                                <a href="<?php echo $this->url('guide', array('module' => 'guide', 'controller' => 'stats', 'action' => 'index', 'item' => $item['id'])); ?>"
                                   class="nav-link rounded-0 <?php echo $controller == "stats"  ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                    <?php _e('Statistics'); ?>
                                    <span class='fas fa-angle-right'></span>
                                </a>
                            <?php } ?>
                        </div>

                    </div>
                <?php } ?>

                <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial') || (isset($item_type) && $item_type == 'commercial')) { ?>
                    <br class="minimized-no-display" />
                    <div class="position-relative">
                        <a class="nav-link collapsed nav-link-collapse" data-toggle="collapse" href="#collapseConfiguration">
                            <span class="fa-minimized fas fa-cogs d-none"></span>
                            <div></div>
                            <strong><?php _e('CONFIGURATION') ?></strong>
                            <hr/>
                        </a>

                        <div id="collapseConfiguration" class="panel-collapse collapse collapse-minimized-only" role="tabpanel">
                            <a href="<?php echo $this->url('', array('module' => 'guide', 'controller' => 'manage', 'action' => 'edit', 'item' => $item['id'])); ?>"
                               class="nav-link rounded-0 <?php echo $action == "add" || $action == "edit" || $action == "additional" || $action == "amenities" || $action == "attach" ? 'active' : '' ?>">
                                <?php _e('Description'); ?> <span class='fas fa-angle-right'></span>
                            </a>

                            <?php if ($config['manage_service']) { ?>
                                <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'service', 'item' => $item['id'])); ?>"
                                   class="nav-link rounded-0 <?php echo $action == "service"|| $action == "manage" || $action == "pricelist" || $action == 'children-policy'  ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                    <?php _e('Products/Prices'); ?> <span class='fas fa-angle-right'></span>
                                </a>
                            <?php } ?>

                            <?php if ((isset($business['enable_opening']) && $business['enable_opening']) || (isset($business['enable_opening_meal_service']) && $business['enable_opening_meal_service'])) { ?>
                                <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'openings', 'item' => $item['id'])); ?>"
                                   class="nav-link rounded-0 <?php echo $action == "openings" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                    <?php _e('Opening hours'); ?> <span class='fas fa-angle-right'></span>
                                </a>
                            <?php } ?>

                            <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'policies', 'item' => $item['id'])); ?>"
                               class="nav-link rounded-0 <?php echo $action == "policies" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                <?php _e('Policies'); ?> <span class='fas fa-angle-right'></span>
                            </a>

                            <?php if ($config['manage_service']) { ?>
                                <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'payment-history', 'item' => $item['id'])); ?>"
                                   class="nav-link rounded-0 <?php echo in_array($action, ['payment-method', 'payment-tax', 'payment-online', 'payment-history']) ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                    <?php _e('Payment'); ?> <span class='fas fa-angle-right'></span>
                                </a>
                            <?php } ?>

                            <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'promotion', 'item' => $item['id'])); ?>"
                               class="nav-link rounded-0 <?php echo $action == "promotion" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                <?php _e('Deals/Special Offers'); ?> <span class='fas fa-angle-right'></span>
                            </a>
                        </div>
                    </div>
                <?php } ?>

                <?php if ((isset($item['item_type']) && $item['item_type'] == 'commercial') || (isset($item_type) && $item_type == 'commercial')) { ?>
                    <br class="minimized-no-display" />
                    <div class="position-relative">
                        <a class="nav-link collapsed nav-link-collapse" data-toggle="collapse" href="#collapseDistribution">
                            <span class="fa-minimized fas fa-network-wired d-none"></span>
                            <div></div>
                            <strong><?php _e('DISTRIBUTION') ?></strong>
                            <hr/>
                        </a>

                        <div id="collapseDistribution" class="panel-collapse collapse collapse-minimized-only" role="tabpanel">
                            <a href="<?php echo $this->url('guide', array('module' => 'guide', 'controller' => 'manage', 'action' => 'tools', 'item' => $item['id'])); ?>"
                               class="nav-link rounded-0 <?php echo $action == "tools"  ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                <?php _e('Widget'); ?> <span class='fas fa-angle-right'></span>
                            </a>
                            <?php if ($config['manage_service']) { ?>
                                <a href="<?php echo $this->url('', array('controller' => 'manage', 'action' => 'event-list', 'item' => $item['id'])); ?>"
                                   class="nav-link rounded-0 <?php echo $action == "event-list" ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                                    <?php _e('Events'); ?> <span class='fas fa-angle-right'></span>
                                </a>
                            <?php } ?>
                            <a href="#"
                               class="nav-link rounded-0 disabled" style="color:lightgrey!important; background-color:transparent">
                                <?php _e('Sales Channels (Soon)'); ?> <span class='fas fa-angle-right'></span>
                            </a>
                        </div>
                    </div>
                <?php } ?>
            </div>
        <?php endif ?>

        <?php if (in_array('guide', $userConfig['side_menu']) && Pi::service('module')->isActive('guide') && $guideConfig['manage_active'] && $guideConfig['sponsor_active']) { ?>
            <a href="<?php echo Pi::url($this->url('guide', ['module' => 'guide', 'controller' => 'manage', 'action' => 'sponsor'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'sponsor') { echo ' active'; } ?>">
                <?php _e('Sponsorship'); ?> <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (Pi::service('module')->isActive('guide')) { ?>
            <a href="<?php echo $this->url('guide', array('module' => 'guide', 'controller' => 'stats', 'action' => 'index')); ?>"
               class="nav-link rounded-0 <?php echo ($controller == "stats" && empty($item['id']))  ? 'active' : '' ?> <?php echo $action == "add"  ? 'disabled' : '' ?>">
                <span class="fa-minimized fas fa-chart-line d-none"></span>
                <span class="label"><?php _e('My statistics'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('message', $userConfig['side_menu']) && Pi::service('module')->isActive('message')) { ?>
            <?php $message = _number(Pi::api('api', 'message')->getUnread($uid, 'message')); ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'message', 'controller' => 'index', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'message') { echo ' active'; } ?>">
                <?php _e('Messages'); ?> <span class='fas fa-angle-right'></span>
                <span class="badge badge-warning"><?php echo $message; ?></span>
            </a>

            <?php $notification = _number(Pi::api('api', 'message')->getUnread($uid, 'notification')); ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'message', 'controller' => 'notify', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'notification') { echo ' active'; } ?>">
                <?php _e('Notifications'); ?> <span class='fas fa-angle-right'></span>
                <span class="badge badge-warning"><?php echo $notification; ?></span>
            </a>
        <?php } ?>

        <?php if (in_array('support', $userConfig['side_menu']) && Pi::service('module')->isActive('support')) { ?>
            <?php $support = _number(Pi::api('ticket', 'support')->getCount($uid)); ?>
            <a href="<?php echo Pi::url($this->url('support', ['module' => 'support', 'controller' => 'index', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'support') { echo ' active'; } ?>">
                <?php _e('Support tickets'); ?> <span class='fas fa-angle-right'></span>
                <span class="badge badge-warning"><?php echo $support; ?></span>
            </a>
        <?php } ?>

        <?php if (in_array('order', $userConfig['side_menu']) && Pi::service('module')->isActive('order')) { ?>
            <a href="<?php echo Pi::url($this->url('order', ['module' => 'order', 'controller' => 'index', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'order') { echo ' active'; } ?>">
                <?php _e('Orders'); ?> <span class='fas fa-angle-right'></span>
            </a>

            <?php $orderConfig = Pi::service('registry')->config->read('order'); ?>
            <?php if ($orderConfig['credit_active']) { ?>
                <?php $credit = Pi::api('credit', 'order')->getCredit($uid); ?>
                <a href="<?php echo Pi::url($this->url('order', ['module' => 'order', 'controller' => 'credit', 'action' => 'index'])); ?>"
                   class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'credit') { echo ' active'; } ?>">
                    <?php _e('Credit'); ?> <span class='fas fa-angle-right'></span>
                    <span class="badge badge-warning"><?php echo $credit['amount_view']; ?></span>
                </a>
            <?php } ?>
        <?php } ?>

        <?php if (in_array('video', $userConfig['side_menu']) && Pi::service('module')->isActive('video')) { ?>
            <a href="<?php echo Pi::url($this->url('video', ['module' => 'video', 'controller' => 'dashboard', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'videoDashboard') { echo ' active'; } ?>">
                <?php _e('Manage Videos'); ?> <span class='fas fa-angle-right'></span>
            </a>
            <a href="<?php echo Pi::url($this->url('video', ['module' => 'video', 'controller' => 'dashboard', 'action' => 'purchased'])); ?>"
               class="nav-link rounded-0 <?php if ($module == 'videoPurchased') { echo ' active'; } ?>">
                <?php _e('Purchased Videos'); ?> <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>

        <?php if (in_array('media', $userConfig['side_menu']) && Pi::service('module')->isActive('media')) { ?>
            <a href="<?php echo Pi::url($this->url('default', ['module' => 'media', 'controller' => 'list', 'action' => 'index'])); ?>"
               class="nav-link rounded-0 <?php if (isset($sideActive) && $sideActive == 'media') { echo ' active'; } ?>">
                <span class="fa-minimized far fa-images d-none"></span>
                <span class="label"><?php _e('My Media'); ?></span>
                <span class='fas fa-angle-right'></span>
            </a>
        <?php } ?>
    </div>
</div>
<script>
    var DASHBOARD_URL = '<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'dashboard'])); ?>';
    var DASHBOARD_PRO_URL = '<?php echo Pi::url($this->url('user', ['module' => 'user', 'controller' => 'dashboardPro'])); ?>';
</script>
<script>
    // Cookies
    function createCookie(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";

        document.cookie = name + "=" + value + expires + "; path=/";
    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }

    function eraseCookie(name) {
        createCookie(name, "", -1);
    }

    $(document).ready(function(){
        $('#switch-pro').on('change', function(){
            if($(this).is(':checked')){
                // $('#nav-perso').addClass('d-none');
                // $('#nav-pro').removeClass('d-none');

                $('.custom-control-label-perso').removeClass('text-warning').addClass('text-muted');
                $('.custom-control-label-pro').addClass('text-warning').removeClass('text-muted');

                window.location = DASHBOARD_PRO_URL;

            } else {
                // $('#nav-perso').removeClass('d-none');
                // $('#nav-pro').addClass('d-none');

                $('.custom-control-label-perso').addClass('text-warning').removeClass('text-muted');
                $('.custom-control-label-pro').removeClass('text-warning').addClass('text-muted');

                window.location = DASHBOARD_URL;
            }
        });
    });

    $(document).on('click', '#minimize-btn', function(){
        $('body').toggleClass('sidebar-minimized');

        if($('body').hasClass('sidebar-minimized')) {
            createCookie('minimizedMode', 1);
        } else {
            eraseCookie('minimizedMode');
        }
    });

    if(readCookie("minimizedMode")){
        $('body').addClass('sidebar-minimized');
    } else {
        $('body').removeClass('sidebar-minimized');
    }
</script>
<style>
    .sticky-top-sidebar-usersection{
        background:#0F99E9 no-repeat center center;
        background-size:cover;
        height: 100%;
    }

    .sticky-top-sidebar-perso{
        background-image:url('<?php echo $this->assetModule('front/img/dashboard-perso.jpg', 'user') ?>');
    }

    .sticky-top-sidebar-pro{
        background-image:url('<?php echo $this->assetModule('front/img/dashboard-pro.jpg', 'user') ?>');
    }
</style>