//
//  ModalMoleculeStackTemplate.swift
//  MVMCoreUI
//
//  Created by Ryan on 3/6/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import UIKit

open class ModalMoleculeStackTemplate: MoleculeStackTemplate {
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    // For subclassing the model.
    open override func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ModalStackPageTemplateModel {
        try decoder.decode(ModalStackPageTemplateModel.self, from: data)
    }
    
    //--------------------------------------------------
    // MARK: - Lifecycle
    //--------------------------------------------------
    
    override open func handleNewData() {
        super.handleNewData()
        _ = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: { [weak self] _ in
            guard let self = self else { return }
            let closeAction = (self.templateModel as? ModalStackPageTemplateModel)?.closeAction ??
                ActionBackModel()
            MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar)
        })
    }
}
