<script setup>
import { ref, computed } from "vue";
import XSquareCarouselImage from "../../../components/XSquareCarouselImage.vue";
import { toWXMiniApp } from "../../../utils/uils.js";
import XImage from "../../../components/XImage.vue";

const { data, home } = defineProps({
    data: {
        type: Object,
        default: null,
    },
    home: {
        type: Boolean,
        default: false,
    }
});

const current = ref(0);

const list = computed(() => data.children.material[current.value].comment?.flatMap(v => v.children ? [v, ...v.children] : [v]));
</script>

<template>
    <!--领取素材-->
    <view class="!flex gap-[24rpx] !mb-[28rpx]">
        <view v-for="(item, index) in data.children.material" @click="current = index"
            :class="['tab-item', index === current ? 'cur' : '']">
            素材{{ index + 1 }}
        </view>
    </view>

    <template v-if="true">
        <view class="block"
            v-if="data.material_type?.title_limit > 0 && data.children.material[current].title?.length > 0">
            <view class="block-title">
                标题:
            </view>
            <view class="block-info">
                {{ data.children.material[current].title }}
            </view>
        </view>
        <view class="block" v-if="data.material_type?.desc_limit > 0">
            <view class="block-title">
                正文:
            </view>
            <view class="block-info">
                {{ data.children.material[current].content }}
            </view>
        </view>
        <view class="block"
            v-if="data.material_type?.tags_limit > 0 && data.children.material[current].tags_arr?.length > 0">
            <view class="block-title">
                话题:
            </view>
            <view class="block-info">
                {{data.children.material[current].tags_arr.map(item => `#${item}`).join(' ')}}
            </view>
        </view>
        <view class="block" v-if="data.children.material[current].material_arr?.length > 0">
            <view class="block-title">
                素材:
            </view>
            <view class="block-info">
                <x-square-carousel-image :list="data.children.material[current].material_arr"
                    :show-s-y="home"></x-square-carousel-image>
            </view>
        </view>
        <view class="block" v-if="list?.length > 0">
            <view class="block-title">
                评论区案例:
            </view>
            <view class="block-info">
                <view v-for="(v, index) in list">
                    <view>
                        评论{{ index + 1 }}:
                        <text v-if="v.pid" class="text-[rgba(134,144,156)]">
                            <image class="!size-[20rpx]" src="/static/icons/msgback.png"></image>
                            回复{{
                                list.findIndex(k => k.pid === v.pid)
                            }}
                        </text>
                        {{ v.intro }}
                    </view>
                    <view class="!flex gap-[20rpx] flex-wrap !my-[10rpx]">
                        <view class="!w-[96rpx] !h-[96rpx] !aspect-square" v-for="k in v.image_arr">
                            <x-image :style="{
                                width: '96rpx',
                                height: '96rpx',
                            }" :src="k" :list="v.image_arr">
                            </x-image>
                        </view>
                    </view>
                </view>
            </view>
        </view>

        <tui-button size="28" @click="toWXMiniApp(data.id, data.children.id)">
            <tui-icon size="20" color="#fff" name="bottom"></tui-icon>
            <view class="!ml-[20rpx]">一键下载</view>
        </tui-button>
    </template>
</template>

<style scoped lang="scss">
.tab-item {
    padding: 12rpx 26rpx;
    border-radius: 9999rpx;
    background-color: #F7F8FA;
    font-size: 24rpx;
    color: #4E5969;
    transition: 500ms;
}

.cur {
    background-color: #E8F3FF;
    color: #165DFF;
}

.block {
    display: flex;
    gap: 20rpx;
    margin-bottom: 20rpx;

    .block-title {
        flex-shrink: 0;
        color: rgb(134, 144, 156);
        font-size: 24rpx;
        font-weight: 500;
        line-height: 140%;
        letter-spacing: 0;
        text-align: left;
        width: 160rpx;
    }

    .block-info {
        color: rgb(78, 89, 105);
        font-size: 24rpx;
        font-weight: 500;
        line-height: 140%;
        letter-spacing: 0;
        white-space: pre-line;
    }
}
</style>
