import React, { Component, ReactChildren } from 'react'
import context from './context'

export interface ConfirmProps {
  confirmText: string
  cancelText: string
  onConfirmClick: () => void
  onCancelClick: () => void
  content: string
  isPad: boolean
  children: ReactChildren
}

class Confirm extends Component<ConfirmProps> {
  public static defaultProps = {
    onConfirmClick: () => {},
    onCancelClick: () => {},
    cancelText: '取消',
    confirmText: '确定',
    content: ''
  }
  public render() {
    return (
      <context.Consumer>
        {({
          cancelText,
          confirmText,
          onConfirmClick,
          onCancelClick,
          content,
          children
        }: any) => (
          <div className="ph-dialog-confirm">
            <div className="ph-dialog-content">
              {children ? children : content}
            </div>
            <div className="ph-dialog-btn-area">
              <div
                className="ph-dialog-btn ph-dialog-cancelbtn"
                onClick={onCancelClick}
              >
                {cancelText}
              </div>
              <div
                className="ph-dialog-btn ph-dialog-confirmbtn"
                onClick={onConfirmClick}
              >
                {confirmText}
              </div>
            </div>
          </div>
        )}
      </context.Consumer>
    )
  }
}

export default Confirm
