import { View } from "@tarojs/components";
import IconStarColor from "@/components/icon/icon-star-color";
import { textPolishing } from '@/service/agent'
import { isSuccess } from "@/utils";
import Taro from "@tarojs/taro";

interface Props {
  text: string; 
  type: "personality" | "greeting"
  onPolished: (text:string|null) => void
}
const Index = ({
  text,
  type,
  onPolished
}: Props) => {
  

  const handleClick = async () => {
    // console.log('请求服务端润色')
    
    Taro.showLoading()
    const response = await textPolishing({
      content: text,
      type: type
    })
    Taro.hideLoading()
    if(isSuccess(response.status)){
      onPolished(response.data?.content)
    }
  }

  return (
    <View className="flex items-center gap-4" onClick={handleClick}>
      <IconStarColor></IconStarColor>{" "}
      <View className="gradient-text">润色</View>
    </View>
  );
};
export default Index;
