<template>
  <view style="height: 100%">
    <view v-if="position === 'fixed'" :style="'height:220rpx;'" />

    <view
      :class="'custom-nav-bar ' + (position === 'fixed' ? 'custom-nav-bar__fixed' : '') + ' ' + (position === 'absolute' ? 'custom-nav-bar__absolute' : '')"
      :style="
                'padding-top:0px;line-height:20px;z-index: ' +
                zIndex +
                ';background-color: ' +
                (color === 'white' ? 'transparent' : '#ffffff') +
                ';height:220rpx;'
            ">
      <view :class="'custom-nav-bar-content__content ' + (border ? 'custom-nav-bar__border-bottom' : '')">
        <view class="custom-nav-bar-content__left" @click="onClickLeft">
          <block v-if="leftArrow || leftText">
            <image v-if="leftArrow" class="custom-nav-bar-content__img"
              :src="color === 'white' ? '/static/images/ic-arrow-white.png' : '/static/images/ic-arrow-black.png'">
            </image>
            <view v-if="leftText"
              :style="'color: ' + (color === 'white' ? '#FFFFFF' : color === 'black' ? '#333333' : color) + ';'"
              class="custom-nav-bar-content__text">
              {{ leftText }}
            </view>
          </block>
          <slot v-else name="left" />
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  // import vanIcon from '@vant/weapp/icon/index';
  // const app = getApp();
  export default {
    components: {
      // vanIcon
    },
    data() {
      return {
        // sysConfig: app.globalData.config,
        height: 46,
        top: 0
      };
    },
    props: {
      leftText: {
        type: String,
        default: ''
      },
      position: {
        type: String,
        default: 'absolute'
      },
      leftArrow: {
        type: Boolean,
        default: false
      },
      zIndex: {
        type: Number,
        default: 99
      },
      color: {
        type: String,
        default: 'white'
      },
      border: {
        type: Boolean,
        default: false
      },
      back: {
        type: Boolean,
        default: false
      }
    },
    options: {
      virtualHost: true
    },
    methods: {
      onClickLeft: function() {
        if (this.leftArrow && !this.back) {
          uni.navigateBack({
            delta: 1
          });
          return;
        }
        this.$emit('customClickLeft');
      }
    },
    created: function() {}
  };
</script>
<style lang="less">
  .custom-nav-bar {
    width: 100%;
    height: var(--custom-nav-bar-height, 68rpx);
    height: 46px;
    background-color: var(--custom-nav-bar-background-color, #fff);
    box-sizing: initial;
    position: relative;
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
  }

  .custom-nav-bar__fixed {
    position: fixed;
    top: 0;
    left: 0;
  }

  .custom-nav-bar__absolute {
    position: absolute;
    left: 0;
    top: 0;
  }

  .custom-nav-bar-content__content {
    position: relative;
    height: 100%;
    padding: 0 40rpx;
    display: flex;
    align-items: center;
  }

  .custom-nav-bar__border-bottom::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: var(--custom-nav-bar-bor-bottom-w, 670rpx);
    height: 1px;
    transform: translateX(-50%);
    background-color: #efefef;
  }

  .custom-nav-bar-content__left {
    height: 100%;
    display: flex;
    align-items: center;
    // position: absolute;
    // top: 0;
    // left: 44rpx;
  }

  .custom-nav-bar-content__img {
    width: 32rpx;
    height: 32rpx;
    margin-bottom: 1px;
    margin-right: 18rpx;
  }

  .custom-nav-bar-content__text {
    font-size: 34rpx;
    font-weight: 500;
    color: #333333;
    line-height: 34rpx;
  }
</style>