//
//  RepoTableViewCell.swift
//  YZGithub
//
//  Created by 郑建文 on 16/7/26.
//  Copyright © 2016年 Zheng. All rights reserved.
//

import UIKit
import SwiftDate
import Kingfisher

class RepoTableViewCell: UITableViewCell {

    @IBOutlet weak var repoImage: UIImageView!
    @IBOutlet weak var repoName: UILabel!
    @IBOutlet weak var repoLastActiveTime: UILabel!
    @IBOutlet weak var repoStarNumber: UILabel!
    @IBOutlet weak var repoInfo: UILabel!
    @IBOutlet weak var repoForkNumber: UILabel!
    @IBOutlet weak var repoLanguage: UILabel!
    
    var repo:Repository? {
        didSet{
            updateUI()
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    func updateUI() {
        repoName.text = repo?.name
        repoInfo.text = repo?.cdescription
        if let forkNumber = repo?.forks_count {
            repoForkNumber.text = "\(forkNumber)"
        }
        if let starNumber  = repo?.stargazers_count {
            repoStarNumber.text = "\(starNumber)"
        }
//        repoLastActiveTime.text = (repo?.pushed_at?.date(format: DateFormat.iso8601)?.toRelativeString(abbreviated: false, maxUnits: 1))! + " age"
        if let lan = repo?.language {
            repoLanguage.text = lan
        }
        repoImage.kf.setImage(with: URL(string: (repo?.owner!.avatar_url)!)!)
    }
}
