<script lang="ts" setup>
import { useClipboard } from '@vueuse/core'
import { showToast } from 'vant'

interface Props {
  streamAnswer: string
}

const props = defineProps<Props>()

function removeImgTags(input: string): string {
  return input.replace(/<img[^>]*\/>/g, '')
}

const { copy, isSupported } = useClipboard()

function onCopy() {
  const copyText = `${removeImgTags(props.streamAnswer.split('♪')[0])}`
  if (!isSupported) {
    showToast('当前浏览器不支持复制')
    return
  }
  copy(copyText)
  showToast('复制成功')
}
</script>

<template>
  <div class="copy-btn">
    <SvgIcon size="22px" name="copyIcon" @click="onCopy" />
  </div>
</template>
