<template>
    <div class="infoCard"
         :class="{ border: border }">
        <template v-if="!config.customHeader">
            <h4 :class="titleClass">
                <span>{{ $t(title) }}</span>
                <i v-if="showClose"
                   class="el-icon-arrow-right close"
                   @click="close" />
            </h4>
        </template>
        <template v-else>
            <div class="custom">
                <slot name="header" />
            </div>
        </template>
        <div class="block"
             :style="customStyle">
            <slot />
        </div>
    </div>
</template>
<script lang="ts">
import { ref, defineComponent } from 'vue'

export default defineComponent({
    name: 'InfoCard',
    props: {
        config: {
            type: Object,
            default: () => {
                return {
                    customHeader: false // 自定义头部
                }
            }
        },
        title: {
            type: String,
            default: 'view'
        },
        titleStyle: {
            type: String,
            default: ''
        },
        customStyle: {
            type: Object,
            default: () => {
                return {}
            }
        },
        border: {
            type: Boolean,
            default: false
        },
        showClose: {
            type: Boolean,
            default: false
        }
    },
    setup (props, { emit }) {
        let titleClass = ref<string>('')
        const initTitleClass = (): void => {
            titleClass.value = props.titleStyle ? props.titleStyle : ''
        }
        const close = (): void => {
            emit('globalCloseInfoCard')
        }
        initTitleClass()
        return {
            titleClass,
            close
        }
    }
})
</script>
<style lang="scss" scoped>
.border {
    border: 1px solid var(--border-color);
}

.infoCard {
    height: 100%;
    background: var(--bg-color);
    overflow: hidden;

    > h4 {
        line-height: 50px;
        height: 50px;
        padding-left: 10px;
        z-index: 11;
        position: relative;

        .close {
            position: absolute;
            right: 20px;
            top: 18px;
        }
    }

    .normal16 {
        font-size: 16px;
    }

    > .block {
        height: calc(100% - 60px);
        padding: 10px;
        border-top: 1px solid var(--border-color);
    }
    .custom {
        line-height: 50px;
        height: 50px;
        padding: 0 15px;
        z-index: 11;
        position: relative;
    }
}
.transfer-table>.block {
    padding: 0;
}
</style>
