<template>
    <div :class="{ 'area-btn': disabled }">
        <div class="btn-submit" @click="clickBtn" :class="{ 'no': loading, 'disabled': disabled }"
            @mouseenter="mouseItem" @mouseleave="mouseLeaveItem">
            <img :src="require('@/assets/svg/icon-iframe-loading.svg')" alt="" class="loading" v-if="loading && icon" />
            <img :src="require('@/assets/svg/icon-btn-box.svg')" alt="" v-if="!loading && icon" />
            <span :style="{ 'font-size': fontSize, 'color': txtCorlor, 'font-weight': fontWeight }">{{ txt }}</span>
        </div>
        <div class="refresh" v-if="disabled">
            <img :src="require('@/assets/svg/icon-refresh-treasure.svg')"
                :class="{ 'icon-refresh-rotate': refreshRotate }" alt="" @click="refresh" />
        </div>
    </div>
</template>
<script setup>
import { inject, defineProps, defineEmits, ref } from 'vue'
let refreshRotate = ref(false);
let state = inject('state')
let props = defineProps({
    txt: {
        type: String,
        default: ''
    },
    loading: {
        type: Boolean,
        default: false
    },
    fontSize: {
        type: String,
        default: '20px'
    },
    fontWeight: {
        type: String,
        default: '800'
    },
    icon: {
        type: Boolean,
        default: true
    },
    disabled: {
        type: Boolean,
        default: false
    },
    txtCorlor: {
        type: String
    }
})
const emit = defineEmits(['on-click', 'on-mouseEnter', 'on-mouseLeave'])

const mouseItem = () => {
    if (props.disabled) {
        emit('on-mouseEnter')
    }
}

const mouseLeaveItem = () => {
    if (props.disabled) {
        emit('on-mouseLeave')
    }
}

const clickBtn = () => {
    if (props.disabled == false && props.loading == false) {
        emit('on-click')
    }
}


const refresh = () => {
    if (!refreshRotate.value) {
        refreshRotate.value = true;
        setTimeout(() => {
            refreshRotate.value = false;
        }, 1000)
        state.refreshInit()
    }
}
</script>
<style scoped lang="scss">
.btn-submit {
    background: #1D9BF0;
    border-radius: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 53px;
    width: 343px;
    margin: 0 auto;
    cursor: pointer;
    user-select: none;

    span {
        font-weight: 800;
        color: #FFFFFF;
        font-size: 20px;
        line-height: 24px;
        margin-left: 6px;

    }

    img {
        width: 20px;
        height: 20px;
    }



    .loading {
        animation: loading 1s infinite linear;
    }
}

.area-btn {
    display: flex;

    .refresh {
        display: flex;
        justify-content: center;
        align-items: center;

        img {
            cursor: pointer;
            margin-left: 12px;
        }

        .icon-refresh-rotate {
            transform: rotate(360deg);
            transition-duration: 1s;
        }
    }

    .no {
        cursor: no-drop;
    }

    .disabled {
        cursor: default;
        background: rgba(56, 154, 255, 0.4);
        color: #FFFFFF;
        width: 305px;
        font-weight: 600;
        margin: 0;


        span {
            font-weight: 600;
            color: #FFFFFF;
        }
    }

    @keyframes loading {
        from {
            transform: rotate(0deg);
        }

        to {
            transform: rotate(360deg);
        }
    }
}
</style>