//
//  MPPositive_SearchResultItemViewModel.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/13.
//

import UIKit
import Kingfisher
class MPPositive_SearchResultItemViewModel: NSObject {
    ///预览图路径
    var reviewUrl:URL?
    ///标题
    var title:String?
    ///副标题
    var subtitle:String?
    ///搜索结果个体
    var item:MPPositive_BrowseItemModel!
    init(_ resultItem:MPPositive_BrowseItemModel) {
        super.init()
        item = resultItem
        configure()
    }
    private func configure() {
        if let url = URL(string: item.coverUrls?.last ?? "") {
            reviewUrl = url
        }
        if item.title != nil {
            title = item.title
        }
        if item.subtitle != nil {
            subtitle = item.subtitle
        }
    }
    //设置预览图
    func setImage(_ imageView:UIImageView) {
        if reviewUrl != nil {
            imageView.kf.setImage(with: reviewUrl, placeholder: placeholderImage)
        }
        if item.itemType == .artist {
            imageView.layer.cornerRadius = 30*width
        }else {
            imageView.layer.cornerRadius = 10*width
        }
    }
}
