<template>
    <el-card class="mt-account-card">
        <div class="mt-title" v-if="item.mt4_server_name" :class="{'mt-title-live':mtType=='live','mt-title-demo':mtType=='demo','mt-title-archiving':mtType=='archiving'}">{{ item.mt4_server_name }}</div>
        <div class="mt-account">
            <div class="mt-group" v-if="item.mt4_type_name" :class="{'mt-group1': isArch}" >{{ item.mt4_type_name }}</div>
            <div class="mt-login" v-if="item.mt4_type_name" :class="{'mt-login1': isArch}" >{{ item.mt4_login }}</div>
            <div class="mt-login" v-else :class="{'mt-login1': isArch}" style="border-radius: 4px;">{{ item.mt4_login }}</div>
            <el-button class="more" type="primary" text v-if="!showMenu && !isArch" @click="showMenu = true" >
                <template #icon >
                    <el-icon size="32px" ><MoreFilled /></el-icon>
                </template>
            </el-button>
            <el-button class="more" style="color: #666666" type="primary" text v-if="showMenu && !isArch" @click="showMenu = false" >
                <template #icon >
                    <el-icon size="32px" ><Close /></el-icon>
                </template>
            </el-button>
            <div v-if="isArch" class="server-type" >
                <div v-if="item.server_type != 'live'" class="mt-server-type">{{ t('home.mtDemo') }}</div>
                <div v-if="item.mt_versions == 5" class="mt-server-type">{{ t('home.mt5Live') }}</div>
                <div v-if="item.mt_versions == 4" class="mt-server-type">{{ t('home.mt4Live') }}</div>
            </div>
        </div>
        <div class="mt-body">
            <div class="mt-amount" v-if="!showMenu">
                <div style="width: 100%;display: flex;flex-wrap: wrap;justify-content: space-between;">
                    <div class="amount-item">
                        <span class="name">{{ t('home.mtBalance') }}</span>
                        <div class="value">
                            <span>{{ splitNum(item.mt4_balance)[0] }}</span>
                            <span class="float-value">.{{ splitNum(item.mt4_balance)[1] }}</span>
                            <span class="unit">{{ item.ifCent == 'NO' ? 'USD' : 'USC' }}</span>
                        </div>
                    </div>
                    <div class="amount-item">
                        <span class="name">{{ t('home.mtCredit') }}</span>
                        <div class="value">
                            <span>{{ splitNum(item.mt4_credit)[0] }}</span>
                            <span class="float-value">.{{ splitNum(item.mt4_credit)[1] }}</span>
                            <span class="unit">{{ item.ifCent == 'NO' ? 'USD' : 'USC' }}</span>
                        </div>
                    </div>
                    <div class="amount-item">
                        <span class="name">{{ t('home.mtEquity') }}</span>
                        <div class="value">
                            <span>{{ splitNum(item.margin_free)[0] }}</span>
                            <span class="float-value">.{{ splitNum(item.margin_free)[1] }}</span>
                            <span class="unit">{{ item.ifCent == 'NO' ? 'USD' : 'USC' }}</span>
                        </div>
                    </div>
                    <div class="amount-item">
                        <span class="name">{{ t('home.mtLeverage') }}</span>
                        <div class="value" style="font-weight: 400;font-size: 26px;">
                            <span>1:{{ item.mt4_leverage }}</span>
                        </div>
                    </div>
                </div>
            </div>
            <div v-else-if="!isArch" class="menu-wrap" >
                <div class="menu-btn" @click="openChangeLeverage(item)" >
                    <svg-icon icon-class="gg" class="menu-icon" />
                    <span>{{ t('home.leverageChange') }}</span>
                </div>
                <div class="menu-btn" @click="goTradeList(item)" >
                    <svg-icon icon-class="jy" class="menu-icon" />
                    <span>{{ t('home.trading') }}</span>
                </div>
                <div class="menu-btn" @click="openChangeMtPwd(item, 0)" >
                    <svg-icon icon-class="jymm" class="menu-icon" />
                    <span>{{ t('home.passwordChange') }}</span>
                </div>
                <div class="menu-btn" @click="openChangeMtPwd(item, 1)" >
                    <svg-icon icon-class="zdmm" class="menu-icon" />
                    <span>{{ t('home.investorPasswordChange') }}</span>
                </div>
                <div style="position: absolute;bottom: 0;right: 0;width: 100%;height: 64px;">
                    <el-button class="mini-btn" type="info" @click="openChangeArchiving(item)">{{ t('home.archivingChange') }}</el-button>
                </div>
            </div>
            <div class="mt-btn" v-if="!isArch" >
                <template v-if="item.server_type == 'live'">
                    <router-link :to="'/capital/goldin/' + item.mt4_server + '/' + item.mt4_login" v-slot="{ navigate }">
                        <el-button type="primary" @click="navigate">{{ t('home.goldin') }}</el-button>
                    </router-link>
                    <router-link :to="'/capital/goldout/' + item.mt4_server + '/' + item.mt4_login" v-slot="{ navigate }"
                        style="margin: 0 10px;">
                        <el-button type="primary" text @click="navigate">{{ t('home.goldout') }}</el-button>
                    </router-link>
                    <router-link :to="'/capital/transfer/' + item.mt4_server + '/' + item.mt4_login" v-slot="{ navigate }">
                        <el-button type="primary" text @click="navigate">{{ t('home.transfer') }}</el-button>
                    </router-link>
                </template>
                <template v-else >
                    <!-- <router-link to="/capital/goldin" v-slot="{ navigate }" >
                        <el-button type="primary">{{ t('home.goldin') }}</el-button>
                    </router-link>
                    <router-link to="/capital/goldout" v-slot="{ navigate }" style="margin: 0 10px;" >
                        <el-button type="primary" text>{{ t('home.goldout') }}</el-button>
                    </router-link>
                    <router-link to="/capital/transfer" v-slot="{ navigate }" >
                        <el-button type="primary" text >{{ t('home.transfer') }}</el-button>
                    </router-link> -->
                </template>
            </div>
        </div>
        <div class="mt-footer" v-if="isArch" >
            {{ t('home.filedAccountTip') }}
        </div>
    </el-card>
</template>

<script setup>
import { splitNum } from '@/utils/htfx'
import { useLocale } from 'element-plus'

const router = useRouter();
const { t } = useLocale()
const emit = defineEmits(['openChangeLeverage', 'openChangeMtPwd', 'openChangeArchiving'])

const props = defineProps({
    item: Object,
    isArch: {
        type: Boolean,
        default: false
    },
    mtType:{
        type: String,
        default: 'live'
  }
})

const showMenu = ref(false)

function goTradeList(item) {
    router.push({ name: 'TradeList', query: { mt4_login: item.mt4_login, mt4_server: item.mt4_server } });
}

function openChangeLeverage(data) {
    emit('openChangeLeverage', data)
}

function openChangeMtPwd(data, type) {
    emit('openChangeMtPwd', data, type)
}

function openChangeArchiving(data) {
    emit('openChangeArchiving', data)
}

</script>

<style lang="scss" scoped>
.mt-account-card {
    margin: 20px 0 0;
    width: 405px;
    position: relative;

    :deep(.el-card__body) {
        width: 100%;
        min-height: 430px;
        padding: 64px 27px 20px !important;
        position: relative;
    }
    .mt-title {
      position: absolute;
      top: 0px;
      left: 0px;
      border-radius: 0px 0px 20px 0px;
      padding: 0px 18px;
      font-size: 16px;
      font-weight: 400;
      letter-spacing: 0px;
      line-height: 40px;
    }
    .mt-title-live {
      color: rgba(15, 54, 117, 1);
      background: rgba(41, 187, 228, 0.11);
    }
    .mt-title-demo {
      color: rgba(15, 54, 117, 1);
      background: rgba(229, 229, 229, 1);
    }
    .mt-title-archiving {
      color: rgba(51, 51, 51, 1);
      background: rgba(229, 229, 229, 1);
    }
    .mt-account {
        width: 100%;
        height: 40px;
        font-size: 16px;
        font-weight: 700;
        display: flex;
        align-items: center;

        .mt-group {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 40px;
            min-width: 80px;
            padding: 0 16px;
            line-height: 15px;
            color: #ffffff;
            background: rgba(15, 54, 117, 1);
            border-radius: 4px 0 0 4px;
        }

        .mt-login {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 40px;
            min-width: 80px;
            padding: 0 16px;
            line-height: 15px;
            color: #000000;
            border: 2px solid rgba(15, 54, 117, 1);
            border-radius: 0 4px 4px 0;
        }

        .mt-server-type {
            margin-left: 20px;
            height: 25px;
            border-radius: 100px;
            padding: 0 10px;
            font-size: 14px;
            font-weight: 400;
            color: rgba(102, 102, 102, 1);
            min-width: 76px;
            display: flex;
            justify-content: center;
            align-items: center;
            background: rgba(246, 246, 246, 1);
        }

        .mt-group1 {
            background-color: rgba(229, 229, 229, 1) !important;
            color: #000 !important;
        }

        .mt-login1 {
            border-color: rgba(229, 229, 229, 1);
        }
    }

    .mt-body {
        padding-top: 18px;
        width: 100%;
        min-height: 94px;
        display: flex;
        flex-direction: column;

        .mt-amount {
            display: flex;
            // flex-grow: 1;
            flex-shrink: 0;
            height: 100%;
            width: 100%;
            padding-bottom: 40px;
            border-bottom: 1px solid #F6F6F6;

            .amount-item {
                width: 170px;
                height: 74px;
                position: relative;
                margin-top: 36px;

                .name {
                    position: absolute;
                    top: 0;
                    left: 0;
                    font-size: 16px;
                    font-weight: 400;
                    color: #777777;
                }

                .value {
                    position: absolute;
                    bottom: 0;
                    left: 0;
                    font-size: 28px;
                    font-weight: 700;
                    line-height: 34px;

                    .float-value {
                        font-size: 18px;
                        font-weight: 500;
                    }

                    .unit {
                        font-size: 18px;
                        font-weight: 500;
                        margin-left: 6px;
                    }
                }
            }
        }

        .mt-btn {
            margin-top: 18px;
            flex-shrink: 0;
            align-self: flex-end;
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: space-between;
            align-items: flex-end;

            .el-button {
                width: 110px;
            }
        }
    }
    .el-button {
        font-size: 18px;
        height: 40px;
        padding: 0 20px;
    }

    .more:focus,
    .more:hover {
        background-color: #fff !important;
    }

    .more {
        padding: 0 10px;
        margin-left: auto;
        color: #000;
    }

    .menu-wrap {
        width: 100%;
        height: 261px;
        padding-top: 14px;
        padding-bottom: 64px;
        border-bottom: 1px solid rgba(236, 236, 236, 1);
        position: relative;
        display: flex;
        flex-wrap: wrap;
        column-gap: 10px;

        .menu-btn {
            background-color: #ffffff;
            border: 1px solid #E5E5E5;
            width: 169px;
            height: 77px;
            padding: 0 17px;
            display: flex;
            align-items: center;
            font-size: 16px;
            font-weight: 400;
            letter-spacing: 0px;
            color: rgba(51, 51, 51, 1);
            cursor: pointer;
        }

        .menu-icon {
            width: 26px;
            height: 26px;
            margin-right: 10px;
            flex-shrink: 0;
        }

        .mini-btn {
            margin: auto 0 0 auto;
            height: 32px;
            position: absolute;
            right: 0;
            bottom: 17px;
            color: #999999;
            background: #F6F6F6;
            border: none;
        }
    }

    .server-type {
        margin-left: auto;
    }

    .mt-footer {
        position: absolute;
        left: 0;
        bottom: 0;
        background-color: #F6F6F6;
        width: 100%;
        height: 82px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 16px;
        font-weight: 400;
        letter-spacing: 0px;
        color: rgba(119, 119, 119, 1);
    }
}
</style>