<template>
  <div>
    <div class="position-item mb-3 job-closed" v-for="(val, i) in props.items" :key="i" @mouseenter="val.active = true" @mouseleave="val.active = false">
      <div class="info-header">
        <div v-if="val.active" class="header-btn">
          <v-btn v-if="props.showCancelBtn" class="half-button ml-3" color="primary" size="small" @click="handleCancel(val)">取消感兴趣</v-btn>
        </div>
        <div class="img-box">
          <v-avatar :image="getUserAvatar(val.contact.avatar, val.contact.sex)" size="x-small"></v-avatar>
          <span class="name">
            <span class="mx-3">{{ val.contact.name }}</span>
            <span class="gray">{{ val.contact.postNameCn }}</span>
          </span>
        </div>
      </div>
      <div class="info-content">
        <div class="job-info">
          <div class="job-name cursor-pointer">
            <span class="mr-3 info-name" @click="handleToPositionDetails(val)">{{ val.job.name }}</span>
            <span v-if="val?.job?.areaName">[{{ val.job.areaName }}]</span>
          </div>
          <div class="job-other">
            <span class="salary">{{ val.job.payFrom }}-{{ val.job.payTo }}/{{ val.job.payName }}</span>
            <v-chip class="mx-3" color="primary" label size="small">{{ val.job.expName }}</v-chip>
            <v-chip color="primary" label size="small">{{ val.job.eduName }}</v-chip>
          </div>
        </div>
        <div class="company-info ml-3" style="flex: 1;">
          <div style="height: 50px; width: 50px;">
            <v-img width="50" height="50" :src="val.enterprise.logoUrl || 'https://minio.citupro.com/dev/menduner/7.png'"></v-img>
          </div>
          <div class="ml-3">
            <div class="cursor-pointer info-name">{{ val.enterprise.name }}</div>
            <div class="mt-3 ellipsis color-666 font-size-13" style="max-width: 260px;">
              <span v-for="(k, i) in desc" :key="k">
                {{ val.enterprise[k] }}
                <span v-if="i !== desc.length - 1 && val.enterprise[k]" class="septal-line"></span>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
defineOptions({ name: 'longStrip'})
import { getPersonJobUnfavorite } from '@/api/position'
import { useI18n } from '@/hooks/web/useI18n'
import Snackbar from '@/plugins/snackbar'
import { getUserAvatar } from '@/utils/avatar'
import { useRouter } from 'vue-router'

const emits = defineEmits(['refresh'])
const { t } = useI18n()
const props = defineProps({
  items: {
    type: Array,
    default: () => []
  },
  showCancelBtn: {
    type: Boolean,
    default: false
  }
})

const router = useRouter()

const desc = ['industryName', 'financingName', 'scaleName']

const handleCancel = async (item) => {
  if (!item.job.id) return Snackbar.warning(t('sys.api.operationFailed'))
  await getPersonJobUnfavorite(item.job.id)
  emits('refresh')
  Snackbar.success(t('common.operationSuccessful'))
}

// 职位详情
const handleToPositionDetails = (item) => {
  router.push(`/recruit/personal/position/details/${item.job.id}`)
}
</script>

<style scoped lang="scss">
.position-item {
  height: 144px;
  background-color: #fff;
  border-radius: 12px;
  &:hover {
    box-shadow: 0 16px 40px 0 rgba(153, 153, 153, .3);
  }
  .info-header {
    height: 48px;
    background: linear-gradient(90deg,#f5fcfc,#fcfbfa);
    border-radius: 12px;
    .img-box {
      padding: 12px 24px;
      .name {
        color: var(--color-222);
        font-weight: 400;
        font-size: 13px;
        .gray {
          color: var(--color-666);
        }
      }
    }
    .header-btn {
      padding: 10px 10px 0 0;
      float: right;
      .v-btn {
        z-index: 1;
      }
    }
  }
  .info-content {
    display: flex;
    padding: 16px 24px;
    justify-content: space-between;
    .job-info {
      width: 430px;
      min-width: 430px;
      max-width: 430px;
      font-weight: 500;
      font-size: 16px;
      .job-name {
        height: 22px;
        line-height: 22px;
        color: var(--color-222);
        margin-bottom: 12px;
      }
      .job-other {
        color: var(--v-error-base);
        height: 22px;
        line-height: 22px;
      }
    }
    .company-info {
      display: flex;
      align-items: center
    }
    .interview-info {
      color: var(--color-333);
      font-size: 15px;
    }
  }
}

.info-name:hover {
  color: var(--v-primary-base);
}
</style>
