<script>
import { AuctionItem } from '../models/AuctionItem.js';

export default {
  name: 'LicitatieResultItem',
  props: {
    licitatie: {
      type: Object,
      required: true
    }
  },
  computed: {
    auction() {
      return AuctionItem.fromApiData(this.licitatie);
    },
    formattedNoticeDate() {
      return this.auction.getFormattedNoticeStateDate();
    },
    formattedDeadline() {
      return this.auction.getFormattedTenderReceiptDeadline();
    },
    authorityName() {
      return this.auction.getAuthorityName();
    },
    isActive() {
      return this.auction.isActive();
    }
  }
}
</script>

<template>
  <a :href="auction.url" target="_blank" class="licitatie-result-item licitatie-link-wrapper"
    :class="{ 'inactive': !isActive }">
    <div class="licitatie-header">
      <div class="licitatie-header-left">
        <span class="licitatie-notice">{{ auction.noticeNo }}</span>
        <span class="licitatie-cpv">CPV: {{ auction.cpvCode }}</span>
      </div>
      <div class="licitatie-header-right">
        <span class="licitatie-status" :class="{ 'active': isActive, 'inactive': !isActive }">
          {{ auction.procedureStatus }}
        </span>
        <span class="licitatie-link-inline">Vezi detalii</span>
      </div>
    </div>
    <span class="licitatie-title">{{ auction.contractTitle }}</span>
    <div class="licitatie-details">
      <div><strong>Autoritate:</strong> {{ authorityName }}</div>
      <div><strong>Tip:</strong> {{ auction.contractType }}</div>
      <div><strong>Suma estimată:</strong> {{ auction.estimatedValueExport }}</div>
      <div><strong>Data publicării:</strong> {{ formattedNoticeDate }}</div>
      <div><strong>Termen limită:</strong> {{ formattedDeadline }}</div>
    </div>
  </a>
</template>
