/**书架中书籍的box容器横小 */

import { Text, View, Image, Button, Navigator } from "@tarojs/components";
import React from 'react'
import './index.less'
import Taro from "@tarojs/taro";
import useApi from "@src/Hook/useApi";
let { getBookInfo } = useApi()
export interface BookboxRowSmallProps {
    bookInfo: {
        bookId: number,//书ID
        authorName: string,//作者
        bookName: string,//书名称
        bookDesc: string,//描述
        picUrl: string,//封面
        bookStatus: number,//完本|连载状态
        wordCount: number,//字数
        labelInfoList: { name: string }[],//标签
        readLogId: string,//上次阅读的记录
        vipFree: boolean
    }
    lastReadingTime: string,//最近阅读时间
}
function BookboxRowSmall(props: BookboxRowSmallProps) {
    const { lastReadingTime, bookInfo } = props
    const { bookName, picUrl, authorName, bookId, readLogId, vipFree } = bookInfo
  const click = () => {
          getBookInfo(bookId).then((res: { data: any, code: any }) => {
              if (res?.data?.code == 200) {
                  console.log(res?.data?.data)
                  let { wechatBookId, inBookshelf } = res?.data?.data
                  let json = JSON.stringify({ inBookshelf, bookId })
                  let encode = encodeURIComponent(json)
                  if (wechatBookId) {
                      Taro.navigateTo({
                          url: `plugin-private://wx293c4b6097a8a4d0/pages/novel/index?bookId=${wechatBookId}&customServerParams=${encode}`
                      })
                  } else {
                      Taro.showToast({
                          title: '小说未上架',
                          icon: 'none'
                      })
                  }
              }
          })
      }
    return <View className='book_box_row_small' onClick={click} style={{ margin: 0 }}>
        <Image src={picUrl} className={`img ${vipFree ? "isVip" : ""}`}></Image>
        <View className='right'>
            <Text className='title'>{bookName}</Text>
            <View className='content'>
                <View className='left'>
                    <Text className='author'>{authorName}</Text>
                </View>
            </View>
        </View>
    </View>
}
export default React.memo(BookboxRowSmall)