<template>
  <b-button size="md" variant="primary" :download="download" :href="href">
    <icon-export /> {{ $t('global.action.export') }}
  </b-button>
</template>

<script>
import IconExport from '@carbon/icons-vue/es/document--export/20';
export default {
  components: {
    IconExport,
  },
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    fileName: {
      type: String,
      default: 'data',
    },
  },
  computed: {
    dataForExport() {
      return JSON.stringify(this.data);
    },
    download() {
      return `${this.fileName}.json`;
    },
    href() {
      return `data:text/json;charset=utf-8,${this.dataForExport}`;
    },
  },
};
</script>
