<template>
  <div class="recommendation-list-card w-full">
    <div class="recommendation-list-card__scroll scroll-x whitespace-nowrap w-full" scroll-x :show-scrollbar="false"
      enhanced>
      <div v-for="item in items" :key="item.id || item.title"
        class="recommendation-list-card__item inline-block bg-white rounded-20 overflow-hidden"
        :class="{ 'is-disabled': disabled }" @click="handleSelect(item)">
        <img class="recommendation-list-card__image block w-full" :src="item.image" mode="aspectFill" />
        <div class="recommendation-list-card__body p-16">
          <div class="recommendation-list-card__name color-1E293B font-size-18 font-900 ellipsis-1">
            {{ item.title }}
          </div>
          <div
            class="recommendation-list-card__distance flex flex-items-center gap-4 mt-4 color-94A3B8 font-size-12 font-800">
            <span class="recommendation-list-card__pin">⌖</span>
            <span>{{ item.distance }}</span>
          </div>
          <div
            class="recommendation-list-card__button flex flex-items-center flex-justify-center mt-12 color-334155 font-size-12 font-900"
            @click.stop="handleSelect(item)">
            {{ getActionText(item) }}
          </div>
        </div>
      </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(["select"]);

const items = computed(() => props.data.items || []);

const getActionText = (item) => {
  return (item.action && item.action.text) || "";
};

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

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