//
//  KMBackgroundWindowController.swift
//  PDF Reader Pro
//
//  Created by lizhe on 2023/11/14.
//

import Cocoa

typealias KMBackgroundWindowControllerOperateCallBack = (_ controller: NSWindowController, _ background: KMBackgroundModel, _ countType: Int) -> ()
class KMBackgroundWindowController: KMBaseWindowController {
    
    @IBOutlet weak var addBackgroundView: KMAddBackgroundView!
    
    var background: KMBackgroundModel = KMBackgroundModel()
    
    var type: KMBackgroundManagerType = .use
    var currentType: Int = 0
    var operateCallBack: KMBackgroundWindowControllerOperateCallBack?
    
    override func windowDidLoad() {
        super.windowDidLoad()
        
        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
        if type == .edit {
            addBackgroundView.background = background
            addBackgroundView.originalBackground = background
        }
        addBackgroundView.isHiddenBatchBtn = isBatch
        addBackgroundView.type = type
        addBackgroundView.currentType = currentType
        addBackgroundView.pdfDocument = self.pdfDocument
        addBackgroundView.cancelAction = { [unowned self] view in
            cancelAction?(self)
        }
        
        addBackgroundView.operateCallBack = { [unowned self] background, countType in
            cancelAction?(self)
            operateCallBack?(self, background, countType)
        }
    }
}