//
//  MFLoadingSpinner+VDS.swift
//  MVMCoreUI
//
//  Created by Matt Bruce on 1/3/24.
//  Copyright © 2024 Verizon Wireless. All rights reserved.
//

import Foundation
import VDS

extension MFLoadingSpinner {
    var loader: Loader? {
        subviews.first as? Loader
    }
    
    @objc open func setSurface(_ strokeColor: UIColor?) {
        if let strokeColor {
            loader?.surface = strokeColor.isDark() ? .light : .dark
        }
    }
    
    @objc open func pause() {
        loader?.isActive = false
    }
    
    @objc open func resume() {
        loader?.isActive = true
    }
    
    @objc open func resumeAfterDelay() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { [weak self] in
            self?.loader?.isActive = true
        }
    }
    
    @objc open func pin() -> NSDictionary? {
        guard let size = loader?.size else { return nil }
        return NSLayoutConstraint.constraintPinView(self, heightConstraint: true, heightConstant: CGFloat(size), widthConstraint: true, widthConstant: CGFloat(size)) as NSDictionary?
    }
}
