<template>
  <view class="tag-list">
    <view
      v-for="(item, index) in tags"
      :key="index"
      class="tag-item"
      @click="handleClick(item)"
    >
      <text class="tag-text">{{ item }}</text>
    </view>
  </view>
</template>

<script setup>
import { ref, nextTick, defineEmits } from "vue";
import { onMounted } from "vue";
import { SCROLL_TO_BOTTOM } from "@/constant/constant";

const props = defineProps({
  question: {
    type: String,
    default: "",
  },
});

const tags = ref([]);
const emits = defineEmits(["replySent"]);

const handleClick = (item) => {
  emits("replySent", item);
};

onMounted(() => {
  tags.value = props.question.split(/[&|;]/).filter((tag) => tag.trim() !== "");
  nextTick(() => {
    setTimeout(() => {
      uni.$emit(SCROLL_TO_BOTTOM, true);
    }, 300);
  });
});
</script>

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