import Taro, { Component } from '@tarojs/taro'
import { Button, Form } from '@tarojs/components'
import './index.scss'
import { ComponentClass } from 'react'

type PageOwnProps = {
  disabled?: any,
  onClick?: any,
  children: any
}

type IProps = PageOwnProps

interface Index {
  props: IProps;
}

class Index extends Component {
  static options = {
    addGlobalClass: true
  }

  formSubmit = e => {
    const formid = e.detail.formId
    Taro.eventCenter.trigger('sd-formid', formid)
  }

  handleClick = e => {
    e.stopPropagation()
    this.props.onClick()
  }

  render() {
    return (
      <Form onSubmit={this.formSubmit} reportSubmit={true}>
        <Button
          formType='submit'
          onClick={this.handleClick.bind(this)}
          className={'sd-shadow-button ' + (this.props.disabled ? 'sd-shadow-button-disabled' : '')} >
          {this.props.children}
        </Button>
      </Form>
    )
  }
}

export default Index as ComponentClass<PageOwnProps>
