<template>
  <div class="search-div">
    <a-input class="search-input" v-model:value="searchInput" placeholder="搜索">
      <template #suffix>
          <div class="search-icon" @click="search"></div>
      </template>
    </a-input>
  </div>
  <div class="setting-table-title-div">
    <div class="table-title-item" style="width: 29px;">
    </div>
    <div class="table-title-item" style="width: 121px;">
      设备名称
    </div>
    <div class="table-title-item" style="width: 121px;border-right: 0px;">设备型号</div>
  </div>
  <div class="setting-table-item" v-for="item in props.deviceList">
    <div class="table-item-col" style="width: 29px;">
      <a-checkbox class="item-check" :checked="getCheck(item.id)" @change="changeCheck(item)"></a-checkbox>
    </div>
    <div class="table-item-col" style="width: 121px;">
      {{ item.name }}
      <div class="user-icon" v-if="props.userId == item.id"></div>
    </div>
    <div class="table-item-col" style="width: 121px;">
      {{ item.typeId }}
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, defineProps, defineEmits } from "vue"
const props = defineProps(['project','deviceList','userId'])
const emits = defineEmits(['searchDevice'])
const searchInput = ref("")
const search = () => {
  emits('searchDevice',searchInput.value)
}
const changeCheck = (item) => {
  console.log(item)
  if(props.project.deviceIds.find(device => device.id == item.id)){
    props.project.deviceIds = props.project.deviceIds.filter(device => device.id != item.id)
  }else{
    props.project.deviceIds.push(item)
  }
}
const getCheck = (id) => {
  return props.project.deviceIds.find(item => item.id == id)
}
</script>

<style lang="scss" scoped>
.search-div{
  height: 30px;
  margin-bottom: 10px;
  .search-input{
    :deep(.ant-input){
      background: #17181F;
      color: #FFFFFF;
    }
    background: #17181F;
    box-shadow: 0px 10px 30px 0px rgba(0,0,6,0.15), 0px 0px 4px 0px rgba(58,87,232,0.48);
    border-radius: 2px;
    border: 1px solid #3B4154;
    color: #FFFFFF;
    .search-icon{
      width: 18px;
      height: 18px;
      background-image: url('/public/projecthome/result_search_icon.png');
      background-size: 100% 100%;
      cursor: pointer;
    }
  }
}
.setting-table-title-div{
  display: flex;
  height: 30px;
  background: #2D3342;
  border-radius: 2px 2px 0px 0px;
  border-top: 1px solid #444B5F;
  border-left: 1px solid #444B5F;
  border-right: 1px solid #444B5F;
  font-family: 'PingFangSC-Regular';
  font-weight: 400;
  font-size: 13px;
  color: #FFFFFF;
  line-height: 18px;
  text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
  .table-title-item{
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #444B5F;
    .sort-icon{
      width: 11px;
      height: 14px;
      background-image: url('/public/projecthome/table_sort_icon.png');
      background-size: 100% 100%;
      margin-left: 2px;
    }
  }
}
.setting-table-item{
  display: flex;
  height: 35px;
  border-bottom: 1px solid #444B5F ;
  border-left: 1px solid #444B5F ;
  border-right: 1px solid #444B5F ;
  font-family: 'PingFangSC-Regular';
  font-weight: 400;
  font-size: 12px;
  color: #FFFFFF;
  line-height: 17px;
  text-shadow: 0px 10px 30px rgba(0,0,6,0.15);
  .table-item-col{
    display: flex;
    align-items: center;
    justify-content: center;
    .user-icon{
      width: 14px;
      height: 14px;
      background-image: url('/public/projecthome/user_icon.png');
      background-size: 100% 100%;
      margin-left: 3px;
    }
    .item-check{
      :deep(.ant-checkbox-inner){
        background-color: #17181F;
      }
    }
  }
}
</style>