//
//  TeseCaseCell.swift
//  KdanAuto
//
//  Created by 朱东勇 on 2022/11/21.
//

import Foundation
import AppKit

protocol TestFileCellViewDelegate : NSObjectProtocol {
    func fileCellNeedReplace(_ cell:TestFileCellView, fileName:String)
}

class TestFileCellView : NSTableCellView {
    @IBOutlet var _titleLbl : NSTextField!
    @IBOutlet var _sepLine : NSView!
    
    @IBOutlet var _replaceBtn : NSButton!
    
    var _title : String!
    var _isExpad: Bool!
    var _typeInfo : NSDictionary!
    
    weak public var _delegate : (TestFileCellViewDelegate)?
    
    class func shared() -> TestFileCellView? {
        var objects : NSArray!
        
        Bundle.main.loadNibNamed("TestFileCellView", owner: nil, topLevelObjects: &objects)
        
        for tView in objects {
            if let tv = tView as? TestFileCellView {
                return tv
            }
        }
        
        return nil
    }
    
    override func awakeFromNib() {
        _sepLine.wantsLayer = true;
        _sepLine.layer?.backgroundColor = NSColor.lightGray.cgColor
    }
    
    // Setter & Getter
    public func setTitle(_ title:String) {
        _title = title;
        
        _titleLbl.stringValue = _title ?? ""
    }
    
    public func title() -> String? {
        return _title
    }
    
    public func fileType() -> String? {
        return _title
    }
    
    public func setNeedReplaceBtn(_ needReplace:Bool) {
        _replaceBtn.isHidden = !needReplace
    }
    
    public func setTypeInfo(_ typeInfo:NSDictionary) {
        _typeInfo = typeInfo
        
        self.setTitle(_typeInfo["Type"] as! String)
    }
    
    public func typeInfo() -> NSDictionary? {
        return _typeInfo
    }
    
    
    @IBAction func replaceAction(_ sender:NSButton) {
        if _delegate != nil {
            _delegate?.fileCellNeedReplace(self, fileName: _title)
        }
    }
}
