
import { View } from "@tarojs/components";
import PageCustom from "@/components/page-custom/index";
import NavBarNormal from "@/components/NavBarNormal/index";
import WemetaTextarea from "@/components/wemeta-textarea/index";
import TextPolish from '@/components/TextPolish'
import { useAgentStore } from "@/store/agentStore";
import useEditAgent from "@/hooks/useEditAgent";
import BottomBar from "@/components/BottomBar";
import ButtonMain from "@/components/buttons/ButtonMain";
export default function Index() {

const agent = useAgentStore((state)=> state.agent)  
const {handleSubmit, onChange, value, setValue} = useEditAgent('greeting', agent?.greeting ?? '')
const onPolished = (text:string|null)=> {
  if(text){
    setValue(text)
  }
  
}
  return (
    <PageCustom>
      <NavBarNormal backText="开场白"></NavBarNormal>
      <View className="flex flex-col items-center w-full">
        <View className="w-full p-16">
          <WemetaTextarea
              value={value}
              autoHeight
              extraClass="min-h-[380px] max-h-[500]"
              onBlur={(value: string) => onChange(value)}
              onInput={(value: string) => onChange(value)}
              placeholder="碰到TA之后，第一句话想说什么？"
              maxlength={200}
              autoFocus
              extra={()=> <TextPolish text={value} type="greeting" onPolished={onPolished}/>}
            />
        </View>

        <BottomBar>
          <ButtonMain className="flex-1" disabled={!value.length} onClick={handleSubmit}>保存</ButtonMain>
        </BottomBar>  
      </View>
    </PageCustom>
  );
}
