import React, { useCallback, useEffect, useState } from 'react'
import styles from './index.module.scss'
import { Button, Modal, Input } from 'antd'
import MyPopconfirm from '@/components/MyPopconfirm'
// import ZRichTexts from '@/components/ZRichTexts'
import { C1_APIgetbk, C1_APIsavebk } from '@/store/action/C1reserveOpt'
import { MessageFu } from '@/utils/message'

type Props = {
  closeFu: () => void
}

function C1xuZhi({ closeFu }: Props) {
  const [val, setVal] = useState('')

  // 获取设置
  const getEMfu = useCallback(async () => {
    const res = await C1_APIgetbk({ type: 'notice' })
    if (res.code === 0) {
      setVal(res.data?.rtf || '')
    }
  }, [])

  useEffect(() => {
    getEMfu()
  }, [getEMfu])

  // 点击提交
  const btnOk = useCallback(async () => {
    // 富文本校验不通过
    // const rtf = ZRichTextRef.current?.fatherBtnOkFu() || { flag: true }

    // const res = await C1_APIsavebk({ type: 'notice', rtf: rtf.val.txtArr[0].txt || '' })
    const res = await C1_APIsavebk({ type: 'notice', rtf: val || '' })
    if (res.code === 0) {
      MessageFu.success(`设置预约须知成功!`)
      closeFu()
    }
  }, [closeFu, val])

  return (
    <Modal
      wrapClassName={styles.C1xuZhi}
      open={true}
      title={'预约须知'}
      footer={
        [] // 设置footer为空，去掉 取消 确定默认按钮
      }
    >
      <div className='formRow'>
        {/* <ZRichTexts
          check={false}
          dirCode={'C1xuZhiText'}
          isLook={false}
          ref={ZRichTextRef}
          myUrl='museum/upload/upload'
          isOne={true}
          upAudioBtnNone={true}
        /> */}
        <Input
          value={val}
          maxLength={3000}
          showCount
          onChange={(e: React.ChangeEvent<HTMLInputElement>) => setVal(e.target.value)}
          placeholder='请输入内容，最多3000字'
        />
      </div>

      <div className='C1Xbtn'>
        <MyPopconfirm txtK='取消' onConfirm={closeFu} />
        &emsp;
        <Button type='primary' onClick={btnOk}>
          提交
        </Button>
      </div>
    </Modal>
  )
}

const MemoC1xuZhi = React.memo(C1xuZhi)

export default MemoC1xuZhi
