<template>
  <div class="flex sift">
    <div class="sift-left">
      <div class="">筛选条件: </div>
      <div class="sift-item" v-for="item in data" :key="item.label">
        <span class="sift-item_label">{{ item.label }}: </span>
        <span class="sift-item_value">{{ item.value }} </span>
        <i class="iconfont icon-xt-close_default sift-item_icon" @click="handleClose(item)" />
      </div>
    </div>
    <div v-if="data.length" class="sift-right" @click="handleClear"> 清除 </div>
  </div>
</template>

<script setup lang="ts">
  interface Props {
    tit?: string;
    data: Array<{
      field: string;
      label: string;
      value: string;
      isDict?: boolean;
      dict?: string;
    }>;
  }

  withDefaults(defineProps<Props>(), {
    tit: '筛选条件',
    data: () => [],
  });
  const emit = defineEmits(['close']);
  function handleClose(item) {
    console.log('🚀 ~ file: Sift.vue:28 ~ handleClose ~ item:', item);
    emit('close', { type: 'close', item });
  }

  function handleClear() {
    emit('close', { type: 'clear' });
  }
</script>

<style lang="less" scoped>
  .sift {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;

    &-left {
      display: flex;
      align-items: center;
    }

    &-right {
      font-size: 14px;
      font-weight: 400;
      color: #0075ff;
      border-bottom: 1px solid #0075ff;
      cursor: pointer;
    }

    &-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-left: 8px;
      padding: 0 8px;
      min-width: 80px;
      height: 32px;
      font-size: 14px;
      font-weight: 500;
      color: #000a18;
      line-height: 32px;
      background: #e9f5ff;
      border-radius: 4px;

      &_label {
        margin-right: 4px;
      }

      &_icon {
        margin-left: 8px;
        font-size: 12px;
        color: #9198a5;
        cursor: pointer;
      }
    }
  }
</style>
