import { Button, Drawer, Space } from 'antd'
import type { ReactNode } from 'react'

interface FormDrawerProps {
  title: string
  open: boolean
  onClose: () => void
  onSubmit: () => void
  submitting?: boolean
  okText?: string
  width?: number
  children: ReactNode
}

/** 标准表单抽屉：宽 640、底部取消/主按钮、destroyOnClose。 */
export default function FormDrawer({
  title, open, onClose, onSubmit, submitting = false, okText = '确定', width = 640, children,
}: FormDrawerProps) {
  return (
    <Drawer
      title={title}
      open={open}
      onClose={onClose}
      width={width}
      destroyOnClose
      footer={
        <Space style={{ display: 'flex', justifyContent: 'flex-end' }}>
          <Button onClick={onClose}>取消</Button>
          <Button type="primary" loading={submitting} onClick={onSubmit}>{okText}</Button>
        </Space>
      }
    >
      {children}
    </Drawer>
  )
}
