import { useAjax } from "@/Hook/useAjax"
import { syncByCorpAppApi } from "@/pages/weComTask/API/weChatApiLicense"
import { App, Button } from "antd"
import React from "react"

/**
 * 应用信息同步
 * @param params 
 * @returns 
 */
const SyncApp: React.FC<{ corpId: string, onChange?: () => void }> = ({ corpId, onChange }) => {

    /*********************************/
    const { message } = App.useApp()
    const syncByCorpApp = useAjax((params) => syncByCorpAppApi(params))
    /*********************************/

    const syncHandle = () => {
        syncByCorpApp.run({ corpId }).then((res) => {
            if (res?.data) {
                message.success('同步成功')
                onChange?.()
            }
        })
    }

    return <Button type="link" style={{ margin: 0, padding: 0 }} loading={syncByCorpApp.loading} onClick={syncHandle}>应用信息同步</Button>
}

export default React.memo(SyncApp)