//
//  EvidationImageViewLayoutBlockBuilder.swift
//  EvidationMarkdown
//
//  Created by Helena McGahagan on 6/13/19.
//  Copyright © 2019 Evidation Health, Inc. All rights reserved.
//

import Markdown

class EvidationImageViewLayoutBlockBuilder : LayoutBlockBuilder<UIView> {
    
    //MARK: LayoutBuilder
    
    override func relatedMarkDownItemType() -> MarkDownItem.Type {
        return EvidationImageBlockMarkDownItem.self
    }
    
    override func build(_ markDownItem:MarkDownItem, asPartOfConverter converter : MarkDownConverter<UIView>, styling : ItemStyling) -> UIView {
        let imageBlockMarkDownItem = markDownItem as! EvidationImageBlockMarkDownItem
        
        let imageView = EvidationRemoteImageView(file: imageBlockMarkDownItem.file, altText: imageBlockMarkDownItem.altText)
        imageView.spinner.color = (styling as? SpinnerStyling)?.spinnerColor ?? UIColor.gray
        
        let spacing:UIEdgeInsets? = (styling as? ContentInsetStylingRule)?.contentInsets
        return ContainerView(view: imageView, spacing: spacing)
    }
}
