import React, { useEffect, useState } from 'react'
import { Modal, Form, Input, notification, message, Radio, Checkbox, Space} from 'antd';
import { AddUserAuthSetting, GetUserAuthSet, } from '@/services/database/api'
import SiteModal from '@/components/Modal/SiteModa';



const AuthModal = props => {
    const plainOptions = [
        { label: '访客', value: 0 },
        { label: '普通用户', value: 1 },
        { label: '管理员', value: 2 },
        { label: '超级管理员', value: 3 },
    ];
    const [form] = Form.useForm();
    const { Item } = Form;
    const { title, visible, onCancel, onSelect, currentUser } = props;
    const [selectValue,setSelctValue] = useState(1)


    useEffect(() => {
        currentUser.userID && visible
        GetUserAuthSet({
            UserId: currentUser.userID
        }).then(
            res => {
                if(res.code === 0){
                    setSelctValue(res.data)
                }
            }
        )
    }, [currentUser])
    const onTypeChange = (value) => {
        setSelctValue(value)
    }
    const onSubmit = () => {
        AddUserAuthSetting({userId:currentUser.userID}).then(
            res =>{
                if(res.code === 0){
                    message.info("提交成功")
                }
            }
        )
    }


    return (
        <SiteModal
            title={title}
            visible={visible}
            onCancel={onCancel}
            onOk={onSubmit}
            okText="确认"
            cancelText="取消"
            width="800px"
        >
            <div style={{ width: '800px' }}>
                <Form form={form}>
                    <Item
                        label="数据权限"
                        name="operate_type"
                    >
                        
                        <Radio.Group
                            defaultValue={selectValue}
                            options={plainOptions}
                            onChange={onTypeChange}
                        />
                        
                    </Item>
                </Form>
            </div>
        </SiteModal>

    )
}
export default AuthModal