//
//  BlogDetailsVC.swift
//  WOKA
//
//  Created by Bilal on 14/06/2024.
//

import UIKit

class BlogDetailsVC: UIViewController {

    @IBOutlet weak var blogImage: UIImageView!
    @IBOutlet weak var blogTitle: UILabel!
    @IBOutlet weak var blogDescription: UITextView!
    
    var blogData : BlogDM.Blog?

    override func viewDidLoad() {
        super.viewDidLoad()
        updateUI()
    }

    @IBAction func clostBtnTapped(_ sender: UIButton) {
        PersistentStorage.shared.addOthersCount()
        self.dismiss(animated: true)
    }
    
    func updateUI(){
        blogImage.roundCorner(radius: 10)
        guard let data = blogData else{return}
        if let url = data.thumbnailPath{
            self.blogImage.imageURL(url)
        }
        
        if AuthFunc.shareInstance.getDefaultLanguage() == .english{ // 1 enlgish , 2 hindi
            guard let languageData = data.contentMoreDetails?.filter({$0.languageMasterID == 1}).first else{return}
            self.blogTitle.text = languageData.title
            
            if let desc = languageData.article?.htmlToAttributedString{
                let sizeText = NSMutableAttributedString(attributedString: desc)
                sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Medium, size: 16))
                self.blogDescription.attributedText = sizeText
            }
            
        }else{
            guard let languageData = data.contentMoreDetails?.filter({$0.languageMasterID == 2}).first else{return}
            self.blogTitle.text = languageData.title
            if let desc = languageData.article?.htmlToAttributedString{
                let sizeText = NSMutableAttributedString(attributedString: desc)
                sizeText.setFontFace(font: FontCustom.shareInstance.customFont(fontName: .Exo2_Medium, size: 16))
                self.blogDescription.attributedText = sizeText
            }
        }
        
    }
}
