<template>
  <CSidebar
      fixed
      :minimize="minimize"
      :show="show"
      @update:show="(value) => $store.commit('admin/set', ['sidebarShow', value])"
  >
    <CSidebarBrand class="d-md-down-none">
      <a href="/" target="_blank">
        <IconsLogo class="c-sidebar-brand-full" name="logo" style="width: 100%"/>
        <img src="/favicon.png" alt="logo" class="c-sidebar-brand-minimized" size="custom-size" :height="35" name="logo">
      </a>
    </CSidebarBrand>

    <!--    <CRenderFunction flat :content-to-render="$options.nav"/>-->

    <!-- sidebar content -->
    <CSidebarNav  v-if="!$route.name.includes('admin-branches') && $route.name.includes('admin-branch')">
      <CSidebarNavItem name="شعب" :to="{name: 'admin'}" font-icon="fal fa-code-branch"/>

      <CSidebarNavItem name="صفحه اصلی" :to="{name: 'admin-branch'}" font-icon="fal fa-home"/>

      <CSidebarNavItem v-if="hasPermission('users') || hasPermission('super-admin')" name="مدیریت کاربران"
                       :to="{name: 'admin-branch-users'}" font-icon="fal fa-user-crown"/>

      <CSidebarNavItem v-if="hasPermission('reports') || hasPermission('super-admin')" name="گزارشات" :to="{name:
      'admin-branch-reports'}" font-icon="fal fa-analytics"/>

      <CSidebarNavItem v-if="hasPermission('orders') || hasPermission('super-admin')" name="مدیریت سفارشات"
                       :to="{name: 'admin-branch-orders'}" font-icon="fal fa-cash-register"/>


      <CSidebarNavDropdown v-if="hasPermission('foods') || hasPermission('super-admin')" name="مدیریت محصولات" fontIcon="fal fa-utensils">
        <CSidebarNavItem name="انواع منوها" :to="{name: 'admin-branch-menu-types'}" :exact="false"/>
        <CSidebarNavItem name="دسته بندی محصولات" :to="{name: 'admin-branch-food-categories'}" :exact="false"/>
        <CSidebarNavItem name="لیست محصولات" :to="{name: 'admin-branch-foods'}" :exact="false"/>
        <CSidebarNavItem name="منوهای ویژه مهمانی" :to="{name: 'admin-branch-party-sets'}" :exact="false"/>
      </CSidebarNavDropdown>

      <CSidebarNavDropdown v-if="hasPermission('super-admin')" name="مدیریت اپلیکیشن" fontIcon="fal fa-mobile-android">
        <CSidebarNavItem v-if="hasPermission('settings') || hasPermission('super-admin')" name="تنظیمات فروشگاه"
                         :to="{name: 'admin-branch-storeInfo'}" :exact="false"/>
        <CSidebarNavItem v-if="hasPermission('notification') || hasPermission('super-admin')" name="نوتیفیکیشن"
                         :to="{name: 'admin-branch-notification'}" :exact="false"/>
        <CSidebarNavItem v-if="hasPermission('settings') || hasPermission('super-admin')" name="مدیریت شغل ها"
                         :to="{name: 'admin-branch-jobs'}" :exact="false"/>
        <CSidebarNavItem v-if="hasPermission('discounts') || hasPermission('super-admin')" name="کد های تخفیف"
                         :to="{name: 'admin-branch-discounts'}" /><!--font-icon="fal fa-badge-percent"-->
        <CSidebarNavItem v-if="hasPermission('customers') || hasPermission('super-admin')" name="لیست مشتریان"
                         :to="{name: 'admin-branch-customers'}"/><!--font-icon="fal fa-users"-->
      </CSidebarNavDropdown>

<!--      <CSidebarNavDropdown v-if="hasPermission('settings') || hasPermission('super-admin')" name="مدیریت وبسایت" fontIcon="fal fa-cog">-->
<!--        <CSidebarNavItem name="اسلایدر" :to="{name: 'admin-slider'}" :exact="false"/>-->
<!--        <CSidebarNavItem name="گالری تصاویر" :to="{name: 'admin-gallery'}" :exact="false"/>-->
<!--        <CSidebarNavItem name="پیام های صفحه تماس با ما" :to="{name: 'admin-contact-us-messages'}" :badge="unreadMessages ? {text: unreadMessages,color:'danger'} : null" :exact="false"/>-->
<!--        <CSidebarNavItem name="امور مشترکین" :to="{name: 'admin-subscribers'}" :exact="false"/>-->
<!--      </CSidebarNavDropdown>-->

    </CSidebarNav>

    <CSidebarNav v-else>
<!--      <CSidebarNavItem name="صفحه اصلی" :to="{name: 'admin'}" font-icon="fal fa-home"/>-->

      <CSidebarNavItem name="شعب" :to="{name: 'admin'}" font-icon="fal fa-code-branch"/>

      <CSidebarNavDropdown v-if="hasPermission('settings') || hasPermission('super-admin')" name="مدیریت وبسایت" fontIcon="fal fa-cog">
        <CSidebarNavItem name="اسلایدر" :to="{name: 'admin-slider'}" :exact="false"/>
        <CSidebarNavItem name="گالری تصاویر" :to="{name: 'admin-gallery'}" :exact="false"/>
        <CSidebarNavItem name="پیام های صفحه تماس با ما" :to="{name: 'admin-contact-us-messages'}" :badge="unreadMessages ? {text: unreadMessages,color:'danger'} : null" :exact="false"/>
        <CSidebarNavItem name="امور مشترکین" :to="{name: 'admin-subscribers'}" :exact="false"/>
      </CSidebarNavDropdown>
    </CSidebarNav>

    <!-- sidebar content -->

    <CSidebarMinimizer
        class="d-md-down-none"
        @click.native="$store.commit('admin/set', ['sidebarMinimize', !minimize])"
    />
  </CSidebar>
</template>

<script>
// import nav from './_nav'

export default {
  name: 'TheSidebar',
  // nav,
  computed: {
    show() {
      return this.$store.state.admin.sidebarShow
    },
    minimize() {
      return this.$store.state.admin.sidebarMinimize
    },
    unreadMessages() {
      return this.$store.state.admin.unreadMessagesCount
    },
    unreadTickets() {
      return this.$store.state.admin.unreadTicketsCount
    }
  },
  methods: {
    hasPermission(permission) {
      if (this.$auth.loggedIn) return this.$auth.user.permissions.includes(permission)
      else return false
    }
  }
}
</script>
