<template>
    <div class="px-3 py-3 flex items-center doc-nav-bar">
        <div class="shrink-0 left">
            <slot name="left">
                <span class="back-btn" @click="goBack" v-if="!hideBack">
                    <doc-icon type="doc-left-1" style="color: #262626"/>
                </span>
            </slot>
        </div>
        <div class="grow text-center font-semibold title">
            <slot>
                {{title}}
            </slot>
        </div>
        <div class="shrink-0 right">
            <slot name="right"></slot>
        </div>
    </div>
</template>

<script>
import { backHome } from '@/utils/common.js'

export default {
    name: 'DocNavBar',
    props: {
        title: String,
        // 是否首页
        home: Boolean,
        // 替换返回函数
        backFunc: Function,
        // 隐藏返回按键
        hideBack: Boolean
    },
    methods: {
        goBack() {
            if (this.backFunc) {
                this.backFunc()
                return
            }
            if (this.home) {
                backHome()
                return
            }
            this.$router.back()
        }
    }
}
</script>

<style lang="less" scoped>
.doc-nav-bar {
    background: transparent;
    border-bottom: 1px solid #00000019;
    .left {
        min-width: 24px;
    }
    .title {
        font-size: 16px;
    }
}
</style>
