export default {
  methods: {
    setSlotProp: function(name, dataAttribute) {
      if (this[dataAttribute] !== undefined) {
        // currentHeader will re-render if slot is not defined
        if (
          this.$route &&
          this.$route.meta !== undefined &&
          this.$route.meta.template !== undefined &&
          this.$route.meta.template[name] !== undefined
        ) {
          // try loading currentHeader from current route
          this[dataAttribute] = this.$route.meta.template[name]
        } else if (
          this.$route &&
          this.$route.matched.some(
            record => record.meta.template !== undefined && record.meta.template[name] !== undefined
          )
        ) {
          let component = this.$route.matched.filter(item => {
            return item.meta !== undefined && item.meta.template !== undefined && item.meta.template[name] !== undefined
              ? item
              : false
          })[0]

          if (component !== false) {
            this[dataAttribute] = component.meta.template[name]
          }
        } else if (typeof this.$props !== 'undefined' && typeof this.$props[name] !== 'undefined') {
          // try loading from props
          this[dataAttribute] = this.$props[name]
        } else if (this.$ibsTemplate !== undefined && typeof this.$ibsTemplate.options[name] !== 'undefined') {
          // Load header from template options
          this[dataAttribute] = this.$ibsTemplate.options[name]
        } else {
          this[dataAttribute] = null
        }
      }
    },
  },
}
