import { mapState } from 'vuex'

export default {
  computed: {
    ...mapState({
      masterData: state => state.masterDataModule.master_data,
      masterDataEnrolment: state => state.masterDataModule.master_data_enrolement,
    }),
  },
  methods: {
    getMasterDataIdByKeyAndTitle(key, title) {
      let data = this.masterData[key]
      if (typeof data !== 'undefined' && data.length > 0) {
        let row = data.find(x => x.title === title)
        if (typeof row !== 'undefined' && Object.keys(row).length > 0) {
          return row.id
        }
      }
      return ''
    },
    getMasterDataEnrolementIdByKeyAndTitle(key, title) {
      let data = this.masterDataEnrolment[key]
      if (typeof data !== 'undefined' && data.length > 0) {
        let row = data.find(x => x.title === title)
        if (typeof row !== 'undefined' && Object.keys(row).length > 0) {
          return row.id
        }
      }
      return ''
    },
  },
}
