<template>
  <section class="AiSearchBar grid" :class="{bottomBorder,isSingleRow}">
    <div class="left">
      <div class="flex wrap gridZone">
        <slot name="left"/>
      </div>
    </div>
    <div class="right" v-if="$slots.right">
      <slot name="right"/>
    </div>
    <ai-pull-down class="row" v-if="!isSingleRow" v-model="expand"/>
  </section>
</template>

<script>
export default {
  name: "AiSearchBar",
  props: {
    bottomBorder: Boolean,
  },
  computed: {
    isSingleRow: v => v.height <= 45
  },
  data() {
    return {
      height: 0,
      expand: false
    }
  },
  watch: {
    expand: {
      handler(v) {
        this.$el.querySelector(".left").style.height = v ? 'auto' : '33px'
      }
    }
  },
  mounted() {
    this.height = this.$el.querySelector(".left .gridZone").getBoundingClientRect().height
    // 卡浏览器渲染帧,为了避免flex布局溢出后只显示尾部元素,先用auto 高度,再延时一帧再设置为33px
    setTimeout(() => {
      this.$el.querySelector(".left").style.height = "33px"
    },50)
  },
}
</script>

<style lang="scss" scoped>
.AiSearchBar {
  gap: 10px;
  grid-template-columns: 1fr auto;
  position: relative;

  &.isSingleRow {
    padding-bottom: 12px;
  }

  &.bottomBorder {
    border-bottom: 1px solid #eee;
  }

  .left {
    padding-top: 1px;
    height: auto;
    overflow: hidden;

    .gridZone {
      gap: 8px;
    }
  }

  :deep(.right ) {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    align-self: flex-start;
    width: 280px;

    .el-input {
      width: 280px;
    }
  }

  .el-input {
    width: auto;
  }
}
</style>
