//
//  GDPRSettingsViewController.swift
//  sdk-demo-ios
//
//  Created by Smaato Inc on 25.06.18.
//  Copyright © 2018 Smaato Inc. All rights reserved.
//

import UIKit

class GDPRSettingsViewController: UIViewController {

    @IBOutlet private var removeConsentInformationButton: UIButton!
    @IBOutlet private var infoView: AdBlockView!
    private let gdprHelper = GDPRHelper()

    override func viewDidLoad() {
        super.viewDidLoad()
        infoView.tip = gdprHelper.gdprInfo()
        infoView.tipAlignment = .left
        
        self.title = OtherContent.GDPR.identifier
        
        removeConsentInformationButton.isEnabled = !gdprHelper.shouldShowConsentDialogMessage()
        
        gdprHelper.delegate = self
    }

    //MARK: Actions

    @IBAction private func onShowConsentDialog(_: Any?) {
        gdprHelper.showConsentDialog(onViewController: self)
    }
    @IBAction func onDeleteConsentInformation(_ sender: Any) {
        gdprHelper.deleteConsentInformation()
    }
}

extension GDPRSettingsViewController: GDPRHelperDelegate {

    func needsUpdateGDPRInformation() {
        infoView.tip = gdprHelper.gdprInfo()
        removeConsentInformationButton.isEnabled = !gdprHelper.shouldShowConsentDialogMessage()
        self.dismiss(animated: true, completion: nil)
    }

}
