import { PageContainer, ProTable } from "@ant-design/pro-components"
import { columns } from "./tableConfig"
import { useAjax } from "@/Hook/useAjax"
import { history, useModel } from "@umijs/max"
import { Button } from "antd"
import { PlusCircleOutlined } from "@ant-design/icons"
import { listOfPage } from "@/services/miniApp/extend"
import { authSuccess, getMpAccount, preAuth } from "@/services/miniApp/emsCnpl"
import { useEffect } from "react"

const Page: React.FC = () => {
    let { initialState } = useModel("@@initialState")
    let getList = useAjax((params) => getMpAccount(params), { type: 'table' })
    let PreAuth = useAjax((params) => preAuth(params)) //授权地址
    let AuthSuccess = useAjax((params) => authSuccess(params)) //授权
    useEffect(()=>{
        console.log("history.location.search", history.location.search)
    },[])
    // 授权
    const auth = () => {
        PreAuth.run({ callbackPage: "https://testdistribution.zanxiangwl.com/#/miniApp/emsCnpl/auth" }).then(res => {
            if (res.code === 200) {
                window.open(res?.data?.data)
            }
        })
    }
    return <PageContainer title={false}
    >
        <ProTable<any, any>
            scroll={{ x: true }}
            toolBarRender={() => {
                return [
                    <Button
                        type="primary"
                        onClick={auth}
                    >
                        <PlusCircleOutlined />
                        授权
                    </Button>,
                ];
            }}
            params={{
                appId: initialState?.selectApp?.id || "",
                appType: initialState?.selectApp?.appType || "",
                linkType: 1,
            }}
            headerTitle={"已授权公众号列表"}
            rowKey={(r) => r.linkId}
            search={{
                labelWidth: 90,
                span: 4
            }}
            request={async (params) => {
                return await getList.run(params)
            }}
            columns={columns(initialState?.selectApp?.appCategory || 1)}
        // bordered
        />
    </PageContainer>

}
export default Page