<template>
  <div class="ged-page-customs-container">
    <Banner :herited-options="heritedOptions" page="space_documents" />

    <TemplateContainer size="l">
      <AddContent
        v-if="permissionAddContent()"
        :parents="['space_folders']"
        :contents="['space_documents']"
        :multi-upload-contents="['space_documents']"
        type="admin"
      />
      <GedGlobal
        content-documents="space_documents"
        content-folders="space_folders"
      />
    </TemplateContainer>
  </div>
</template>

<script>
import { storage } from '@inside-library/helpers/Storage'

import Banner from '../components/commons/Banner'
import GedGlobal from '../components/ged/GedGlobal'
import TemplateContainer from '@inside-commons/components/lib/TemplateContainer'
import AddContent from '../components/commons/AddContent'

export default {
  name: 'ged-page-customs',
  $_i18nRootPath: 'customs.HOMEPAGE',
  components: {
    Banner,
    TemplateContainer,
    GedGlobal,
    AddContent
  },
  beforeMount() {
    const { clients, site, siteTitle } = this.$route.query

    if (clients) {
      this.$store.commit('setUserInformation', {
        key: 'client',
        value: clients
      })
    }

    if (site) {
      this.$store.commit('setUserInformation', {
        key: 'site',
        value: { uuid: site, title: siteTitle }
      })
    }
  },
  mounted() {
    if (storage.get('client')) {
      const client = storage.get('client')
      const clientTitle = typeof client === 'string' ? client : client.title

      this.$_triggerSuccessToast({
        title: this.$_tr('client', [clientTitle]),
        text: this.$_tr('site', [storage.get('site').title]),
        duration: -100
      })
    }
  },
  methods: {
    permissionAddContent() {
      return this.getUserInfos.permissions.add.includes('space_documents')
    }
  }
}
</script>
