<template>
  <div class="pt-[4px] pb-[8px] w-full">
    <div
      class="pb-[2px] overflow-x-auto whitespace-nowrap w-full scrollbar-none [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
      <div v-for="item in items" :key="item.id || item.title"
        class="w-[200px] mr-3.5 align-top border border-slate-100 shadow-[0_8px_22px_rgba(15,23,42,0.06)] inline-block bg-white rounded-[20px] overflow-hidden active:opacity-86"
        :class="{ 'opacity-55': disabled }" @click="handleSelect(item)">
        <img class="h-[110px] block w-full" :src="item.image" />
        <div class="p-[16px]">
          <div class="leading-[22px] text-[#1e293b] text-[18px] font-bold truncate">
            {{ item.title }}
          </div>
          <div class="leading-[16px] flex items-center gap-[4px] mt-[4px] text-[#94A3B8] text-[12px] font-bold">
            <span class="text-[13px] leading-[13px]">⌖</span>
            <span>{{ item.distance }}</span>
          </div>
          <div
            class="h-9 border border-gray-200 rounded-lg bg-slate-50 flex items-center justify-center mt-[12px] text-[#334155] text-[12px] font-bold"
            @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>
