import { useI18n } from 'vue-i18n';
import useClipboard from 'vue-clipboard3';
import { MessagePlugin } from 'tdesign-vue-next';

export default function () {
  const { t } = useI18n();
  const doCopy = (keyword: string) => {
    if (!keyword) {
      return;
    }
    const { toClipboard } = useClipboard();
    toClipboard(keyword)
      .then(() => {
        MessagePlugin.closeAll();
        MessagePlugin.success(t('header.copySuccess'));
      })
      .catch((e) => {
        MessagePlugin.closeAll();
        MessagePlugin.error(t('header.copyerror'));
      });
  };
  return {
    doCopy,
  };
}
