import {Text, Textarea, View} from "@tarojs/components";
import {FC, useEffect, useState} from "react";
import './topic.scss'

interface Props {
  data: ShareSubject
  onAnswer: (isAnswer: boolean) => void
  validate: boolean
}

const ShortAnswer: FC<Props> = ({data, onAnswer, validate}) => {
  const [value, setValue] = useState<string>('')

  useEffect(() => {
    if (validate) {
      if (value.length < 1) {
        onAnswer(false)
      } else {
        onAnswer(true)
      }
    }
  }, [validate])

  return (
    <View className='topic'>
      <View className='mb-3'>
        <Text className='topicType'>简答题</Text>
        <Text>{data.question}</Text>
      </View>

      <Textarea
        placeholder='请输入答案'
        className='Textarea'
        maxlength={255}
        onInput={(e) => setValue(e.detail.value)}/>


      <View className='mt-3'>
        <View className='font-weight my-3'>题目解析</View>
        <View>{data.analysis}</View>
      </View>

    </View>
  )
}

export default ShortAnswer
