<template>
  <component :is="layout"/>
</template>

<script>
import { setGlobalInfo } from '@app/util'

export default {
  methods: {
    getLayout () {
      if (this.$page.path) {
        const layout = this.$page.frontmatter.layout
        if (layout && (this.$vuepress.getLayoutAsyncComponent(layout)
          || this.$vuepress.getVueComponent(layout))) {
          return layout
        }
        return 'Layout'
      }
      return 'NotFound'
    }
  },

  computed: {
    layout () {
      const layout = this.getLayout()
      setGlobalInfo('layout', layout)
      return layout
    }
  }
}
</script>
