<template>
    <div class="message-branch-container">
        <div v-if="header" class="message-branch-title">{{ header }}</div>
        <div v-for="(item, index) in items" :key="`${item?.content ?? ''}-${index}`" class="message-branch-item">
            {{ item?.content ?? '' }}
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue'

interface BranchItem {
    content?: string
}

interface BranchContent {
    header?: string
    title?: string
    items?: BranchItem[] | null
}

interface CustomerServicePayload {
    content?: BranchContent | null
}

interface Props {
    payload?: CustomerServicePayload | null
}

const props = defineProps<Props>()

const header = computed(() => {
    return props.payload?.content?.header ?? props.payload?.content?.title ?? ''
})

const items = computed<BranchItem[]>(() => {
    return props.payload?.content?.items ?? []
})
</script>

<style scoped>
.message-branch-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-branch-title {
    word-break: break-all;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px;
    font-size: 14px;
    color: #000;
    letter-spacing: 0;
    overflow-wrap: break-word;
    position: relative;
    background: #EEF0F5;
    border-radius: 10px 0 10px 10px;
    margin-bottom: 8px;
    max-width: 300px;
    width: fit-content;
}

.message-branch-item {
    word-break: break-all;
    max-width: 200px;
    background: #EEF0F5;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 8px;
    color: #1c66e5;
    width: fit-content;
    display: inline-block;
    font-size: 14px;
}
</style>
