import { Button, Input, ScrollView, View } from '@tarojs/components'
import Taro, { useDidShow, usePullDownRefresh, useRouter } from '@tarojs/taro'
import type { ReactNode } from 'react'
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import classnames from 'classnames'
import styles from './index.module.scss'
import { alert, goLink } from '@/common/common'
import { formatDateTime, formatPriceDiv, formatWeightDiv } from '@/common/format'
import IconFont from '@/components/iconfont/iconfont'
import Popup from '@/components/popup'

interface Props {
  title: string
  isQuire?: boolean
  placeholderFont?: string
  handBlur?: (any) => void
  inputValue?: string
  isDisabled?: boolean
  inputType?: any
  maxlength?: number
  children?: ReactNode
  showInput?: boolean
  showMore?: boolean
  showBorder?: boolean
  handNav?: () => void
}
const Form = (props: Props) => {
  const {
    title = '标题',
    isQuire = true,
    placeholderFont = '请输入',
    handBlur,
    handNav,
    inputValue,
    isDisabled,
    inputType = 'text',
    maxlength = 999,
    children,
    showInput = true,
    showMore = false,
    showBorder = true,
  } = props

  return (
    <View className={classnames(showBorder ? styles.mainItem : styles.mainItemactive)}>
      <View className={styles.leftItem}>{title}
        {
          isQuire && <View className={styles.xing}>*</View>
        }
      </View>
      {
        !children && <View className={styles.rightItem} onClick={() => handNav?.()}>
          {
            showInput && <Input
              maxlength={maxlength}
              type={inputType}
              disabled={isDisabled}
              className={styles.inputStyle}
              placeholder={placeholderFont}
              placeholderStyle={styles.placeholderStyle}
              onBlur={e => handBlur?.(e.detail.value)}
              value={inputValue}
            ></Input>
          }
          {
            showMore && <IconFont name="icon-chakanquanbukehu" size={50} color="#000000"></IconFont>
          }
        </View>
      }
      {children}
    </View>
  )
}
export default memo(Form)
