<template>
  <view class="d-flex flex-column bg-base pb-45">
    <SimplePageContentLoader :loader="loader">
      <template v-if="loader.content.value">
        <view class="d-flex flex-col">
          <swiper 
            v-if="loader.content.value.images.length > 0"
            circular 
            :indicator-dots="true"
            :autoplay="true"
            :interval="3000"
            :duration="1000"
            class="height-500"
          >
            <swiper-item v-for="(item, key) in loader.content.value.images" :key="key">
              <view class="item">
                <image 
                  :src="item" 
                  class="w-100 height-500 radius-base"
                  mode="aspectFill" 
                  @click="onPreviewImage(key)"
                />
              </view>
            </swiper-item>
          </swiper>
          <image 
            v-else-if="loader.content.value.image"
            class="w-100 radius-base"
            :src="loader.content.value.image"
            mode="widthFix"
          />
          <view class="d-flex flex-col p-3">
            <view class="size-ll color-title-text">{{ loader.content.value.title }}</view>
            <view class="d-flex flex-row mt-2">
              <text class="size-s color-text-content-second">{{ loader.content.value.author }}</text>
              <text class="size-s color-text-content-second">{{ DataDateUtils.formatDate(loader.content.value.publishAt, 'YYYY-MM-dd HH:ii:ss') }}</text>
            </view>
          </view>
          <view class="p-3 radius-ll bg-light mt-3">
            <u-parse 
              v-if="loader.content.value.content"
              :content="loader.content.value.content"
              :tagStyle="commonParserStyle"
            ></u-parse>
          </view>

          <ContentNote />
        </view>
        <view class="bottom-actions">
          <view class="action">
            <text class="iconfont icon-read"></text>
            {{ loader.content.value.views }}
          </view>
          <view class="action">
            <text class="iconfont icon-like" v-if="!loader.content.value.isLike"></text>
            <text class="iconfont icon-liked" v-else></text>
            {{ loader.content.value.likes }}
          </view>
        </view>
      </template>
    </SimplePageContentLoader>
  </view>
</template>

<script setup lang="ts">
import type { GetContentDetailItem } from "@/api/CommonContent";
import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
import { DataDateUtils } from "@imengyu/js-request-transform";
import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
import NewsIndexContent from "@/api/news/NewsIndexContent";
import commonParserStyle from "@/common/style/commonParserStyle";
import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
import { useSwiperImagePreview } from "@/common/composeabe/SwiperImagePreview";
import ContentNote from "../parts/ContentNote.vue";

const loader = useSimplePageContentLoader<
  GetContentDetailItem, 
  { id: number }
>(async (params) => {
  if (!params)
    throw new Error("!params");
  const res = await NewsIndexContent.getContentDetail(params.id);
  //console.log(res);
  uni.setNavigationBarTitle({ title: res.title });
  return res;
});

const { onPreviewImage } = useSwiperImagePreview(() => loader.content.value?.images || [])

useLoadQuerys({ id : 0, }, (p) => loader.loadData(p));
</script>

<style lang="scss" scoped>
.bottom-actions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 100%;
  height: 75rpx;
  background: #FFFFFF;

  .action {
    margin-left: 48rpx;
    font-weight: 800;
    font-size: 24rpx;
    color: #191919;
    display: flex;
    align-items: center;

    &:last-child {
      margin-right: 70rpx;
    }

    .iconfont {
      font-size: 30rpx;
      margin-right: 14rpx;
    }

    .iconfont.icon-liked {
      color: #FF8719;
    }
  }
}
</style>
