//
//  ModalSectionListTemplate.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 10/8/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


open class ModalSectionListTemplate: SectionListTemplate {
    //--------------------------------------------------
    // MARK: - Codec
    //--------------------------------------------------
    
    // For subclassing the model.
    open override func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ModalSectionListTemplateModel {
        try decoder.decode(ModalSectionListTemplateModel.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? ModalSectionListTemplateModel)?.closeAction ??
                ActionBackModel()
            MVMCoreActionHandler.shared()?.asyncHandleAction(with: closeAction, additionalData: nil, delegateObject: self.delegateObjectIVar)
        })
    }
}
