<template>
    <div class="connect-wallet" v-if="showConnectWalletModal" @click.self="handleClose">
        <div class="dialog" :show-close="false">
            <div class="content">
                <div class="title">{{$t('connectWallet')}}</div>
                <ul class="wallet-list">
                    <li class="wallet-item pointer" @click="connectMetaMask">
                       {{checkEnvironment() ? $t('connectMetamask') : $t('installMetamask')}}
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex';
import { connectWallet } from '@/service/loginService';
import { checkEnvironment } from '@/api/demoMETAMASK'
const { mapState, mapMutations } = createNamespacedHelpers('wallet')
export default {
    name: 'MConnectWallet',
    components: {

    },
    data() {
        return {
            checkEnvironment,
        }
    },
    computed: {
        ...mapState(['showConnectWalletModal']),
    },
    methods: {
        ...mapMutations(['CHANGE_CONNECT_WALLET_MODAL_STATUS']),
        handleClose() {
            this.CHANGE_CONNECT_WALLET_MODAL_STATUS(false)
        },
        connectMetaMask() {
            if (checkEnvironment()) {
                connectWallet();
            } else {
                window.open('https://metamask.io/')
            }
            this.CHANGE_CONNECT_WALLET_MODAL_STATUS(false)
        },
    }
}
</script>

<style scoped lang="scss">
.connect-wallet {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba($color: #000000, $alpha: 0.7);
    z-index: 100;
    color: #333;
    .content {
        position: absolute;
        left: 0;
        right: 0;
        top: 15vh;
        margin: 0 auto;
        width: 6.6rem;
        height: 6rem;
        background: #FFF;
        padding: .39rem .32rem .78rem;
        .title {
            font-size: .3rem;
            font-weight: 500;
            color: #333;
            margin-bottom: .38rem;
        }
        .wallet-list {
            padding: .2rem;
            .wallet-item {
                height: 1rem;
                border: 1px solid #eee;
                border-radius: .1rem;
                font-size: .3rem;
                display: flex;
                justify-content: center;
                align-items: center;
                &:hover {
                    border-color: $themeColor;
                }
            }
        }
    }
}
</style>
