<template>
  <div
    class="flex flex-row gap-x-[9px] ml-[12px] py-[8px] overflow-x-auto whitespace-nowrap [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden">
    <div class="border border-white bg-white/50 px-3 py-1 rounded-[50px] flex flex-row items-center"
      v-for="(item, index) in itemList" :key="index" @click="sendReply(item)">
      <div class="flex items-center justify-center">
        <img v-if="item.icon" class="w-5 h-5 mr-[2px]" :src="item.icon" />
        <span class="text-[14px] text-[#2D91FF] leading-5">
          {{ item.title }}
        </span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { Command } from "@/constants/ChatModel";
import { SEND_MESSAGE_COMMAND_TYPE } from "@/constants/constant";
import { checkToken } from "@/hooks/useGoLogin";

const itemList = ref([
  {
    icon: "",
    title: "快速预定",
    type: Command.quickBooking,
  },
  {
    icon: "",
    title: "我的订单",
    type: Command.myOrder,
  },
  {
    icon: "",
    title: "呼叫服务",
    type: Command.callServiceCard,
  },
  {
    icon: "https://oss.nianxx.cn/mp/static/version_101/home/more.png",
    title: "更多",
    type: Command.more,
  },
]);

const sendReply = (item) => {
  // 更多服务
  if (item.type === Command.more) {
    uni.$emit("SHOW_MORE_POPUP");
    return;
  }

  // 快速预定
  if (item.type === Command.quickBooking) {
    checkToken().then(() => {
      uni.navigateTo({ url: "/pages-quick/list" });
    });
    return;
  }

  // 我的订单
  if (item.type === Command.myOrder) {
    checkToken().then(() => {
      uni.navigateTo({ url: "/pages-order/order/list" });
    });
    return;
  }

  uni.$emit(SEND_MESSAGE_COMMAND_TYPE, item);
};
</script>
