<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>
            <template v-if="isArch">
                <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>
            </template>
        </div>
        <div class="mt-body">
            <div class="mt-amount">
                <el-space wrap style="width: 100%">
                    <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">
                            <span>1:{{ item.mt4_leverage }}</span>
                        </div>
                    </div>
                </el-space>
            </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 12px;">
                        <el-button type="primary" text @click="navigate">{{ t('home.goldout') }}</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 12px;" >
                        <el-button type="primary" text>{{ t('home.goldout') }}</el-button>
                    </router-link> -->
                </template>
                <el-button type="primary" text @click="goTradeList(item)">{{ t('home.trading') }}</el-button>
                <el-dropdown>
                    <el-button class="more" icon="MoreFilled" type="primary" text></el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <template v-if="item.server_type == 'live'">
                                <router-link :to="'/capital/transfer/' + item.mt4_server + '/' + item.mt4_login" v-slot="{ navigate }">
                                    <el-dropdown-item @click="navigate">
                                        <div style="font-size: 18px;padding: 4px;">{{ t('home.transfer') }}</div>
                                    </el-dropdown-item>
                                </router-link>
                            </template>
                            <template v-else >
                                <!-- <router-link to="/capital/transfer" v-slot="{ navigate }" >
                                    <el-dropdown-item @click="navigate" >
                                        <div style="font-size: 18px;padding: 4px;">{{ t('home.transfer') }}</div>
                                    </el-dropdown-item>
                                </router-link> -->
                            </template>
                            <el-dropdown-item @click="openChangeLeverage(item)">
                                <div style="font-size: 18px;padding: 4px;">{{ t('home.leverageChange') }}</div>
                            </el-dropdown-item>
                            <el-dropdown-item @click="openChangeMtPwd(item, 0)">
                                <div style="font-size: 18px;padding: 4px;">{{ t('home.passwordChange') }}</div>
                            </el-dropdown-item>
                            <el-dropdown-item @click="openChangeMtPwd(item, 1)">
                                <div style="font-size: 18px;padding: 4px;">{{ t('home.investorPasswordChange') }}</div>
                            </el-dropdown-item>
                            <el-dropdown-item @click="openChangeArchiving(item)">
                                <div style="font-size: 18px;padding: 4px;">{{ t('home.archivingChange') }}</div>
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
        </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'
    }
})

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-top: 20px;

    :deep(.el-card__body) {
        width: 100%;
        min-height: 190px;
        padding: 54px 44px 24px 44px !important;
        position: relative;
    }
    .mt-title {
      position: absolute;
      top: 0px;
      left: 0px;
      height: 34px;
      border-radius: 0px 0px 20px 0px;
      padding: 7px 15px;
      font-size: 14px;
      font-weight: 400;
      letter-spacing: 0px;
      line-height: 20.27px;
    }
  .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;

        .mt-amount {
            display: flex;
            flex-grow: 1;
            // flex-shrink: 0;
            height: 100%;

            .amount-item {
                width: 220px;
                // max-width: 260px;
                // min-width: max-content;
                height: 84px;
                position: relative;

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

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

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

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

        .mt-btn {
            flex-shrink: 0;
            align-self: flex-end;
            min-width: 300px;
            height: 100%;
            display: flex;
            justify-content: flex-end;
            align-items: flex-end;
            padding-right: 70px;

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

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

            .more {
                padding: 0 10px;
            }
        }
    }
}
</style>