<template>
  <div class="search-option" :class="{ active: isActive }" @click="handleClick">
    <template v-if="item.type === 'command'">
      <div class="command">
        <div class="name">{{ item.name }}</div>
        <div class="desc">{{ item.desc }}</div>
        <Icon v-if="item.icon" :name="item.icon"></Icon>
      </div>
    </template>
    <template v-else>
      <h3 class="option">
        <div class="name">{{ item.name }}</div>
        <div class="count" v-show="item.count">{{ item.count }}</div>
      </h3>
    </template>
  </div>
</template>

<script>
export default {
  name: 'SearchOption',
  props: {
    isActive: {
      type: Boolean,
    },
    item: {
      type: Object,
      required: true,
    },
  },
  setup(props, { emit }) {
    const handleClick = () => {
      emit('click', props.item);
    };

    return {
      handleClick,
    };
  },
};
</script>

<style lang="stylus" scoped>
@import '~@theme/styles/_mixins.styl';

.search-option {
  margin-top: space();
  padding: space() space(2);
  border-radius: 8px;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;

  &:hover,&.active {
    background: var(--bg-color-2);
  }

  .icon {
    font('lg');
    margin-left: auto;
  }

  .command {
    display: flex;
    align-items: center;
    font('sm');

    .name {
      flex: 0 0 auto;
      display: inline-block;
      padding: 0 space();
      border: 1px solid var(--separator-color);
      margin-right: space();
      border-radius 4px;
    }
  }


  .option {
    display: flex;
    align-items: center;
    font('base');

    .count {
      margin-left: auto;
    }
  }
}
</style>
