<template>
  <view class="d-flex flex-col bg-base">
    <SimplePageContentLoader :loader="loader">
      <template v-if="loader.content.value">
        <view class="banner">
          <swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="2000" :duration="1000">
            <swiper-item v-for="(item, key) in loader.content.value.images" :key="key">
              <view 
                class="item"
                @click="onPreviewImage(key)"
              >
                <ImageWrapper 
                  :src="item"
                  mode="aspectFill"
                  width="750rpx"
                />
              </view>
            </swiper-item>
          </swiper>
        </view>
        <view class="d-flex flex-col p-3 bg-light">
          <view class="intro-block artifact-info">
            <HomeTitle :title="loader.content.value.title" />
            <view class="desc no-indent">
              <view v-if="loader.content.value.address" class="navigation">
                <view class="address">
                  <text class="iconfont icon-navigation"></text>
                  <text>{{ loader.content.value.address }}</text>
                </view>
                <view class="link" @click="handleNavTo">
                  去这里 <text class="iconfont icon-go"></text>
                </view>
              </view>
              <view v-if="loader.content.value.openStatusText" class="entry">
                <view class="label">开放时间：</view>
                <view class="value">{{ loader.content.value.openStatusText }}</view>
              </view>
              <view v-if="loader.content.value.age" class="entry">
                <view class="label">年代：</view>
                <view class="value">{{ loader.content.value.age }}</view>
              </view>
              <view class="entry">
                <view class="label">文物类型：</view>
                <view class="value">{{ loader.content.value.crTypeText }}</view>
              </view>
              <view class="entry">
                <view class="label">所属区域：</view>
                <view class="value">{{ loader.content.value.regionText }}</view>
              </view>
              <view class="entry">
                <view class="label">级别：</view>
                <view class="value">{{ loader.content.value.levelText }}</view>
              </view>
              <view v-if="loader.content.value.protectedArea" class="entry">
                <view class="label">保护范围：</view>
                <view class="value">
                </view>
              </view>
              <u-parse :content="loader.content.value.protectedArea" :tagStyle="commonParserStyle"></u-parse>
            </view>
          </view>
          <view class="intro-block">
            <view class="title">
              <view class="line"></view>
              <text class="sm">简介</text>
            </view>
            <view class="desc">
              <u-parse :content="loader.content.value.intro" :tagStyle="commonParserStyle"></u-parse>
            </view>
            <view class="desc">
              <u-parse :content="loader.content.value.value" :tagStyle="commonParserStyle"></u-parse>
            </view>
          </view>
          <ContentNote />
          <!-- <HomeTitle title="更多人气好去处" />
          <view class="rec-list">
            <swiper class="swiper" :autoplay="false" :circular="false" :duration="500" :next-margin="'145rpx'">
              <swiper-item v-for="item in loader.content.value.associationMeList" :key="item.id" @click="goDetails(item)">
                <view class="item">
                  <image :src="item.image" mode="aspectFill"></image>
                  <view class="name">
                    <text>{{ item.title }}</text>
                  </view>
                </view>
              </swiper-item>
            </swiper>
          </view> -->
        </view>
      </template>
    </SimplePageContentLoader>
  </view>
</template>
<script setup lang="ts">
import type { GetContentDetailItem } from "@/api/CommonContent";
import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
import { onLoad } from "@dcloudio/uni-app";
import { navTo } from "@/common/utils/PageAction";
import UnmoveableContent from "@/api/inheritor/UnmoveableContent";
import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
import ImageWrapper from "@/common/components/ImageWrapper.vue";
import HomeTitle from "@/pages/parts/HomeTitle.vue";
import commonParserStyle from "@/common/style/commonParserStyle";
import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
import { useSwiperImagePreview } from "@/common/composeabe/SwiperImagePreview";
import ContentNote from "@/pages/parts/ContentNote.vue";

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

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

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

function handleNavTo() {
  navTo('../../travel/nav/navto', {
    latitude: loader.content.value?.latitude,  
    longitude: loader.content.value?.longitude,  
  }) 
}
function goDetails(item: any) {
  navTo('./details', { id: item.id })
}
</script>

<style lang="scss" scoped>
.rec-list {
  swiper {
    height: 300rpx;
  }

  .item {
    width: 514rpx;
    height: 300rpx;
    position: relative;
    border-radius: 20rpx;
    overflow: hidden;
    background-color: #eaeaea;

    image {
      width: 100%;
      height: 100%;
    }

    .name {
      position: absolute;
      bottom: 34rpx;
      right: 22rpx;
      color: #fff;
      font-weight: 600;
      font-size: 28rpx;
    }
  }
}

.intro-block {
  margin-bottom: 38rpx;
  .title{
    .sm{
      font-size: 30rpx;
    }
  }
  &.artifact-info{
    .desc{
      line-height: inherit;
      padding-bottom: 10rpx;
    }
  }
  .entry {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin-bottom: 10rpx;

    .label {
      color: #666666;
      font-weight: 400;
      font-size: 28rpx;
    }
    .value {
      font-size: 28rpx;
      color: #312520;
      font-weight: 400;
    }
  }
  .sub-title{
    margin-left: 20rpx;
    margin-top: 10rpx;
    font-size: 30rpx;
    font-weight: 600;
  }
  .desc{
    padding:30rpx;
  }
  .navigation{
    display: flex;
    align-items: center;
    margin-bottom: 28rpx;
    .address{
      flex:1;
      height: auto;
      background: #F9F6EB;
      border-radius: 28rpx;
      font-weight: 400;
      font-size: 24rpx;
      color: #000000;
      line-height: 48rpx;
      padding-left: 30rpx;
      display: flex;
      align-items: center;
      text.iconfont{
        display: inline-block;
        font-size: 36rpx;
        margin-right: 8rpx;
      }
    }
    .link{
      margin-left: 20rpx;
      color:#FF8719;
    }
  }
}
.banner {
  margin-top: 0;
  .swiper {
    border-radius: 0;
    height: 504rpx;
  }
}

</style>
