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 onClick={onIconClick}><IconMic /></View>
  }
  return <>
    <View className="px-16 py-12">
      <WemetaInput 
      	adjustPosition={false}
        disabled={disabled}
        extraStyle={{'borderRadius': '10px'}}
        confirmType="send"
        prefix={iconMic} 
        placeholder="有问题尽管问我..." 
        value={value} 
        cursorSpacing={400}
        onConfirm={handleConfirm}
        onInput={handleInput}>
      </WemetaInput>
    </View>  
  </>
}