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

export default function () {
  const doCopy = (keyword: string, toast: boolean = true) => {
    if (!keyword) {
      return;
    }
    const { toClipboard } = useClipboard();
    toClipboard(keyword)
      .then(() => {
        if (toast) {
          MessagePlugin.success('复制成功');
        }
      })
      .catch((e: any) => {
        if (toast) {
          MessagePlugin.error('复制失败');
        }
      });
  };
  return {
    doCopy,
  };
}
