UnifiedCouponBCFooterTableViewCell.swift 7.89 KB
//
//  UnifiedCouponBCFooterTableViewCell.swift
//  SwiftWarplyFramework
//
//  Created by Manos Chorianopoulos on 7/4/23.
//

import UIKit
//import RSBarcodes_Swift
import AVFoundation
// import SwiftEventBus

@objc public class UnifiedCouponBCFooterTableViewCell: UITableViewCell, UITextViewDelegate {
    @IBOutlet weak var termsButton: UIButton!
    @IBOutlet weak var termsTextView: UnselectableTappableTextView!
    @IBOutlet weak var termsTextViewHeight: NSLayoutConstraint!
    @IBOutlet weak var mapButton: UIButton!
    @IBOutlet weak var mapButtonHeight: NSLayoutConstraint!
    @IBOutlet weak var mapButtonTopSpace: NSLayoutConstraint!
    @IBOutlet weak var cancelButton: UIButton!

    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        termsTextView.delegate = self
        
        mapButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 17)
        mapButton.setTitle("Δες τα supermarket", for: .normal)
        mapButton.setTitleColor(UIColor(red: 1.00, green: 1.00, blue: 1.00, alpha: 1.00), for: .normal)
        mapButton.backgroundColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00)
        mapButton.layer.cornerRadius = 15.0
        mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 50)
        mapButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
        
        cancelButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 17)
        cancelButton.setTitle("Ακύρωση ενιαίου κουπονιού", for: .normal)
        cancelButton.setTitleColor(UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00), for: .normal)
        cancelButton.layer.cornerRadius = 15.0
        cancelButton.frame = CGRect(x: 0.0, y: 0.0, width: cancelButton.intrinsicContentSize.width, height: 50)
        cancelButton.contentEdgeInsets = UIEdgeInsets(top: 0, left: 25, bottom: 0, right: 25)
        cancelButton.backgroundColor = .clear
        cancelButton.layer.borderWidth = 2
        cancelButton.layer.borderColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00).cgColor

        // mapButton.isHidden = true
        // mapButtonHeight.constant = 0
        // mapButtonTopSpace.constant = 0
        
        // let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
        
        // for merchant in merchantList {
        //     if (merchant._uuid == couponSetData?.merchant_uuid) {
        //         if (merchant._show_map == true) {
        //             mapButton.setTitle("Δες τα καταστήματα", for: .normal)
        //             mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
        //             mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
        //             mapButton.isHidden = false
        //             mapBtnVisible = true
        //             eshopBtnVisible = false
        //             mapButtonHeight.constant = 44
        //             mapButtonTopSpace.constant = 10
        //         } else if (merchant._eshop == true) {
        //             mapButton.setTitle("Δες το eshop", for: .normal)
        //             mapButton.frame = CGRect(x: 0.0, y: 0.0, width: mapButton.intrinsicContentSize.width, height: 44)
        //             mapButton.contentEdgeInsets = UIEdgeInsets(top: 1, left: 16, bottom: 0, right: 16)
        //             mapButton.isHidden = false
        //             mapBtnVisible = false
        //             eshopBtnVisible = true
        //             mapButtonHeight.constant = 44
        //             mapButtonTopSpace.constant = 10
        //         } else {
        //             mapButton.isHidden = true
        //             mapBtnVisible = false
        //             eshopBtnVisible = false
        //             mapButtonHeight.constant = 0
        //             mapButtonTopSpace.constant = 0
        //         }
        //         eshopWebsite = merchant._website
        //         break;
        //     }
        // }

        // Fix width for ipad
//        if UIDevice.current.userInterfaceIdiom == .pad {
//             // iPad
//            mapButton.widthAnchor.constraint(equalToConstant: 250).isActive = true
//         } else {
//             // not iPad (iPhone, mac, tv, carPlay, unspecified)
//             mapButton.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true
//         }
        
        termsButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
//        termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
        termsButton.setTitle("Όροι χρήσης", for: .normal)
        termsButton.setTitleColor(UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00), for: .normal)
        termsButton.setImage(UIImage(named: "ic_down_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        termsButton.semanticContentAttribute = .forceRightToLeft
        termsButton.tintColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 1.00)
        termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
        termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
        termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
        
        let termsText = "1. Το εκπτωτικό κουπόνι ισχύει έως την ημερομηνία που αναφέρεται παραπάνω.\n2. To εκπτωτικό κουπόνι αφορά στα ενεργά κουπόνια προσφορών όπως αναφέρονται παραπάνω.\n3. Το εκπτωτικό κουπόνι μπορεί να χρησιμοποιηθεί σε μια μόνο συναλλαγή.\n4. Εάν δεν γίνει χρήση ενός επιμέρους κουπονιού προσφοράς από το εκπτωτικό κουπόνι, το κουπόνι προσφοράς επιστρέφει στο καλάθι στην ενότητα COSMOTE SUPERMARKET DEALS."
        termsTextView.attributedText = NSAttributedString(string: termsText)
        termsTextView.font = UIFont(name: "PeridotPE-Regular", size: 14)
        termsTextView.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
        termsTextView.textAlignment = .left
        termsTextView.isScrollEnabled = false
        
        termsTextView.isUserInteractionEnabled = true
        termsTextView.isEditable = false
        termsTextView.isSelectable = true
        termsTextView.dataDetectorTypes = [.link]
        
    }

    public override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    public func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
        UIApplication.shared.open(URL)

        // Disable `.preview` by 3D Touch and other interactions
        return false
    }
    
    func configureCell(termsVisible: Bool) {
        toggleTerms(termsVisible: termsVisible)
    }
    
    func toggleTerms(termsVisible: Bool) {
        if (termsVisible) {
            termsTextView.isHidden = false
            let targetSize = CGSize(width: termsTextView.frame.width, height: CGFloat(MAXFLOAT))
            termsTextViewHeight.constant = termsTextView.sizeThatFits(targetSize).height
            
            termsButton.setImage(UIImage(named: "ic_up_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        } else {
            termsTextView.isHidden = true
            termsTextViewHeight.constant = CGFloat(0)
            
            termsButton.setImage(UIImage(named: "ic_down_dark_2.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        }
    }

}