//
//  KMRemovePasswordAlertWindowController.swift
//  PDF Reader Pro
//
//  Created by tangchao on 2022/11/29.
//

import Cocoa

typealias KMRemovePasswordAlertWindowControllerItemClick = (Int) -> ()
class KMRemovePasswordAlertWindowController: NSWindowController {

    @IBOutlet weak var titleLabel: NSTextField!
    
    @IBOutlet weak var cancelButton: NSButton!
    @IBOutlet weak var confirmButton: NSButton!
    
    var itemClick: KMRemovePasswordAlertWindowControllerItemClick!
    
    override func windowDidLoad() {
        super.windowDidLoad()

        titleLabel.stringValue = NSLocalizedString("Are you sure you want to remove the security settings for the file?", comment: "")
        titleLabel.font = NSFont.boldSystemFont(ofSize: 16)
        let style = NSMutableParagraphStyle()
        style.lineSpacing = 6
        style.alignment = .center
        titleLabel.attributedStringValue = NSAttributedString.init(string: titleLabel.stringValue, attributes: [.font : NSFont.boldSystemFont(ofSize: 16),.paragraphStyle : style])
        
        for button in [cancelButton, confirmButton] {
            button?.wantsLayer = true
            button?.layer?.borderWidth = 1
            button?.layer?.borderColor = NSColor.black.cgColor
            button?.layer?.cornerRadius = 4
            
            button!.target = self
            if ((button?.isEqual(to: cancelButton))!) {
                button?.title = NSLocalizedString("Cancel", comment: "")
                button?.action = #selector(cancelButtonAction)
            } else {
                button?.title = NSLocalizedString("Delete", comment: "")
                button?.layer?.backgroundColor = NSColor.black.cgColor
                button?.attributedTitle = NSMutableAttributedString(string: button!.title, attributes: [.foregroundColor : NSColor.white])
                button?.action = #selector(confirmButtonAction)
            }
        }
    }
    
    @objc func cancelButtonAction() {
        guard let callback = itemClick else {
            return
        }
        
        callback(1)
    }
    
    @objc func confirmButtonAction() {
        guard let callback = itemClick else {
            return
        }
        
        callback(2)
    }
}