<template>
  <div class="lofty-house-item">
    <div class="lofty-house-img">
      <a target="_blank" :href="house.detailUrl">
        <img v-if="house.previewPicture" :src="house.previewPicture" loading="lazy" :alt="house.address">
        <img v-else :src="noImg" loading="lazy" :alt="house.address">
      </a>
      <house-mask v-if="house.isProtected"></house-mask>
      <template v-if="!house.isProtected">
        <div v-for="tag in house.listingTags" :class="['lofty-status-tag', tag.style.className]">{{ tag.value }}</div>
        <div class="lofty-img-counts">
          <i class="lofty_iconfont lofty-icon-pic"></i>
          <span class="lofty-count-number">{{ house.picturesNum }}</span>
        </div>
        <i v-show="!house.soldDate && !house.collectStatus" class="lofty_iconfont lofty-icon-heart-fill lofty-icon-heart-mask"></i>
        <i v-if="!house.soldDate" @click="toggleCollect" :class="['lofty_iconfont', house.collectStatus ? 'lofty-icon-heart-fill' : 'lofty-icon-heart']"></i>
        <slot name="inner" :house="house"></slot>
      </template>
    </div>
    <p v-if="house.soldDate && house.showSoldPrice" class="lofty-item-price">
      <span>{{ house.soldPrice }}</span>
      <span class="lofty-house-initial-price">{{ house.price }}</span>
      <span v-if="house.priceChange && !house.isProtected" :class="['lofty-trend-rate', house.priceTrend]">
                    <i v-if="house.priceTrend==='up'" class="lofty_iconfont lofty-icon-arrow_03_up"></i>
                    <i v-else-if="house.priceTrend==='down'" class="lofty_iconfont lofty-icon-arrow_04_down"></i>
        {{house.priceChangePercent}}
      </span>
    </p>
    <p v-else class="lofty-item-price">{{ house.price }}</p>
    <div class="lofty-house-info">
      <p class="lofty-house-base">
        <span v-for="item in house.basic" :key="item.key">{{item.text}}</span>
      </p>
      <p class="lofty-feature-address">
        <a target="_blank" :href="house.detailUrl">{{house.address}}</a>
      </p>
    </div>
    <div v-if="house.showMls" class="lofty-house-mls-id">
      MLS# {{ house.mlsListingId }}
    </div>
    <div class="lofty-mls-info">
      <p class="lofty-mls-text" v-html="house.provided"></p>
      <div v-if="house.mlsLogo" class="lofty-mls-logo">
        <img :src="house.mlsLogo" :alt="house.mlsOrg.name">
      </div>
    </div>
  </div>
</template>

<script setup>
import HouseMask from './houseMask.vue';
import collectHouse from "@/common/collect-house.js";
import EmptyImage from "@/static/feature-listing-slider.jpg";
const noImg = LoftyIdxUtils.static_url(EmptyImage)
const { house }  = defineProps({house: Object})
const emits = defineEmits(['refresh'])
function toggleCollect() {
  collectHouse(house.id, house.collectStatus, ()=>{
    house.collectStatus = !house.collectStatus
    emits('refresh')
  })
}
</script>
<style lang="scss">
.lofty-house-item {
  .lofty-house-img {
    height: 230px;
    position: relative;
    a {
      display: block;
      width: 100%;
      height: 100%;
      img {
        width: 100%;
        height: 100% !important;
        object-fit: cover;
        transition: 0.5s;
      }
    }
  }
  .lofty-status-tag {
    position: absolute;
    left: 10px;
    top: 10px;
    height: 22px;
    padding: 0 6px;
    border-radius: 2px;
    color: #fff;
    font-size: 12px;
    font-weight: 400;
    line-height: 22px;
    text-align: center;
    margin: 0;
  }
  .lofty-img-counts {
    width: 51px;
    height: 28px;
    background: rgba(17, 17, 17, 0.4);
    border-bottom-left-radius: 10px;
    position: absolute;
    right: 0;
    top: 0;
    padding: 5px 7px;
    color: #fff;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .lofty-icon-pic {
      font-size: 14px;
    }
    .lofty-count-number {
      font-size: 14px;
      font-weight: 400;
      text-align: left;
    }
  }
  .lofty-icon-heart-fill, .lofty-icon-heart{
    position: absolute;
    right: 10px;
    bottom: 10px;
    cursor: pointer;
    font-size: 24px;
    width: 27px;
    height: 24px;
  }
  .lofty-icon-heart-fill {
    color: rgba(240, 69, 76, 1);
  }
  .lofty-icon-heart {
    color: #fff;
  }
  .lofty-icon-heart-mask {
    color: rgba(25, 25, 25, 0.4)!important;
  }
  .lofty-item-price {
    margin-top: 20px;
    font-size: 26px;
    font-family: "font-bold";
    line-height: 30px;
    text-align: left;
    color: #111111;
    display: flex;
    align-items: center;
    margin-bottom: 0;
    .lofty-house-initial-price {
      color: #a8a8a8;
      margin-top: 3px;
      font-size: 16px;
      line-height: 24px;
      font-weight: 400;
      margin-left: 10px;
      text-decoration: line-through;
    }
    .lofty-trend-rate {
      margin-left: 10px;
      font-size: 16px;
    }
    .up {
      color: #25C44E;
    }
    .down {
      color: #F0454C;
    }
  }
  .lofty-house-info {
    margin-top: 10px;
    font-size: 15px;
    line-height: 20px;
    color: #555555;
    p.lofty-house-base {
      span + span {
        padding-left: 7px;
        &::before {
          content: "|";
          margin-right: 10px;
        }
      }
    }
    p.lofty-feature-address {
      margin-top: 6px;
      line-height: 20px;
      a:hover {
        text-decoration: underline;
      }
    }
  }
  .lofty-house-mls-id {
    margin-top: 10px;
    color: #aaaaaa;
    font-size: 14px;
  }
  .lofty-mls-info {
    display: flex;
    align-items: flex-end;
    margin-top: 10px;
    @include media-600 {
      margin-bottom: 0;
    }
    .lofty-mls-text {
      color: #aaaaaa;
      font-size: 14px;
      margin-right: 10px;
      line-height: 1.5;
    }
    .lofty-mls-logo {
      margin-left: auto;
      display: flex;
      img {
        height: 18px;
      }
    }
  }
}
</style>