UnifiedCouponBCFooterTableViewCell.swift 7.14 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!

    public override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        termsTextView.delegate = self
        
        mapButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 18)
        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.47, green: 0.75, blue: 0.08, alpha: 1.00)
        mapButton.layer.cornerRadius = 8.0
        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 = 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: "PFSquareSansPro-Regular", size: 16)
//        termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
        termsButton.setTitle("Όροι χρήσης", for: .normal)
        termsButton.setTitleColor(UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00), for: .normal)
        termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        termsButton.semanticContentAttribute = .forceRightToLeft
        termsButton.tintColor = UIColor(red: 0.21, green: 0.32, blue: 0.41, 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: "PFSquareSansPro-Regular", size: 15)
        termsTextView.textColor = UIColor(red: 0.25, green: 0.33, blue: 0.39, alpha: 1.00)
        termsTextView.textAlignment = .center
        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.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        } else {
            termsTextView.isHidden = true
            termsTextViewHeight.constant = CGFloat(0)
            
            termsButton.setImage(UIImage(named: "ic_down_dark.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
        }
    }

}