import { useReducer } from 'react'
import { useAjax } from '@/Hook/useAjax'
import { AddGroup, addGroup, configGroup, delGroup, editApproveStatus, EditGroup, editGroup, listGroup, perfect } from '@/services/operating/account'
type State = {
    visible: boolean,//弹窗开启与否
}
export type Action = {
    type: 'show' | 'code',
    params?: any
}
export function reducer(state: State, action: Action) {
    let { type, params } = action
    switch (type) {
        case 'show':
            return { ...state, visible: !state.visible }
        default:
            return state;
    }
}

export default function useWxGroupList() {
    const [state, dispatch] = useReducer(reducer, { visible: false })
    /*
       * 分组操作
       */
    const groupAdd = useAjax((params: AddGroup) => addGroup(params), {
        msgNmae: '添加',
    })
    const groupEdit = useAjax((params: EditGroup) => editGroup(params), {
        msgNmae: '编辑',
    })
    const groupDel = useAjax((params: { groupId: string }) => delGroup(params), {
        msgNmae: '删除',
    })
    const groupList = useAjax(() => listGroup(), {})
    const groupConfig = useAjax((params: { groupId: string, mpAccountId: string }) => configGroup(params), {
        msgNmae: '修改'
    })
    const editStatus = useAjax((params: { mpId: string, status: string }) => editApproveStatus(params), { msgNmae: '修改' })
    const perfectInformation = useAjax((params: {
        mpId: string,
        administratorCard?: string,//管理员身份证号码
        administratorName?: string,//管理员名称
        administratorWechat?: string,//管理员微信号
        legalCard?: string,//法人身份证
        legalName?: string,//法人姓名
        legalWechat?: string,//法人手机号
      }) => perfect(params), { msgNmae: '操作' })
    return {
        state,
        dispatch,
        groupAdd,
        groupEdit,
        groupDel,
        groupList,
        groupConfig,
        editStatus,
        perfectInformation
    }
}
