import React, { useEffect, useState } from 'react'
import PageContainer from '@/components/BasePageContainer';
import { Card, Form, Input, Button, Switch, message } from 'antd'
import { GetAuthSet, AuthSetting } from '@/services/database/api'
import styles from './index.less'
const AuthControl = () => {

    const [flag,setFlag] = useState(0)
    const [auChecked, setAuChecked] = useState()
    const [cacheChecked, setCacheAuChecked] = useState()

    useEffect(() => {
        GetAuthSet().then(
            res => {
                if (res.code === 0) {
                    setAuChecked(res.data.IsOpenAuth)
                    setCacheAuChecked(res.data.IsUseCache)
                }
            }
        )

    }, [flag])
    const loadConfig = () => {

    }
    const operateControl = value => {
        AuthSetting({
            IsOpenAuth:value
        }).then(
            res =>{
                if(res.code === 0){
                    setFlag(flag + 1)
                    message.success("设置成功！")
                }
            }
        )

    }
    return (
        <>
            <PageContainer>
                <div style={{display:"flex",flexWrap:"wrap"}}>
                    <Card title="数据管理" style={{ width: 350, marginLeft: 15 }}>
                        <div className={styles.auth_container}>
                            <div className={styles.operate_item}>
                                <div>数据库鉴权</div>
                                <Switch checkedChildren='开启' unCheckedChildren='关闭' checked={auChecked} onChange={operateControl} />
                            </div>
                        </div>
                    </Card>
                    <Card title="缓存管理" style={{ width: 350, marginLeft: 15 }}>
                        <div className={styles.auth_container}>
                            <div className={styles.operate_item}>
                                <div>开启缓存</div>
                                <Switch checkedChildren='开启' unCheckedChildren='关闭' checked={cacheChecked} disabled={true} />
                            </div>
                        </div>
                    </Card>
                </div>
            </PageContainer>
        </>
    )
}
export default AuthControl;