<template>
  <div class="facility-location-card bg-white rounded-24 overflow-hidden w-full">
    <img class="facility-location-card__image block w-full" :src="data.image" mode="aspectFill" />

    <div class="facility-location-card__body px-24 pb-24">
      <div class="facility-location-card__title-row flex flex-items-center">
        <div class="facility-location-card__badge color-2563EB bg-EFF6FF font-size-12 font-900">
          {{ type.text }}
        </div>
        <div class="facility-location-card__title color-1E293B font-size-18 font-900 ellipsis-1">
          {{ data.title }}
        </div>
      </div>

      <div class="facility-location-card__distance flex flex-items-center color-94A3B8 font-size-14 font-900">
        <span class="facility-location-card__distance-icon">{{ distance.icon }}</span>
        <span>{{ distance.text }}</span>
      </div>

      <div class="facility-location-card__location bg-F8FAFC rounded-20">
        <div class="facility-location-card__location-label flex flex-items-center color-64748B font-size-13 font-900">
          <span class="facility-location-card__location-dot">{{ location.icon }}</span>
          <span>{{ location.label }}</span>
        </div>
        <div class="facility-location-card__location-text color-1E293B font-size-16 font-900">
          {{ location.text }}
        </div>
      </div>

      <div
        class="facility-location-card__button flex flex-items-center flex-justify-center bg-0F172A color-white font-size-18 font-900"
        :class="{ 'is-disabled': disabled }" @click="handleAction">
        <span class="facility-location-card__button-icon">{{ action.icon }}</span>
        <span>{{ action.text }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue";

const props = defineProps({
  data: {
    type: Object,
    default: () => ({}),
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});

const emit = defineEmits(["action", "select"]);

const type = computed(() => props.data.type || {});
const distance = computed(() => props.data.distance || {});
const location = computed(() => props.data.location || {});
const action = computed(() => props.data.action || {});

const handleAction = () => {
  if (props.disabled) return;
  emit("action", props.data);
  emit("select", props.data);
};
</script>

<style scoped lang="scss">
@import "./styles/index.scss";
</style>
