 import Cocoa
 import ReactiveCocoa
 
-// TODO: Find better way to incorporate VCs and VMs
+// TODO: Find better way to incorporate VCs and VMs. Current workaround is making all properties mutable and unwrapped. Ew.
 
 class ProjectDropViewController: NSViewController, DropViewDelegate {
     

    static func instantiate(viewModel: SelectedProjectViewModel) -> ProjectDropViewController {
        let controller = NSStoryboard(name: "Main", bundle: nil)!.instantiateControllerWithIdentifier("ProjectDroppa") as! ProjectDropViewController
        controller.viewModel = viewModel
        controller.setup()
        return controller
    }
    
    func setup() {
        self.view.wantsLayer = true

        // Intialize RoundedDropView
        dropView.translatesAutoresizingMaskIntoConstraints = false
        dropView.delegate = self
        dropView.layer?.borderWidth = borderWidth
        
        let fillDropView = NSLayoutConstraint.centeringConstraints(dropView, into: view, size: NSSize(width: 125+borderWidth, height: 125 + borderWidth))
        NSLayoutConstraint.activateConstraints(fillDropView)

    }

    func dropViewShouldAcceptDraggedPath(dropView: DropView, paths: [String]) -> Bool {
        let acceptable = viewModel.shouldAcceptPath(paths)
        
        if !acceptable {
            let anim = CABasicAnimation(keyPath: "position.x")
            anim.duration = 0.05
            anim.repeatCount = 3
            anim.autoreverses = true
            anim.fromValue = view.frame.origin.x + 10
            anim.toValue = view.frame.origin.x - 10
            view.layer?.addAnimation(anim, forKey: "x")
        }
        return acceptable
    }
    
    func dropViewNumberOfAcceptableItems(dropView: DropView, items: [Path]) -> Int {
        return 1
    }
}
