import { View } from "@tarojs/components"
import IconMic from "@/components/icon/icon-mic"
import { useState } from "react";
import WemetaInput from '@/components/wemeta-input'
interface Props {
  disabled: boolean,
  onIconClick: () => void
  onSend: (msg: string)=> void
}
export default ({disabled, onIconClick, onSend}:Props) => {
  const [value, setValue] = useState('')
  
  const handleInput = (value: string)=> {
    setValue(value)
  }
  const handleConfirm = (value: string)=> {
    console.log(value)
    if(!value.length){
      return;
    }
    onSend(value)
    setValue('')
  }
  const iconMic = ()=> {
    return <View className="flex-center" onClick={onIconClick}><IconMic /></View>
  }
  return <>
    
      <WemetaInput 
      	adjustPosition={false}
        disabled={disabled}
        extraStyle={{'borderRadius': '10px'}}
        confirmType="send"
        prefix={iconMic} 
        placeholder="有问题尽管问我..." 
        value={value} 
        cursorSpacing={400}
        onConfirm={handleConfirm}
        onInput={(value: any) => handleInput(value)}
        >
      </WemetaInput>
  </>
}