<template>
    <div class="bg-light-background dark:bg-dark-background md:h-screen md:overflow-hidden lg:flex">
        <!--On Top of App Components-->
        <FilePreview />
        <Spotlight />

        <!--Mobile Navigation-->
        <MobileNavigation />

        <!--ConfirmPopup Popup-->
        <ConfirmPopup />

        <!-- Create language popup -->
        <CreateLanguage />

        <!--Navigation Sidebar-->
        <SidebarNavigation />

        <MobileNavigationToolbar />

        <ContentSidebar>
            <ContentGroup
                v-for="(menu, i) in nav"
                :key="i"
                :title="menu.groupTitle"
                :slug="menu.groupTitle"
                :can-collapse="false"
            >
                <router-link
                    v-for="(item, i) in menu.groupLinks"
                    :key="i"
                    :to="{ name: item.route }"
                    class="flex items-center py-2.5"
                    :class="{
                        'router-link-active':
                            item.linkActivation &&
                            item.linkActivation.includes($router.currentRoute.fullPath.split('/')[2]),
                    }"
                >
                    <box-icon v-if="item.icon === 'box'" size="17" class="vue-feather icon-active mr-2.5" />
                    <users-icon v-if="item.icon === 'users'" size="17" class="vue-feather icon-active mr-2.5" />
                    <settings-icon v-if="item.icon === 'settings'" size="17" class="vue-feather icon-active mr-2.5" />
                    <monitor-icon v-if="item.icon === 'monitor'" size="17" class="vue-feather icon-active mr-2.5" />
                    <globe-icon v-if="item.icon === 'globe'" size="17" class="vue-feather icon-active mr-2.5" />
                    <credit-card-icon v-if="item.icon === 'card'" size="17" class="vue-feather icon-active mr-2.5" />
                    <database-icon v-if="item.icon === 'database'" size="17" class="vue-feather icon-active mr-2.5" />
                    <dollar-sign-icon v-if="item.icon === 'dollar'" size="17" class="vue-feather icon-active mr-2.5" />
                    <file-text-icon v-if="item.icon === 'file-text'" size="17" class="vue-feather icon-active mr-2.5" />

                    <b class="text-active text-xs font-bold">
                        {{ item.title }}
                    </b>
                </router-link>
            </ContentGroup>
        </ContentSidebar>

        <router-view class="relative w-full overflow-x-hidden px-2.5 pb-12 md:px-6 lg:pt-6 lg:pb-0" />
    </div>
</template>

<script>
import FilePreview from '../components/FilePreview/FilePreview'
import CreateLanguage from '../components/Others/CreateLanguage'
import MobileNavigation from '../components/Others/MobileNavigation'
import ConfirmPopup from '../components/Others/Popup/ConfirmPopup'
import ContentGroup from '../components/Sidebar/ContentGroup'
import ContentSidebar from '../components/Sidebar/ContentSidebar'
import SidebarNavigation from '../components/Sidebar/SidebarNavigation'
import Spotlight from '../components/Spotlight/Spotlight'
import MobileNavigationToolbar from '../components/Mobile/MobileNavigationToolbar'
import {
    BoxIcon,
    CreditCardIcon,
    DatabaseIcon,
    DollarSignIcon,
    FileTextIcon,
    GlobeIcon,
    HelpCircleIcon,
    MonitorIcon,
    RefreshCwIcon,
    SettingsIcon,
    UsersIcon,
} from 'vue-feather-icons'
import { mapGetters } from 'vuex'

export default {
    name: 'Admin',
    computed: {
        ...mapGetters(['isVisibleNavigationBars', 'config']),
        nav() {
            let subscriptionLinks = {
                metered: [
                    {
                        title: this.$t('Payments'),
                        route: 'PaymentSettings',
                        icon: 'card',
                    },
                    {
                        title: this.$t('admin_menu.plans'),
                        route: 'Plans',
                        icon: 'database',
                        linkActivation: ['plans', 'plan'],
                    },
                    {
                        title: this.$t('Transactions'),
                        route: 'Invoices',
                        icon: 'file-text',
                    },
                ],
                fixed: [
                    {
                        title: this.$t('Payments'),
                        route: 'PaymentSettings',
                        icon: 'card',
                    },
                    {
                        title: this.$t('Subscriptions'),
                        route: 'Subscriptions',
                        icon: 'dollar',
                    },
                    {
                        title: this.$t('admin_menu.plans'),
                        route: 'Plans',
                        icon: 'database',
                        linkActivation: ['plans', 'plan'],
                    },
                    {
                        title: this.$t('Transactions'),
                        route: 'Invoices',
                        icon: 'file-text',
                    },
                ],
            }[this.config.subscriptionType]

            let sections = [
                {
                    groupCollapsable: false,
                    groupTitle: this.$t('global.admin'),
                    groupLinks: [
                        {
                            title: this.$t('admin_menu.dashboard'),
                            route: 'Dashboard',
                            icon: 'box',
                        },
                        {
                            title: this.$t('admin_menu.users'),
                            route: 'Users',
                            icon: 'users',
                            linkActivation: ['users', 'user'],
                        },
                        {
                            title: this.$t('admin_menu.settings'),
                            route: 'AppSettings',
                            icon: 'settings',
                        },
                    ],
                },
                {
                    groupCollapsable: false,
                    groupTitle: this.$t('Content'),
                    groupLinks: [
                        {
                            title: this.$t('admin_menu.pages'),
                            route: 'Pages',
                            icon: 'monitor',
                        },
                        {
                            title: this.$t('admin_menu.languages'),
                            route: 'Language',
                            icon: 'globe',
                        },
                    ],
                },
            ]

            // Push subscription if there is metered or fixed type
            if (this.config.subscriptionType !== 'none') {
                sections.push({
                    groupCollapsable: false,
                    groupTitle: this.$t('Subscription'),
                    groupLinks: subscriptionLinks,
                })
            }

            return sections
        },
    },
    components: {
        MobileNavigationToolbar,
        FilePreview,
        Spotlight,
        SidebarNavigation,
        MobileNavigation,
        CreateLanguage,
        ContentSidebar,
        DollarSignIcon,
        HelpCircleIcon,
        RefreshCwIcon,
        CreditCardIcon,
        FileTextIcon,
        ContentGroup,
        DatabaseIcon,
        SettingsIcon,
        MonitorIcon,
        UsersIcon,
        GlobeIcon,
        ConfirmPopup,
        BoxIcon,
    },
}
</script>
