<template>
  <view class="d-flex flex-column bg-base">
    <SimplePageContentLoader :loader="loader">
      <template v-if="loader.content.value">
        <view class="d-flex flex-col">
          <image 
            v-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 :content="loader.content.value.content" :tagStyle="commonParserStyle"></u-parse>
          </view>
        </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";

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

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>
