import Clipboard from 'clipboard'

let modules;
modules = {
  name: 'propertiesDialog',
  props: {
    attachment: Object
  },
  components: {},
  created() {
    this.title = this.$t2('分享', 'components.fileLibrary.share') + '：' + this.attachment.name;
    this.url = this.attachment.domain + this.attachment.url + '?_d=true&_n=' + encodeURIComponent(this.attachment.name);
  },
  mounted() {

  },
  data() {
    return {
      showDialog: true,
      url: '',
      title: ''
    };
  },
  watch: {},
  methods: {
    dialogClose() {
      this.$emit('update:visiable', false);
    },
    copyUrl(e) {
      this.copyToClipboard(this.url, e, this.$message, this.$t2('复制成功', 'components.fileLibrary.copySuccess'), this.$t2('复制失败', 'components.fileLibrary.copyFail'));
    },
    copyToClipboard(content, clickEvent, $message, successMsg, errorMsg) {
      const clipboard = new Clipboard(clickEvent.target, {
        text: () => content
      });

      clipboard.on('success', () => {
        $message.success(successMsg);
        clipboard.destroy();
      })

      clipboard.on('error', () => {
        $message.error(errorMsg);
        clipboard.destroy();
      });

      clipboard.onClick(clickEvent);
    }
  }
};
export default modules;
