<script setup>
import { computed } from 'vue';

const props = defineProps({
    block: {
        type: Object,
        required: true,
    },
    activeLang: {
        type: String,
        default: '',
    },
});

const displayContent = computed(() => {
    const c = props.block.content;
    // Legacy: plain string
    if (typeof c === 'string') return c;
    // Object: try active lang, then first available, then empty
    if (c && typeof c === 'object') {
        return c[props.activeLang] || c[Object.keys(c)[0]] || '';
    }
    return '';
});
</script>

<template>
    <section class="block-text">
        <div v-if="displayContent" class="block-text__body" v-html="displayContent"></div>
        <p v-else class="block-text__placeholder">Add narrative copy for this full-width text row.</p>
    </section>
</template>

<style scoped>
.block-text {
    margin: 0 auto;
    max-width: 56rem;
    text-align: center;
}

.block-text__placeholder {
    color: var(--project-muted, #6b7280);
    font-size: clamp(1.05rem, 1.8vw, 1.4rem);
    line-height: 1.75;
    margin: 0;
}

:deep(.block-text__body p),
:deep(.block-text__body h2),
:deep(.block-text__body h3),
:deep(.block-text__body ul),
:deep(.block-text__body ol) {
    color: var(--project-ink, #111827);
    font-size: clamp(1.05rem, 1.8vw, 1.4rem);
    line-height: 1.75;
    margin: 0 0 0.75em;
}

:deep(.block-text__body p:last-child),
:deep(.block-text__body h2:last-child),
:deep(.block-text__body h3:last-child),
:deep(.block-text__body ul:last-child),
:deep(.block-text__body ol:last-child) {
    margin-bottom: 0;
}

:deep(.block-text__body h2) {
    font-size: clamp(1.3rem, 2.2vw, 1.8rem);
    font-weight: 700;
}

:deep(.block-text__body h3) {
    font-size: clamp(1.1rem, 1.9vw, 1.5rem);
    font-weight: 700;
}

:deep(.block-text__body ul),
:deep(.block-text__body ol) {
    display: inline-block;
    padding-left: 1.4rem;
    text-align: left;
}

:deep(.block-text__body a) {
    color: #0f766e;
    text-decoration: underline;
}
</style>