//
//  PQRecommVideoModel.swift
//  PQSpeed
//
//  Created by SanW on 2020/5/26.
//  Copyright © 2020 BytesFlow. All rights reserved.
//

import BFCommonKit
import UIKit

public protocol BFVideoItemProtocol {
    dynamic var uniqueId: String? { get set } // 唯一ID
    dynamic var videoId: Int { get set } // 视频ID
    dynamic var id: UInt64 { get set } // 视频ID
    dynamic var eventId: String? { get set } // 事件ID
    dynamic var title: String? { get set } // 标题
    dynamic var attributedTitle: NSMutableAttributedString? { get set } // 富文本标题
    dynamic var summary: String? { get set } // 描述
    dynamic var imageUrl: String { get set } // 图片地址
    dynamic var selectedImage: String { get set } // 图片地址
    dynamic var isSelected: Bool { get set }
    dynamic var recommendLogVO: String? { get set } // 推荐日志对象
    dynamic var flowPool: String? { get set } // 流量池数据 eg：#1#12#5#169182931029
    dynamic var abInfoData: String? { get set } // AB
    dynamic var pageCategoryId: Int { get set } // 页面分类ID
    dynamic var version: String { get set } // 版本号
    dynamic var mid: String { get set } // 设备ID
    dynamic var date: Int { get set } // 当前时间戳  Float64(Date.init().timeIntervalSince1970) * 1000
    var headVideoId: String? { get set } // 当前的相关推荐视频是属于哪个视频的相关推荐，值为那个头部视频的videoId
    var auditStatus: Int { get set } // 审核状态 1 审核中，2 不通过 3 待修改，4 自己可见 5 通过 ,
    var barrageCount: Int { get set } // 弹幕数量
    var barrageSwitch: Int { get set } // 是否打开弹幕 1打开 -1关闭 ,
    var auditReason: String? { get set } // 审核不通过或者待修改的原因
    var barrage: Any? { get set } // 弹幕集合
    var chargeDetail: [String: Any]? { get set } // 收费的相关信息
    var commentCount: Int { get set } // 评论数量
    var coverImg: [String: Any]? { get set } // 封面对象 ,
    var cutVoStr: String? { get set } // h5剪切板内容 ,
    var descr: String? { get set } // 视频简介 ,
    var encryption: Int { get set } // 是否加密视频：0是1不是 ,
    var favorited: Bool { get set } // 是否收藏 ,
    var favoriteds: Int { get set } //  收藏数 ,
    var fileExtensions: String? { get set } // 视频后缀 ,
    var firstPicture: Bool { get set } // 封面是否是第一帧，false不是true是 ,
    var gmtCreate: String? { get set } // 创建时间 ,
    var gmtCreateDescr: String? { get set } // 发视频时间描述 ,
    var gmtCreateTimestamp: Int { get set } // 创建时间戳 ,
    var gmtModifie: String? { get set } // 修改时间 ,
    var gmtModifiedTimestamp: Int { get set } // 修改时间戳 ,
    var h5ShareImgPath: String? { get set } // h5分享图URL ,
    var hasShareSpaceData: Bool { get set } // 是否有分享空间数据,
    var isRecommendShare: Int { get set } // 是否有分发推荐的封面和标题 1 有 0 无 传空或者不传默认为0,
    var lastTimestamp: Int { get set } // 时间戳 ,
    //  liteVideoData (LiteVideoDataVO, optional): lite数据,
    var measure: Int { get set }
    var measureId: Int { get set }
    var measureType: Int { get set } // 0 非流量池 1曝光池2普通推荐测试池3待推荐测试池 ,
    var playBeforeDay: Int { get set } // 播放时间距离今天的天数 ,
    var playCount: Int { get set } // 播放次数 ,
    var playCountFormatStr: String? { get set } //  用户视频总播放数,格式化后的值，前端直接显示 ,
    var playCountTotal: Int { get set } // 总播放次数 ,
    var playTime: Int { get set } // 播放时间 ,
    var processShareHeadLab: [String: Any]? { get set } // 视频分享片尾数据 ,
    var processShareTailLab: [String: Any]? { get set } // 视频分享片尾数据 ,
    var pwd: String? { get set } // 视频密码 ,
    var recommendId: String? { get set } // 推荐链路ID ,
    var recommendSource: Int { get set } // 0 默认 1 第四范式
    var recommendStatus: Int { get set } // 推荐状态 ,
    var rotate: Int { get set } // 旋转角度 ,
    var sampleJobId: String? { get set }
    var sampleRequestId: String? { get set }
    var sampleTotalTime: Int { get set }
    var sampleTranscodeStatus: Int { get set }
    var sampleTransedVideoPath: String? { get set }
    var sendBeforeDay: Int { get set } // 发视频距离今天的天数 ,
    var sensitiveMsg: String? { get set } // 敏感提示信息 ,
    var sensitiveStatus: Int { get set } //  内容敏感状态（0：未检验，1：不敏感，2：敏感，3：敏感已审） ,
    var shareCount: Int { get set } // 分享到朋友圈次数 ,
    var shareId: String? { get set } // 分享的 ID
    var shareCountFriend: Int { get set } // 分享到微信好友 ,
    var shareImgPath: String? { get set } // 分享图URL ,
    var shareLinkType: Int { get set } // 分享到微信好友的图片的链接的类型 ,
    var sharePageType: Int { get set } // 0 综合模块 1 feed流 ,
    var shareTitle: String? { get set } // 分享到微信好友的图片的title ,
    var showHotRecommend: Bool { get set } // 是否需要显示热门推荐 ,
    var size: Int { get set } //  大小 ,
    var status: Int { get set } // 数据状态，1 有效，2 已删除，3 已屏蔽,4 关注可见，5 分享可见 6 自己可见 ,
    var tabShareImgPath: String? { get set } // 转发分享图URL ,
    var thumbnailImagePath: String? { get set } // 缩略图URL ,
    var totalTime: Int { get set } // 视频时长 ,
    var totalTimeParas: String? { get set } // 视频时长十分秒 ,
    var transcodeStatus: Int { get set } // 转码状态:1-不需转码 2-转码中 3-转码完成 4-转码失败 ,
    var transcodeVOList: [Any]? { get set } // 多码率数据 ,
    var uid: Int { get set } // 视频的用户ID ,
    var user: [String: Any]? { get set } //  用户对象 ,
    var videoCollectionId: Int { get set } // 视频所在的视频集ID ,
    var videoCoverSnapshotPath: String? { get set } // 原始封面图片 ,
    var videoPath: String? { get set } // 视频地址 ,
    var videoReportMeta: String? { get set } // 视频上报数据，上报时原样返回 ,
    var videoShareJumpModel: [String: Any]? { get set } // 分享页跳转的信息 ,
    var playProgress: Float64 { get set } // 已播放时长
    var duration: Float64 { get set } // 视频总时长
    var tab_pageType: TAB_PAGETYPE { get set } // 0-推荐 1-关注
    var pageSource: PAGESOURCE { get set }
    var isVerticality: Bool { get set }
    var isShareList: Bool { get set } // 是否是分享列表
    var uplpadBucketKey: String? { get set } // 上传视频地址
    var uplpadStatus: Int { get set } // 上传视频状态  1-上传中 2-上传完成 3-上传失败 4-发布中 4-发布完成
    var uplpadRequest: OSSMultipartUploadRequest? { get set }
    var stsToken: [String: Any]? { get set } // 上传信息
    var localPath: String? { get set } // 地址
    var progress: Float { get set }
    var projectId: String? { get set } // 项目ID-发布创作的视频时必传，会在进入创作工具页时生成，以app_no_projectdata为前缀
    var autoType: autoType? { get set } // autoType 自动动作的类型
    // 发布视频来源类型
    var videoFromScene: videoFromScene { get set }
    // extParams: 额外参数-传入发布页 - 主要中秋红包塞活动使用
    var extParams:String { get set }
    // 话题信息
    var topicData: [String: Any]? { get set }
}

open class PQVideoListModel: PQBaseModel, BFVideoItemProtocol {
    @objc public required init() {
        super.init()
    }

    public var id: UInt64 = 0
    public var headVideoId: String? // 当前的相关推荐视频是属于哪个视频的相关推荐，值为那个头部视频的videoId
    public var auditStatus: Int = 0 // 审核状态 1 审核中，2 不通过 3 待修改，4 自己可见 5 通过 ,
    public var barrageCount: Int = 0 // 弹幕数量
    public var barrageSwitch: Int = 0 // 是否打开弹幕 1打开 -1关闭 ,
    public var auditReason: String? // 审核不通过或者待修改的原因
    public var barrage: Any? // 弹幕集合
    public var chargeDetail: [String: Any]? // 收费的相关信息
    public var commentCount: Int = 0 // 评论数量
    public var coverImg: [String: Any]? // 封面对象 ,
    public var cutVoStr: String? // h5剪切板内容 ,
    public var descr: String? // 视频简介 ,
    public var encryption: Int = 0 // 是否加密视频：0是1不是 ,
    public var favorited: Bool = false // 是否收藏 ,
    public var favoriteds: Int = 0 //  收藏数 ,
    public var fileExtensions: String? // 视频后缀 ,
    public var firstPicture: Bool = false // 封面是否是第一帧，false不是true是 ,
    public var gmtCreate: String? // 创建时间 ,
    public var gmtCreateDescr: String? // 发视频时间描述 ,
    public var gmtCreateTimestamp: Int = 0 // 创建时间戳 ,
    public var gmtModifie: String? // 修改时间 ,
    public var gmtModifiedTimestamp: Int = 0 // 修改时间戳 ,
    public var h5ShareImgPath: String? // h5分享图URL ,
    public var hasShareSpaceData: Bool = false // 是否有分享空间数据,
    public var height: CGFloat = 0 // 视频高 ,
    public var isRecommendShare: Int = 0 // 是否有分发推荐的封面和标题 1 有 0 无 传空或者不传默认为0,
    public var lastTimestamp: Int = 0 // 时间戳 ,
    //  liteVideoData (LiteVideoDataVO, optional): lite数据,
    public var measure: Int = 0
    public var measureId: Int = 0
    public var measureType: Int = 0 // 0 非流量池 1曝光池2普通推荐测试池3待推荐测试池 ,
    public var playBeforeDay: Int = 0 // 播放时间距离今天的天数 ,
    public var playCount: Int = 0 // 播放次数 ,
    public var playCountFormatStr: String? //  用户视频总播放数,格式化后的值，前端直接显示 ,
    public var playCountTotal: Int = 0 // 总播放次数 ,
    public var playTime: Int = 0 // 播放时间 ,
    public var processShareHeadLab: [String: Any]? // 视频分享片尾数据 ,
    public var processShareTailLab: [String: Any]? // 视频分享片尾数据 ,
    public var pwd: String? // 视频密码 ,
    public var recommendId: String? // 推荐链路ID ,
    public var recommendSource: Int = 0 // 0 默认 1 第四范式
    public var flowPool: String?
    public var recommendStatus: Int = 0 // 推荐状态 ,
    public var rotate: Int = 0 // 旋转角度 ,
    public var sampleJobId: String?
    public var sampleRequestId: String?
    public var sampleTotalTime: Int = 0
    public var sampleTranscodeStatus: Int = 0
    public var sampleTransedVideoPath: String?
    public var sendBeforeDay: Int = 0 // 发视频距离今天的天数 ,
    public var sensitiveMsg: String? // 敏感提示信息 ,
    public var sensitiveStatus: Int = 0 //  内容敏感状态（0：未检验，1：不敏感，2：敏感，3：敏感已审） ,
    public var shareCount: Int = 0 // 分享到朋友圈次数 ,
    // add by ak 个人中心里我分享的视频列表返回的参数 e.g. 78C10B44-6892-42A8-AE69-F1B35F9E676F-534530
    public var shareId: String? // 分享的 ID
    public var shareCountFriend: Int = 0 // 分享到微信好友 ,
    public var shareImgPath: String? // 分享图URL ,
    public var shareLinkType: Int = 0 // 分享到微信好友的图片的链接的类型 ,
    public var sharePageType: Int = 0 // 0 综合模块 1 feed流 ,
    public var shareTitle: String? // 分享到微信好友的图片的title ,
    public var showHotRecommend: Bool = false // 是否需要显示热门推荐 ,
    public var size: Int = 0 //  大小 ,
    public var status: Int = 0 // 数据状态，1 有效，2 已删除，3 已屏蔽,4 关注可见，5 分享可见 6 自己可见 ,
    public var tabShareImgPath: String? // 转发分享图URL ,
    public var thumbnailImagePath: String? // 缩略图URL ,
    public var totalTime: Int = 0 // 视频时长 ,
    public var totalTimeParas: String? // 视频时长十分秒 ,
    public var transcodeStatus: Int = 0 // 转码状态:1-不需转码 2-转码中 3-转码完成 4-转码失败 ,
    public var transcodeVOList: [Any]? // 多码率数据 ,
    public var uid: Int = 0 // 视频的用户ID ,
    public var user: [String: Any]? //  用户对象 ,
    public var userInfo: PQUserInfoModel? //  用户对象 ,
    public var videoCollectionId: Int = 0 // 视频所在的视频集ID ,
    public var videoCoverSnapshotPath: String? // 原始封面图片 ,
    public var videoPath: String? // 视频地址 ,
    public var videoURL: String? // 视频地址 ,
    public var videoReportMeta: String? // 视频上报数据，上报时原样返回 ,
    public var videoShareJumpModel: [String: Any]? // 分享页跳转的信息 ,
    public var width: CGFloat = 0 // 视频宽
    public var itemHeight: CGFloat = 0 // 个人中心cell高
    public var originImageH: CGFloat = 0 // 原始图片的宽
    public var originImageW: CGFloat = 0 // 原始图片的高
    public var imageH: CGFloat = 0 // 图片的高
    public var imageW: CGFloat = 0 // 图片的宽
    public var titleH: CGFloat = 0 // 标题的高
    public var descH: CGFloat = 0 // 描述的高
    public var titleFontSize: CGFloat = 0 // add by ak 标题字号
    public var usnameW: CGFloat = 0 // add by ak 用户名宽度
    public var rotationH: CGFloat = 0 // add by ak 三个推荐视频高度包括标题
    public var watchInfoH: CGFloat = 0 // add by ak watch info 高度
    public var watchInfoY: CGFloat = 0 // add by ak watch info Y 值
    public var relationData: [PQVideoListModel]?
    public var playProgress: Float64 = 0 // 已播放时长
    public var duration: Float64 = 0 // 视频总时长
    public var tab_pageType: TAB_PAGETYPE = .TAB_PAGETYPE_NORMAL // 0-推荐 1-关注
    public var pageSource: PAGESOURCE = .sp_category
    public var isVerticality: Bool = false
    public var isShareList: Bool = false // 是否是分享列表

    public var funcH: CGFloat = cDefaultMargin * 33
    public var funcW: CGFloat = cDefaultMargin * 5
    public var uplpadImage: UIImage? // 上传的图片封面
    public var uplpadBucketKey: String? // 上传视频地址
    public var uplpadStatus: Int = 0 // 上传视频状态  1-上传中 2-上传完成 3-上传失败 4-发布中 4-发布完成
    public var uplpadRequest: OSSMultipartUploadRequest?
    public var stsToken: [String: Any]? // 上传信息
    public var localPath: String? // 地址
    public var progress: Float = 0
    public var projectId: String? // 项目ID-发布创作的视频时必传，会在进入创作工具页时生成，以app_no_projectdata为前缀
    public var reCreateVideoData: PQReCreateModel? // 再创作数据
    // 视频创作埋点数据
    public var eventTrackData: PQVideoMakeEventTrackModel?
    public var autoType: autoType? // autoType 自动动作的类型
    // add by ak 发布视频来源类型
    public var videoFromScene: videoFromScene = .UploadNormal
    // extParams: 额外参数-传入发布页 - 主要中秋红包塞活动使用
    public var extParams:String = ""
    // 视频分类
    public var categoryName: String = ""
    // 视频分类图
    public var categoryImage: String?
    // 话题信息
    public var topicData: [String: Any]?

    override public init(jsonDict: [String: Any]) {
        super.init(jsonDict: jsonDict)
        if jsonDict.keys.contains("id") {
            id = UInt64("\(jsonDict["id"] ?? "")") ?? 0
        }
        if jsonDict.keys.contains("videoPath") {
            videoPath = "\(jsonDict["videoPath"] ?? "")"
            videoURL = videoPath
            if videoPath?.contains(".m3u8") ?? false {
                videoURL = videoPath?.components(separatedBy: "?").first
            }
        }
        if jsonDict.keys.contains("videoCoverSnapshotPath") {
            videoCoverSnapshotPath = "\(jsonDict["videoCoverSnapshotPath"] ?? "")"
            if (videoCoverSnapshotPath?.count ?? 0) > 0, !(videoCoverSnapshotPath?.contains("http") ?? false) {
                videoCoverSnapshotPath = "https://rescdn.yishihui.com/" + videoCoverSnapshotPath!
            }
        }
        if jsonDict.keys.contains("thumbnailImagePath") {
            thumbnailImagePath = "\(jsonDict["thumbnailImagePath"] ?? "")"
        }
        if jsonDict.keys.contains("rotate") {
            rotate = Int("\(jsonDict["rotate"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("descr") {
            descr = "\(jsonDict["descr"] ?? "")"
            if descr != nil, (descr?.count ?? 0) > 2, descr?.hasSuffix("\n") ?? false {
                descr = String(descr?.prefix((descr?.count ?? 2) - 2) ?? "")
            }
        }
        if jsonDict.keys.contains("favorited") {
            favorited = jsonDict["favorited"] as! Bool
        }
        if jsonDict.keys.contains("firstPicture") {
            firstPicture = jsonDict["firstPicture"] as! Bool
        }
        if jsonDict.keys.contains("shareImgPath") {
            shareImgPath = "\(jsonDict["shareImgPath"] ?? "")"
        }
        if jsonDict.keys.contains("coverImg") {
            coverImg = jsonDict["coverImg"] as? [String: Any]
        }
        if jsonDict.keys.contains("user") {
            user = jsonDict["user"] as? [String: Any]
            userInfo = PQUserInfoModel(jsonDict: user!)
        }
        if jsonDict.keys.contains("topicData") {
            topicData = jsonDict["topicData"] as? [String: Any]
        }
        if jsonDict.keys.contains("topicInfo") {
            topicData = jsonDict["topicInfo"] as? [String: Any]
        }
        if jsonDict.keys.contains("shareCountFriend") {
            shareCountFriend = Int("\(jsonDict["shareCountFriend"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("shareId") {
            shareId = "\(jsonDict["shareId"] ?? "")"
        }
        if jsonDict.keys.contains("shareCount") {
            shareCount = Int("\(jsonDict["shareCount"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("favoriteds") {
            favoriteds = Int("\(jsonDict["favoriteds"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("uid") {
            uid = Int("\(jsonDict["uid"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("lastTimestamp") {
            lastTimestamp = Int("\(jsonDict["lastTimestamp"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("auditStatus") {
            auditStatus = Int("\(jsonDict["auditStatus"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("status") {
            status = Int("\(jsonDict["status"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("auditReason") {
            auditReason = "\(jsonDict["auditReason"] ?? "")"
        }
        if jsonDict.keys.contains("transcodeStatus") {
            transcodeStatus = Int("\(jsonDict["transcodeStatus"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("playCountTotal") {
            playCountTotal = Int("\(jsonDict["playCountTotal"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("measure") {
            measure = Int("\(jsonDict["measure"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("measureId") {
            measureId = Int("\(jsonDict["measureId"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("measureType") {
            measureType = Int("\(jsonDict["measureType"] ?? "0")") ?? 0
        }
        if jsonDict.keys.contains("playCountFormatStr") {
            playCountFormatStr = "\(jsonDict["playCountFormatStr"] ?? "")"
        }
        if jsonDict.keys.contains("recommendId") {
            recommendId = "\(jsonDict["recommendId"] ?? "")"
        }
        if jsonDict.keys.contains("abInfoData") {
            abInfoData = "\(jsonDict["abInfoData"] ?? "")"
        }
        if jsonDict.keys.contains("flowPool") {
            flowPool = "\(jsonDict["flowPool"] ?? "")"
        }
        if jsonDict.keys.contains("totalTime") {
            totalTime = Int("\(jsonDict["totalTime"] ?? "0")") ?? 0
            totalTimeParas = Float64(totalTime).formatDurationToHMS()
        }
        if jsonDict.keys.contains("width") {
            width = CGFloat(Float("\(jsonDict["width"] ?? 0)") ?? 0)
            if rotate > 0 {
                originImageH = width
            } else {
                originImageW = width
            }
        }
        if jsonDict.keys.contains("height") {
            height = CGFloat(Float("\(jsonDict["height"] ?? 0)") ?? 0)
            if rotate > 0 {
                originImageW = height
            } else {
                originImageH = height
            }
        }
        if jsonDict.keys.contains("produceProjectDataV2"), ((jsonDict["produceProjectDataV2"] as? [String: Any])?.keys.count ?? 0) > 0 {
            reCreateVideoData = PQReCreateModel(jsonDict: jsonDict["produceProjectDataV2"] as! [String: Any])
            if reCreateVideoData?.canReproduce == 1 {
                funcH = funcH + cDefaultMargin * 7
            }
            reCreateVideoData?.videoId = uniqueId
        }
        if coverImg != nil, coverImg?.count ?? 0 > 0 {
            imageW = cScreenWidth
            imageH = imageW * originImageH / originImageW
            isVerticality = originImageH > originImageW
            if imageH > cScreenHeigth {
                imageH = cScreenHeigth
                imageW = imageH * originImageW / originImageH
            }
        }
        // 计算个人中心高度
        var tempTitleH: CGFloat = -cDefaultMargin
        if title != nil, (title?.count ?? 0) > 0 {
            tempTitleH = sizeWithText(text: title ?? "", font: UIFont.systemFont(ofSize: 16), size: CGSize(width: (cScreenWidth - cDefaultMargin * 3) / 2, height: cDefaultMargin * 4)).height
        }
        itemHeight = (cScreenWidth - cDefaultMargin * 3) / 2 * originImageH / originImageW + tempTitleH + cDefaultMargin * 4.5

        if title != nil, (title?.count ?? 0) > 0 {
            titleH = sizeWithText(text: title ?? "", font: UIFont.systemFont(ofSize: 26, weight: .medium), size: CGSize(width: cScreenWidth - cDefaultMargin * 2, height: CGFloat.greatestFiniteMagnitude)).height + cDefaultMargin
        }
        if titleH > 70 {
            titleH = 70
            titleFontSize = cScreenWidth <= 320 ? 19 : 21
        } else {
            titleFontSize = 25
        }

        BFLog(message: "title \(String(describing: title))   titleH :\(titleH)  titleFontSize :\(titleFontSize)")

        var isFollowed: Bool = false

        if tab_pageType == .TAB_PAGETYPE_RECOMM {
            isFollowed = userInfo?.followed != 1
        } else {
            isFollowed = true
        }

        let attM: CGFloat = cDefaultMargin * 4.5
        usnameW = sizeWithText(text: userInfo?.nickName ?? "", font: UIFont.systemFont(ofSize: 16, weight: .medium), size: CGSize(width: !isFollowed ? (cScreenWidth - cDefaultMargin * 8) : (cScreenWidth - cDefaultMargin * 9 - attM), height: cDefaultMargin * 2)).width + cDefaultMargin * 2

        BFLog(message: "nickname is \(userInfo?.nickName ?? "") '    'usnameW is \(usnameW) isFollowed is \(isFollowed)")

        updateReommendAgent()

        watchInfoY = -cDefaultMargin

        BFLog(message: "watchInfoY11111 is \(watchInfoY)")
    }

    public func updateReommendAgent() {
        // 计算相关推荐高度
        var itemH: CGFloat = 0
        var verticality: Bool = false
        var haveTitle: Bool = false
        if (relationData?.count ?? 0) > 0 {
            for item in (relationData)! {
                if item.imageH > item.imageW {
                    verticality = true
                    break
                }
                BFLog(message: "item.title  \(String(describing: item.title))")
                if item.title != nil, (item.title?.count ?? 0) > 0 {
                    haveTitle = true
                    break
                }
            }
        }
        itemH = verticality ? 130 : (haveTitle ? 90 : 55)
        itemH = (relationData?.count ?? 0) > 0 ? itemH : 0

        BFLog(message: "itemH is： \(itemH) sss \(String(describing: relationData?.count))")

        rotationH = itemH
        // 描述部分
        if (relationData?.count ?? 0) > 0, tab_pageType != .TAB_PAGETYPE_ATTEN {
            watchInfoY = (isVerticality ? -cDefaultMargin : -(cDefaultMargin * 2 + rotationH))
        } else {
            watchInfoY = -cDefaultMargin
        }

        BFLog(message: "watchInfoY2222 is \(watchInfoY)")

        let nomalH: CGFloat = cDefaultMargin * 1.5
//        let likeH: CGFloat = favoriteds <= 0 ? 0 : nomalH
        let likeH: CGFloat = 0
        watchInfoH = cDefaultMargin * 2 + nomalH + likeH + cDefaultMargin
        if reCreateVideoData != nil, reCreateVideoData?.canReproduce == 1 {
            watchInfoH = watchInfoH + ((reCreateVideoData?.rhythmMusicFlag != 1 && (reCreateVideoData?.parentVideoId != nil)) ? cDefaultMargin * 8 : 43)
        }
        if descr != nil, !(descr?.isEmpty ?? true) {
            if Thread.isMainThread {
                descH = sizeTextFits(attributedText: NSMutableAttributedString(string: descr ?? ""), text: nil, numberOfLines: 5, font: UIFont.systemFont(ofSize: 14), maxSize: CGSize(width: cScreenWidth - funcW - cDefaultMargin * 3, height: CGFloat.greatestFiniteMagnitude)).height
                watchInfoH = watchInfoH + descH
            } else {
                DispatchQueue.main.async { [weak self] in
                    self?.descH = sizeTextFits(attributedText: NSMutableAttributedString(string: (self?.descr)!), text: nil, numberOfLines: 5, font: UIFont.systemFont(ofSize: 14), maxSize: CGSize(width: cScreenWidth - (self?.funcW ?? 0) - cDefaultMargin * 3, height: CGFloat.greatestFiniteMagnitude)).height
                    self?.watchInfoH = (self?.watchInfoH ?? 0) + (self?.descH ?? 0)
                }
            }
        }
    }
}
