<template>
  <div class="d-flex">
    <div class="position-box">
      <div class="sub-li"
        v-for="(item, index) in list" :key="index"
        :class="{'chosen': chosenIndex === index}"
        :style="`margin-top: ${index ? '12px' : '0'}`"
        @mouseenter="item.active = true" @mouseleave="item.active = false"
        @click="handleClick(item, index)"
      >
        <div class="job-info">
          <div class="sub-li-top">
            <div class="sub-li-info">
              <p v-ellipse-tooltip.top :class="['name', {'default-active': item.active }]">{{ formatName(item.name) }}</p>
              <svg-icon v-if="item.hire" name="pin" size="30"></svg-icon>
            </div>
          </div>
          <div class="d-flex justify-space-between align-center">
            <div>
              <span v-for="(j, i) in desc" :key="i" class="font-size-13" style="color: #808080;">
                <span v-if="item[j.value] || j.value === 'areaName'" class="mr-1 d-inline-block">
                  {{ j.value === 'areaName' ? !item.areaId ? '全国' : item.area?.str : item[j.value]}}
                  <!-- {{ (j.value === 'areaName' && !item.areaId) ? '全国' : item[j.value] }} -->
                </span>
                <span v-if="i !== desc.length - 1 && (j.value === 'areaName' || item[desc[i + 1].value])" class="septal-line ml-1"></span>
              </span>
            </div>
            <div>
              <p v-if="!item.payFrom && !item.payTo" class="salary">面议</p>
              <p v-else class="salary">{{ item.payFrom ? item.payFrom + '-' : '' }}{{ item.payTo }}{{ item.payName ? '/' + item.payName : '' }}</p>
            </div>
          </div>
          <div class="ellipsis" style="height: 24px;overflow: hidden;">
            <span v-for="(j, i) in item.tagList" :key="i" class="mr-3 tags" style="color: #345768;">{{ j }}</span>
          </div>
        </div>
        <div class="sub-li-bottom">
          <div class="user-info">
            <div class="d-flex align-center">
              <v-avatar size="35">
                <v-img :src="item.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" />
              </v-avatar>
              <span v-ellipse-tooltip.top class="names ml-2 font-size-14 ellipsis" style="max-width: 88%;">
                {{ formatName(item.anotherName || item.name) }}
                <span class="color-999 font-size-13 ml-3">
                  <span>{{ item.industryName }}</span>
                  <span class="septal-line" v-if="item.industryName && item.scaleName"></span>
                  <span>{{ item.scaleName }}</span>
                </span>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
defineOptions({ name: 'position-card-item' })
import { ref, watch } from 'vue'
import { formatName } from '@/utils/getText'
import { spaces } from '@/utils/index.js'

const emit = defineEmits([''])
const props = defineProps({
  items: {
    type: Array,
    default: () => []
  }
})
const chosenIndex = ref(0)
const list = ref([])
watch(
  () => props.items, 
  (newVal) => {
    list.value = newVal
  },
  { immediate: true },
  { deep: true }
)
const desc = [
  { mdi: 'mdi-map-marker-outline', value: 'areaName' },
  { mdi: 'mdi-school-outline', value: 'eduName' },
  { mdi: 'mdi-clock-time-ten-outline', value: 'expName' }
]

const handleClick = (item, index) => {
  chosenIndex.value = index
  list.value.forEach((e, i) => e.active = i === index )
  emit('selectChange', item)
}
</script>

<style lang="scss" scoped>
.position-box {
  width: 100%;
  height: 100%;
}
.chosen { border: 1px solid var(--v-primary-lighten2) !important; }
.sub-li {
  position: relative;
  width: 384px;
  height: 149px;
  margin-right: 8px;
  margin-top: 12px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  // transition: all .2s linear;
  background-color: #fff;
  border: 1px solid #fff;
  &:hover {
    box-shadow: 0 16px 40px 0 rgba(153, 153, 153, .3);
    .salary { color: var(--v-error-base) !important; }
  }
}
.job-info {
  position: relative;
  padding: 16px 20px;
}
.recommend {
  position: absolute;
  left: 0;
  top: 0;
}
.sub-li-top {
  display: flex;
  width: 100%;
  align-items: center;
}
.sub-li-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  height: 31%;
  overflow: hidden;
  flex: 1;
}
.salary {
  font-size: 16px;
  font-weight: 700;
  color: #CEC149;
  line-height: 22px;
  flex: none;
}
.tags {
  font-size: 12px;
  color: #666;
  display: inline-block;
}
.job-text {
  white-space: normal;
  padding-right: 0;
  height: 22px;
  line-height: 22px;
  overflow: hidden;
  word-break: break-all;
  max-width: none;
}
.sub-li-info .name {
  position: relative;
  // max-width: 140px;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  color: #345768;
  &:hover {
    color: var(--v-primary-base);
  }
}
.sub-li-bottom {
  position: absolute;
  width: 100%;
  height: 54px;
  bottom: 1px;
  left: 0;
  margin-top: 10px;
  padding-top: 0;
  display: block;
  border: none;
}
.user-info {
  padding: 12px 20px;
}
.names {
  font-weight: 500;
  &:hover {
    // color: var(--v-primary-base);
    color: #404040;
  }
}
</style>