<script setup>
import XSelect from "../../../../../components/XSelect/index.vue";
import {reactive, ref, watch} from "vue";
import Api from "../../../../../api/index.js";
import {Message} from "@arco-design/web-vue";

const emits = defineEmits(['success']);
const visible = ref(false);
const detail = reactive({});
const {id} = defineProps({
    id: {
        type: Number,
        default: null,
    }
});

watch(
    () => visible.value,
    (val) => {
        if (val) Api.admin.tgAccountDetail(id).then(({data}) => {
            data.abnormaltime = data.abnormaltime * 1000;
            Object.assign(detail, data);
        });
    }
)

const getState = async () => {
    return {
        data: [
            {
                id: -2,
                name: '禁用'
            },
            {
                id: 1,
                name: '正常'
            },
            {
                id: 2,
                name: '异常'
            },
            {
                id: -1,
                name: '未通过'
            },
        ]
    }
}

const success = async () => {
    const {msg} = await Api.admin.tgAccountEdit(detail);
    Message.success(msg);
    emits('success');
}
</script>

<template>
    <a-link :hoverable="false" @click="visible=true">编辑</a-link>

    <a-modal
        @ok="success"
        ok-text="确定修改"
        title="编辑"
        title-align="start"
        v-model:visible="visible">
        <a-form layout="vertical">
            <a-form-item label="ID">
                <a-input :model-value="detail.uid" disabled placeholder="ID"></a-input>
            </a-form-item>
            <a-form-item label="账号">
                <a-input v-model:model-value="detail.account" placeholder="昵称"></a-input>
            </a-form-item>
            <a-form-item label="昵称">
                <a-input v-model:model-value="detail.nickname" placeholder="昵称"></a-input>
            </a-form-item>
            <a-form-item label="主页截图">
                <div class="flex flex-wrap gap-[12px]">
                    <a-image
                        width="62px"
                        height="62px"
                        :src="detail.homepage">
                    </a-image>
                </div>
            </a-form-item>
            <a-form-item label="主页二维码">
                <div class="flex flex-wrap gap-[12px]">
                    <a-image
                        width="62px"
                        height="62px"
                        :src="detail.qrcode">
                    </a-image>
                </div>
            </a-form-item>
            <a-form-item label="状态">
                <x-select v-model:model-value="detail.status" :api="getState" init></x-select>
            </a-form-item>
            <a-form-item label="拒绝原因" v-if="detail.status < 0">
                <a-input v-model:model-value="detail.remark" placeholder="拒绝原因"></a-input>
            </a-form-item>
            <a-form-item label="异常截止时间" v-if="detail.status === 2">
                <a-date-picker class="w-full" v-model:model-value="detail.abnormaltime" showTime></a-date-picker>
            </a-form-item>
            <a-form-item label="添加日期">
                <a-input v-model:model-value="detail.createtime" placeholder="添加日期" disabled></a-input>
            </a-form-item>
        </a-form>
    </a-modal>
</template>

<style scoped lang="scss">

</style>
