<template>
  <table class="table is-fullwidth is-striped">
    <tbody>
      <leanisp-table-field-view-item v-for="(field, index) in fieldListComputed" 
                  :key="index" 
                  :label="$t('document.'+documentName+'.'+field)" 
                  :value="document[field]"/>
    </tbody>
  </table>
</template>

<script>
export default {
  name: 'LeanispTableFieldView',
  props: {
    document: Object,
    documentName: String,
    fieldList: Array,
    excludeFields: {
      type:Array, 
      default() {
        return ["__ob__","id","version","createdDate","createdUser","modifiedDate","modifiedUser","deleted","description","code","events","tags","additionalFields"]
      }
    }
  },
  computed: {
    fieldListComputed () {
      if(!this.fieldList) {
        let fields = Object.getOwnPropertyNames(this.document)
        return fields.filter(item => !this.excludeFields.includes(item))
      }
      return this.fieldList
    }
  }
}
</script>