import { mapGetters, mapActions } from 'vuex'

export const windowsMixin = {
  computed: {
    ...mapGetters('csAppWindowsUtils', [
      'getHeaderVisible',
      'getAppWindowDataSetCurrentRow',
      'getDataSet',
      'getDataSetIdentDataFieldValue',
      'getAppWindowDataSetFindRowAndFieldValue',
      'getAppWindowUniqIdentFromAppWindowIdent',
      'gAWUI',
      'gDCR',
      'gDLR',
      'gDFV',
      'gDLRFV',
      'gDIsEL',
      'getAppWindowModalWindows',
      'viewHTMLFromFile',
      'getAppWindowViewHTML',
      'getAppWindowStyleCSS',
      'getAppWindowIdent'
    ]),
  },
  methods: {
    ...mapActions('csAppWindowsUtils', [
      'setDataSetFieldValue',
      'refreshDataSet',
      'playAudio',
      'pauseAudio'
    ]),
    sDFV: function(
      appWindowIdent,
      dataSetIdent,
      sourceKind,
      dataFieldIdent,
      dataFieldValue
    ) {
      this.setDataSetIdentDataFieldValue(
        appWindowIdent,
        dataSetIdent,
        sourceKind,
        dataFieldIdent,
        dataFieldValue
      )
    },
    setDataSetIdentDataFieldValue: function(
      appWindowIdent,
      dataSetIdent,
      sourceKind,
      dataFieldIdent,
      dataFieldValue
    ) {
      this.setDataSetFieldValue({
        sourceKind: sourceKind,
        dataSet: this.getDataSet(appWindowIdent, dataSetIdent),
        dataFieldIdent: dataFieldIdent,
        dataFieldValue: dataFieldValue
      })
    },
    rfDS: function(appWindowIdent, dataSetIdent, refreshAggregates){
      this.refreshDataSet({ appWindowIdent, dataSetIdent, refreshAggregates })
    },
    scrollPageTop: function(){
      const c = document.documentElement.scrollTop || document.body.scrollTop
      if (c > 0) {
        window.requestAnimationFrame(this.scrollPageTop)
        window.scrollTo(0, c - c / 8)
      }    
    }
  }
}