<template>
  <div class="search-history-bar" v-if="historyList.length > 0">
    <span class="history-label">搜索历史</span>
    <span
      v-for="(item, index) in historyList"
      :key="index"
      class="history-item"
      @click="handleClick(item)"
    >
      {{ item }}
    </span>
    <span class="clear-btn" @click="handleClear">清除全部</span>
  </div>
</template>

<script>
export default {
  name: 'SearchHistoryBar',
  props: {
    historyList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    handleClick(keyword) {
      this.$emit('select', keyword);
    },
    handleClear() {
      this.$emit('clear');
    },
  },
};
</script>

<style scoped lang="less">
.search-history-bar {
  max-width: 1200px;
  margin: 16px auto;
  font-size: 14px;
  color: #666;

  .history-label {
    margin-right: 16px;
    color: #999;
  }

  .history-item {
    margin-right: 16px;
    cursor: pointer;
    color: #072ca6;

    &:hover {
      text-decoration: underline;
    }
  }

  .clear-btn {
    float: right;
    cursor: pointer;
    color: #999;

    &:hover {
      color: #666;
    }
  }
}
</style>
