import React from "react";
import { View } from "@tarojs/components";
import { Icon } from "@/components";
import Taro from "@tarojs/taro";

interface ICopyTextProps {
  icon?: React.ReactNode;
  children: React.ReactNode;
  copyData: string;
}

export default function CopyText(props: ICopyTextProps) {
  const { icon, children, copyData } = props;
  return (
    <View
      className={"flex flex-row items-center gap-1"}
      onClick={(e) => {
        Taro.setClipboardData({
          data: copyData,
        });
        e.stopPropagation();
      }}
    >
      {children}
      {icon ? icon : <Icon name={"copy"} size={14} />}
    </View>
  );
}
