//
//  PatreonComponents.swift
//  AltStore
//
//  Created by Riley Testut on 9/5/19.
//  Copyright © 2019 Riley Testut. All rights reserved.
//

import UIKit

final class PatronCollectionViewCell: UICollectionViewCell
{
    @IBOutlet var textLabel: UILabel!
}

final class PatronsHeaderView: UICollectionReusableView
{
    let textLabel = UILabel()
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        self.textLabel.font = UIFont.boldSystemFont(ofSize: 17)
        self.textLabel.textColor = .white
        self.addSubview(self.textLabel, pinningEdgesWith: UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

final class PatronsFooterView: UICollectionReusableView
{
    let button = UIButton(type: .system)
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        
        self.button.translatesAutoresizingMaskIntoConstraints = false
        self.button.activityIndicatorView.style = .medium
        self.button.activityIndicatorView.color = .white
        self.button.titleLabel?.textColor = .white
        self.addSubview(self.button)
        
        NSLayoutConstraint.activate([self.button.centerXAnchor.constraint(equalTo: self.centerXAnchor),
                                     self.button.centerYAnchor.constraint(equalTo: self.centerYAnchor)])
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

final class AboutPatreonHeaderView: UICollectionReusableView
{
    @IBOutlet var supportButton: UIButton!
    @IBOutlet var twitterButton: UIButton!
    @IBOutlet var instagramButton: UIButton!
    @IBOutlet var accountButton: UIButton!
    @IBOutlet var textView: UITextView!
    
    @IBOutlet private var rileyLabel: UILabel!
    @IBOutlet private var shaneLabel: UILabel!
    
    @IBOutlet private var rileyImageView: UIImageView!
    @IBOutlet private var shaneImageView: UIImageView!
    
    override func awakeFromNib()
    {
        super.awakeFromNib()
        
        self.textView.clipsToBounds = true
        self.textView.layer.cornerRadius = 20
        self.textView.textContainer.lineFragmentPadding = 0
        
        for imageView in [self.rileyImageView, self.shaneImageView].compactMap({ $0 })
        {
            imageView.clipsToBounds = true
            imageView.layer.cornerRadius = imageView.bounds.midY
        }
        
        for button in [self.supportButton, self.accountButton, self.twitterButton, self.instagramButton].compactMap({ $0 })
        {
            button.clipsToBounds = true
            button.layer.cornerRadius = 16
        }
}
    
    override func layoutMarginsDidChange()
    {
        super.layoutMarginsDidChange()
        
        self.textView.textContainerInset = UIEdgeInsets(top: self.layoutMargins.left, left: self.layoutMargins.left, bottom: self.layoutMargins.right, right: self.layoutMargins.right)
    }
}

