<template>
  <view class="video-details main bg-base pb-5">
    <SimplePageContentLoader :loader="loader">
      <template v-if="loader.content.value">
        
        <video 
          v-if="loader.content.value.audio"
          class="video"
          autoplay
          :poster="loader.content.value.image"
          :src="loader.content.value.audio"
          controls
        />
        <video
          v-else-if="loader.content.value.video"
          class="video"
          autoplay
          :poster="loader.content.value.image"
          :src="loader.content.value.video"
          controls
        />
        <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">
          <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="content radius-l bg-light p-3">
            <u-parse :content="loader.content.value.content" :tagStyle="commonParserStyle"></u-parse>
          </view>
        </view>
        <ContentNote />
        <view class="bottom-actions">
          <view class="action">
            <text class="iconfont icon-like"></text>
            <text>{{ loader.content.value.likes }}</text>
          </view>
          <view class="action">
            <text class="iconfont icon-share"></text>
            <text>分享</text>
          </view>
        </view>
      </template>
    </SimplePageContentLoader>
  </view>
</template>

<script setup lang="ts">
import type { GetContentDetailItem } from "@/api/CommonContent";
import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
import NewsIndexContent from "@/api/news/NewsIndexContent";
import commonParserStyle from "@/common/style/commonParserStyle";
import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
import { DataDateUtils } from "@imengyu/js-request-transform";
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);
  uni.setNavigationBarTitle({ title: res.title });
  return res;
});

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

<style lang="scss">
.video-details {
  padding: 0;

  .nested-content {
    padding: 15rpx 25rpx;
  }
  video {
    width: 750rpx;
  }
  .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>
