<template>
  <div>
    <div class="sub-li mb-3 elevation-2" v-for="item in list" :key="item.id" @mouseenter="item.active = true" @mouseleave="item.active = false">
      <div class="company-info-top">
        <div class="company-info">
          <div class="float-left mr-5">
            <v-img :src="item.logoUrl || 'https://minio.citupro.com/dev/menduner/company-avatar.png'" :alt="item.anotherName" :width="40" style="height: 40px;border-radius: 4px;"/>
          </div>
          <h3 :class="{'default-active': item.active }" class="cursor-pointer" @click="handleClickEnterprise(item, 'briefIntroduction')">{{ dealEnterpriseName(item.anotherName || item.name) }}</h3>
          <p>{{ item.industryName }}<span v-if="item.industryName && item.scaleName" class="mx-2">|</span>{{ item.scaleName }}</p>
        </div>
        <div v-if="item.active">
          <v-btn class="half-button ml-3" color="primary" size="small" @click.stop="handleCancel(item)">取消收藏</v-btn>
        </div>
      </div>
      <div class="company-info-bottom">
        <div class="chipBox">
          <div class="d-inline-block" v-for="(val, i) in item.welfareList" :key="i">
            <span>{{ val }}</span>
            <span class="septal-line" v-if="i !== item.welfareList.length - 1 && val && item.welfareList[i + 1]"></span>
          </div>
        </div>
        <div class="position" @click="handleClickEnterprise(item, 'recruitmentPositions')">
          查看全部职位
          <v-icon>mdi-menu-right</v-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
defineOptions({ name: 'long-company-card'})
import Snackbar from '@/plugins/snackbar'
import { useI18n } from '@/hooks/web/useI18n'
import { dealEnterpriseName } from '@/utils/getText'
import { getEnterpriseUnsubscribe } from '@/api/enterprise'

const emits = defineEmits(['refresh'])
defineProps({
  list: Array
})

const { t } = useI18n()

const handleClickEnterprise = (item, key) => {
  window.open(`/recruit/personal/company/details/${item.id}?key=${key}`)
}

// 取消收藏
const handleCancel = async (item) => {
  if (!item.id) return Snackbar.warning(t('sys.api.operationFailed'))
  await getEnterpriseUnsubscribe(item.id)
  emits('refresh')
  Snackbar.success(t('common.operationSuccessful'))
}

</script>

<style scoped lang="scss">
.sub-li {
  position: relative;
  height: 130px;
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  transition: all .2s linear;
  background-color: #fff;
  &:nth-child(4n) {
    margin-right: 0;
  }
  &:hover {
    box-shadow: 0px 3px 5px -1px var(--v-shadow-key-umbra-opacity, rgba(0, 0, 0, 0.2)), 0px 5px 8px 0px var(--v-shadow-key-penumbra-opacity, rgba(0, 0, 0, 0.14)), 0px 1px 14px 0px var(--v-shadow-key-ambient-opacity, rgba(0, 0, 0, 0.12)) !important;
  }
}
.company-info {
  float: left;
  margin-left: 16px;
  width: 282px;
}
.company-info-top {
  display: flex;
  height: 76px;
  padding: 16px 20px;
  overflow: hidden;
  justify-content: space-between;
}
.company-info h3 {
  height: 22px;
  font-size: 16px;
  font-weight: 400;
  color: var(--color-222);
  line-height: 22px;
  margin: 0 0 4px 0;
  padding: 0;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.company-info p {
  height: 18px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-999);
  line-height: 18px;
}
.company-info-bottom {
  display: flex;
  width: 100%;
  padding: 16px 20px;
  justify-content: space-between;
  background-color: #f8fcfb;
  .chipBox {
    width: 70%;
    min-width: 70%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px; 
    color: var(--color-999);
  }
  .position {
    color: var(--color-666);
    font-size: 14px;
    cursor: pointer;
    &:hover {
      color: var(--v-primary-base);
    }
  }
}
</style>
