<template>
  <button 
    v-bind:class="[componentClass]" 
    :title="getTitle" 
    v-on:click="refreshData">
    <slot
      name="content"
      :row="contextRow" 
      :where="where"
    >{{ getLabel }}
    </slot>
  </button>
</template>

<script>

import base from './c-base'
import { mapActions } from 'vuex'

const props = {
  dataFieldIdent: {
    type: String,
    default: null
  },
  dataFieldIdent4Label: {
    type: String,
    default: null
  },
  dataFieldIdent4Title: {
    type: String,
    default: null
  },
  label: {
    type: String,
    default: null
  }
}

export default {
  extends: base,
  data: function () {
    return {
      componentClass: 'c-btnref'
    }
  },
  props,
  computed: {
    getLabel: function () {
      return this.label || this.getDataFieldValue(this.dataFieldIdent4Label)
    },
    getTitle: function () {
      return this.getDataFieldValue(this.dataFieldIdent4Title)
    }
  },
  methods: {
    ...mapActions('csAppWindowsUtils', [
      'refreshDataSetDependence'
    ]),

    refreshData: function () {
      if ((this.sourceKind == "where")) this.refresh()
      else {
        this.refreshDataSetDependence({
          appWindowIdent: this.appWindowIdent,
          parentDataSetIdent: this.dataSetIdent,
          refreshAggregates: 1
        })
      }
    }
  }
}</script>
