<!-- 市场运行管理-监控管理-在线用户查询-强制所有用户下线 -->
<template>
    <app-drawer :title="t('common.alert')" v-model:show="show" :loading="loading" :refresh="refresh">
        <div class="g-text-message">{{ t('marketrun.monitor.user.alloffline.tips') }}</div>
        <template #footer>
            <el-button @click="onCancel(false)">{{ t('operation.cancel') }}</el-button>
            <el-button type="primary" @click="onSubmit">{{ t('operation.confirm') }}</el-button>
        </template>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { marketRunDownonline } from '@/services/api/market'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import { i18n } from '@/stores'

const { global: { t } } = i18n
const show = shallowRef(true)
const refresh = shallowRef(false)
const loading = shallowRef(false)

const onCancel = (isRefresh = false) => {
    show.value = false
    refresh.value = isRefresh
}

const onSubmit = () => {
    loading.value = true
    marketRunDownonline().then(() => {
        ElMessage.success(t('common.tips17'))
        onCancel(true)
    }).catch((err) => {
        ElMessage.error(t('common.tips18') + err)
        onCancel()
    }).finally(() => {
        loading.value = false
    })
}
</script>