<script setup>
import { reactive } from "vue";
import { useRoute } from "vue-router";
import axios from "axios";
import moment from "moment";
import Navbar from "@/components/Navbar.vue";

const route = useRoute();
const newsId = route.params.id; // 網址參數
const news = reactive({
  data: [],
});

(async function getData() {
  try {
    const response = await axios.get(
      `https://cmm.ai:8088/api/get_news?news_id=${newsId}`
    );
    news.data = response.data.news[0];
    console.log("news.data", news.data);
  } catch (error) {
    console.error(error);
  }
})();
</script>

<template>
  <Navbar />
  <div class="position-relative">
    <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
    <v-container class="pa-0 pt-16 position-relative">
      <!-- <img
        src="@/assets/img/news/news-detail-banner.png"
        alt=""
        class="bg-img"
      /> -->

      <div class="content">
        <div class="article">
          <v-row>
            <v-col cols="12">
              <div class="d-flex align-center mb-5">
                <v-chip size="large" variant="elevated" class="px-8 me-3">
                  {{ news.data.category }}
                </v-chip>
                <p>
                  {{ moment(`${news.data.create_time}`).format("YYYY.MM.DD") }}
                </p>
              </div>
              <h2>【{{ news.data.title }}】</h2>
              <img src="@/assets/img/img-04.jpg" alt="" class="cover-img" />
              <!-- <img :src="`https://cmm.ai/ntcri/${news.data.cover_img}`" alt="" /> -->
            </v-col>
            <v-col cols="12">
              <section class="d-flex flex-column pa-0">
                <p v-html="news.data.content"></p>

                <div class="btn-block mt-10">
                  <v-btn rounded="xl" color="grey-darken-2" class="px-7">
                    檔案下載
                  </v-btn>
                  <v-btn rounded="xl" color="grey-darken-2" class="px-7 ms-3">
                    前往連結
                  </v-btn>
                </div>
              </section>
            </v-col>
          </v-row>
        </div>
      </div>
    </v-container>
    <router-link to="/news" class="mt-16 back-link"
      >＜ 返回重要訊息</router-link
    >
    <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
  </div>
</template>

<style lang="scss" scoped>
.btn-block {
  display: flex;
  justify-content: end;
}

.content {
  padding: 20px;
  background-image: url("@/assets/img/news/news-02.png");
  background-position: center;
  background-size: cover;
  border-radius: 50px;
  @media (max-width: 960px) {
    width: 90%;
    margin: auto;
  }
}
.article {
  margin: auto;
  padding: 80px 50px;
  display: flex;
  justify-content: center;
  border: 1px solid #d4d6d8;
  border-radius: 50px;

  // @media (max-width: 960px) {
  //   width: 80%;
  // }

  @media (max-width: 600px) {
    padding-top: 50px;
    border: none;
  }

  h2 {
    margin: 40px auto;
    font-size: 28px;
    font-weight: 500;
    line-height: 38px;
    letter-spacing: 2px;
  }
  section {
    height: 100%;
    padding: 30px;
    p {
      font-size: 18px;
      font-weight: 400;
      line-height: 32px;
      letter-spacing: 1px;
    }
  }

  .cover-img {
    width: 100%;
    height: 500px;
    object-fit: cover;
    @media (max-width: 600px) {
      height: auto;
    }
  }
}
.bg-img {
  height: 1000px;
  position: relative;
  z-index: -1;
  @media (max-width: 600px) {
    height: 650px;
  }
}

.back-link {
  display: block;
  text-align: center;
  transition: all 0.3s;
  letter-spacing: 1px;

  &:hover {
    opacity: 0.8;
  }
}
.material-img {
  position: absolute;

  &:first-child {
    top: -15vw;
  }

  &:last-child {
    bottom: -150px;
    z-index: -5;
    transform: scaleX(-1);

    @media (max-width: 600px) {
      bottom: -50px;
    }
  }
}
</style>
