//
//  RadioSwatchCollectionViewCell.swift
//  MVMCoreUI
//
//  Created by Lekshmi S on 13/04/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


open class RadioSwatchCollectionViewCell: CollectionViewCell {
    public let radioSwatch = RadioSwatch()
    
    open override func setupView() {
        super.setupView()
        isAccessibilityElement = true
        addMolecule(radioSwatch)
        MVMCoreUIUtility.setMarginsFor(contentView, leading: 0, top: 0, trailing: 0, bottom: 0)
    }
    
    open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
        guard let model = model as? RadioSwatchModel else { return }
        radioSwatch.set(with: model, delegateObject, additionalData)
        updateAccessibility()
    }
    
    open func updateAccessibility() {
        accessibilityLabel = radioSwatch.accessibilityLabel
        accessibilityHint = radioSwatch.accessibilityHint
        accessibilityTraits = radioSwatch.accessibilityTraits
    }
    
    open override func accessibilityElementDidBecomeFocused() {
        super.accessibilityElementDidBecomeFocused()
        radioSwatch.bottomText.isHidden = false
    }
    
    open override func accessibilityElementDidLoseFocus() {
        super.accessibilityElementDidLoseFocus()
        if !radioSwatch.isSelected {
            radioSwatch.bottomText.isHidden = true
        }
    }
}
