<template>
    <view>
        <view v-if="fixed && placeholder" :style="'height: ' + height + 'px;'" />

        <view :class="utils.bem('nav-bar', { fixed }) + ' custom-class ' + (border ? 'van-hairline--bottom' : '')" :style="baseStyle">
            <view class="van-nav-bar__content" :style="customStyle">
                <view class="van-nav-bar__left" @tap="onClickLeft">
                    <block v-if="leftArrow || leftText">
                        <van-icon v-if="leftArrow" size="16px" name="arrow-left" custom-class="van-nav-bar__arrow" />
                        <view v-if="leftText" class="van-nav-bar__text" hover-class="van-nav-bar__text--hover" hover-stay-time="70">{{ leftText }}</view>
                    </block>
                    <slot v-else name="left" />
                </view>
                <view class="van-nav-bar__title title-class van-ellipsis">
                    <block v-if="title">{{ title }}</block>
                    <slot v-else name="title" />
                </view>
                <view class="van-nav-bar__right" @tap="onClickRight">
                    <view v-if="rightText" class="van-nav-bar__text" hover-class="van-nav-bar__text--hover" hover-stay-time="70">{{ rightText }}</view>
                    <slot v-else name="right" />
                </view>
            </view>
        </view>
    </view>
</template>
<script module="utils" lang="wxs" src="@/miniprogram_npm/@vant/weapp/wxs/utils.wxs"></script>
<script>
'use strict';
Object.defineProperty(exports, '__esModule', {
    value: true
});
var component_1 = require('../common/component');
var utils_1 = require('../common/utils');
component_1.VantComponent({
    classes: ['title-class'],
    props: {
        title: String,
        fixed: {
            type: Boolean,
            observer: 'setHeight'
        },
        placeholder: {
            type: Boolean,
            observer: 'setHeight'
        },
        leftText: String,
        rightText: String,
        customStyle: String,
        leftArrow: Boolean,
        border: {
            type: Boolean,
            value: true
        },
        zIndex: {
            type: Number,
            value: 1
        },
        safeAreaInsetTop: {
            type: Boolean,
            value: true
        }
    },
    data: {
        statusBarHeight: 0,
        height: 44,
        baseStyle: ''
    },
    created: function () {
        var statusBarHeight = utils_1.getSystemInfoSync().statusBarHeight;
        var _a = this;
        var safeAreaInsetTop = _a.safeAreaInsetTop;
        var zIndex = _a.zIndex;
        var paddingTop = safeAreaInsetTop ? statusBarHeight : 0;
        var baseStyle = 'z-index: ' + zIndex + ';padding-top: ' + paddingTop + 'px;';
        this.setData({
            statusBarHeight: statusBarHeight,
            height: 44 + statusBarHeight,
            baseStyle: baseStyle
        });
    },
    mounted: function () {
        this.setHeight();
    },
    methods: {
        onClickLeft: function () {
            this.$emit('click-left');
        },
        onClickRight: function () {
            this.$emit('click-right');
        },
        setHeight: function () {
            var that = this;
            if (!this.fixed || !this.placeholder) {
                return;
            }
            this.$nextTick(function () {
                that.getRect('.van-nav-bar').then(function (res) {
                    that.setData({
                        height: res.height
                    });
                });
            });
        }
    }
});
</script>
<style>
@import './index.css';
</style>
