import type { ErrorMessageMode } from '/#/axios'
import { useMessage } from '/@/hooks/app/useMessage'
import { useI18n } from '/@/hooks/app/useI18n'
import * as HTTP from '/@/api/types'

const { createMessage, createErrorModal } = useMessage()

export function checkStatus(status: number, _msg: string, errorMessageMode: ErrorMessageMode = 'message'): void {
    const { t } = useI18n()
    const errMessage = status === undefined ? t('sys.api.networkException') : HTTP.toMessage(status)

    if (errMessage) {
        if (errorMessageMode === 'modal') {
            createErrorModal({ title: t('sys.api.errorTip'), content: errMessage })
        } else if (errorMessageMode === 'message') {
            createMessage.error(errMessage)
        }
    }
}
