import { ComponentClass } from 'react'
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Text } from '@tarojs/components'
import './index.scss'
import SdFormid from '../sdFormid';

type PageOwnProps = {
  children?: any // 替换note
  className?: string
  onClick?: any
  thumb?: any
  extThumb?: any
  extraText?: any
  note?: string
  title: any
  topLine?: boolean
  noBorder?: boolean
  disabled?: boolean
}


type IProps = PageOwnProps

interface Index {
  props: IProps;
}

class Index extends Component {

  static options = {
    addGlobalClass: true
  }

  handleClick = (...args) => {
    this.props.onClick(...args)
  }

  render() {
    const {
      thumb,
      extThumb,
      title,
      topLine,
      extraText,
      note,
      className,
      noBorder,
      disabled
    } = this.props

    return (
      <SdFormid disabled={disabled} onClick={this.handleClick}>
        <View className={
          'sd-item '
          +
          (topLine
            ?
            'sd-item-topline '
            :
            ''
          )
          +
          (noBorder
            ?
            'sd-item-noborder '
            :
            ''
          )
          +
          (disabled
            ?
            'sd-item-disabled '
            :
            ''
          )
          +
          (className || '')
        }
        >
          {
            thumb && < Image mode='aspectFill' className='sd-item-thumb' src={thumb} />
          }
          <View className='sd-item-content'>
            <View className='sd-item-title'>{title}</View>
            {
              note && <View className='sd-item-note'>{note}</View>
            }
            {this.props.children}
          </View>
          {
            extraText && <Text className='sd-item-extra-text' >{extraText}</Text>
          }

          {
            extThumb && <Image mode='aspectFill' className='sd-item-extra-thumb' src={extThumb}></Image>
          }

        </View>
      </SdFormid>
    )
  }
}

export default Index as ComponentClass<PageOwnProps>