<template>
    <el-space direction="vertical" class="full-width news-image-background">
        <el-button class="float-btn" @click="gotoNewsBrief(false)"><el-icon>
                <back />
            </el-icon> 返回</el-button>
        <el-space style="width: 993px;" direction="vertical" alignment="flex-start">
            <div style="margin-top: 50px; margin-bottom: 24px; margin-left: 24px;">
                <common-text class="text-title-0-show" color="var(--text-primary-90-color)">{{
                    moduleName
                    }}</common-text>
                <common-text class="text-regular"
                    color="var(--text-primary-65-color)">基于情报价值评估预测算法，掌握全球重要潜在动向</common-text>
            </div>
            <el-space direction="vertical" fill alignment="flex-start" class="background-as-card common-padding">
                <el-radio-group v-model="currentAreaId" class="radio-group-as-gap-btn">
                    <el-space direction="horizontal" wrap alignment="center">
                        <el-radio-button :label="''" @click="changeArea('')">全部</el-radio-button>
                        <el-radio-button v-for="(t, i) in AreaList" :key="i" :label="t.id" @click="changeArea(t.id)">{{
                            t.name }}
                        </el-radio-button>
                    </el-space>
                </el-radio-group>
                <el-divider style="margin: 10px 0px;"></el-divider>
                <div class="">
                    <news-list :news="NewsData" />
                </div>
            </el-space>
        </el-space>
    </el-space>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRoute } from 'vue-router';
import '@/styles/container.scss';
import '@/styles/radio.scss';
import NewsList from "./NewsList.vue";
import { getAreaList, getHotNewsByArea } from "@/api/news/newsBrief";
import { ElSpace, ElDivider, ElRadioButton, ElRadioGroup, ElButton, ElIcon } from "element-plus";
import CommonText from "@/components/base/texts/CommonText.vue";
import { useGotoNewsBrief } from "@/router/modules/news";

const route = useRoute();
const gotoNewsBrief = useGotoNewsBrief();
const moduleId = ref(route.params.id);
const moduleName = ref(route.query.name ?? "");
const NewsData = ref([]);
const AreaList = ref([]);
const currentAreaId = ref("");
onMounted(async () => {
    console.log(route.query.name, moduleId.value, moduleName.value);
    const { data: areaList } = await getAreaList();
    AreaList.value = areaList ?? [];
    await changeArea("")
});
async function changeArea(id) {
    const { data } = await getHotNewsByArea({
        moduleId: moduleId.value,
        industryId: id ? id : null,
    });
    data?.forEach(item => {
        item.newsImage = item.coverUrl ?? ""
    })
    NewsData.value = data ?? [];
}

</script>

<style lang="scss" scoped>
@use '@/styles/common.scss' as *;
@import url("./style.css");


.float-btn {
    position: absolute;
    top: 24px;
    left: 40px;
    width: 92px;
    height: 40px;
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border: 1px solid rgba(255, 255, 255, 1);
    border-radius: 32px;
    @extend .text-regular;
    color: var(--text-primary-65-color);
}
</style>