import { useCallback, useRef } from 'react'
import styles from './index.module.scss'
import { Button } from 'antd'
import ZRichTexts from '@/components/ZRichTexts'
import { forwardRef, useImperativeHandle } from 'react'

type Props = {
  auditSta: string
  auditStaFu: (val: string) => void
  ref: any
  dirCode: string
  myUrl: string
  titHide?: boolean
}

function X3auditInfo({ auditSta, auditStaFu, dirCode, myUrl, titHide }: Props, ref: any) {
  // 富文本的ref
  const TextRef = useRef<any>(null)

  const resData = useCallback(() => {
    const rtf = TextRef.current?.fatherBtnOkFu() || { flag: true }
    return JSON.stringify(rtf.val || '')
  }, [])

  useImperativeHandle(ref, () => ({
    resData
  }))

  // 设置富文本
  //  ZRichTextRef.current?.ritxtShowFu(JSON.parse(data.rtf))

  return (
    <div className={styles.X3auditInfo}>
      <div className='x3Top' hidden={titHide}>
        审批信息
        {/* <Button type='dashed'>待审批</Button> */}
      </div>

      <div className='X3Main'>
        <div className='x3Row'>
          <div className='x3Rowll'>
            <span> * </span> 审批结果：
          </div>
          <div className='x3Rowrr'>
            {['同意', '不同意'].map(v => (
              <Button
                key={v}
                type={v === auditSta ? 'primary' : 'default'}
                onClick={() => auditStaFu(v)}
              >
                {v}
              </Button>
            ))}
          </div>
        </div>
        <div className='x3Row x3RowFull'>
          <div className='x3Rowll'>审批意见：</div>
          <div className='x3Rowrr'>
            <ZRichTexts
              check={false}
              dirCode={dirCode}
              isLook={false}
              ref={TextRef}
              myUrl={myUrl}
              isOne={true}
              upAudioBtnNone={true}
            />
          </div>
        </div>
      </div>
    </div>
  )
}

export default forwardRef(X3auditInfo)
