WalletViewController.swift 69 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515
//
//  WalletViewController.swift
//  WarplySDKFrameworkIOS
//
//  Created by Βασιλης Σκουρας on 5/5/22.
//

import Foundation
import UIKit
import SwiftEventBus

@objc public class WalletViewController: UIViewController {
    @IBOutlet weak var headerImage: UIImageView!
    @IBOutlet weak var profileImage: UIImageView!
    @IBOutlet weak var profileNameLabel: UILabel!
    @IBOutlet weak var questionnaireButton: UIButton!
    @IBOutlet weak var historyButtonView: UIView!
    @IBOutlet weak var historyButtonImage: UIImageView!
    @IBOutlet weak var dfyEarnBannerView: UIView!
    @IBOutlet weak var dfyEarnBannerHeight: NSLayoutConstraint!
    @IBOutlet weak var dfyEarnBannerTopSpace: NSLayoutConstraint!
    @IBOutlet weak var dfyEarnBannerInnerView: UIView!
    @IBOutlet weak var dfyEarnLabel: UILabel!
    @IBOutlet weak var dfyEarnAmountLabel: UILabel!
    @IBOutlet weak var dfyEarnImage: UIImageView!
    @IBOutlet weak var couponEarnView: UIView!
    @IBOutlet weak var couponEarnViewHeight: NSLayoutConstraint!
    @IBOutlet weak var couponEarnViewTopSpace: NSLayoutConstraint!
    @IBOutlet weak var couponEarnInnerView: UIView!
    @IBOutlet weak var couponEarnLabel: UILabel!
    @IBOutlet weak var couponEarnAmountLabel: UILabel!
    @IBOutlet weak var couponEarnImage: UIImageView!
    @IBOutlet weak var dfyLogoImage: UIImageView!
    @IBOutlet weak var dfyLogoImageTopSpace: NSLayoutConstraint!
    @IBOutlet weak var dfyLogoImageHeight: NSLayoutConstraint!
    @IBOutlet weak var activeCodeView: UIView!
    @IBOutlet weak var activeCodeViewHeight: NSLayoutConstraint!
    @IBOutlet weak var activeCodesCountLabel: UILabel!
    @IBOutlet weak var activeCodeLabel: UILabel!
    @IBOutlet weak var activeCodeExpirationLabel: UILabel!
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet weak var activeCodeImage: UIImageView!
    @IBOutlet weak var myPresentsLabel: UILabel!
    @IBOutlet weak var emptyView: UIView!
    @IBOutlet weak var emptyViewHeight: NSLayoutConstraint!
    @IBOutlet weak var emptyImage: UIImageView!
    @IBOutlet weak var emptyLabel: UILabel!
    @IBOutlet weak var activeCodeScrollView: UIScrollView!
    @IBOutlet weak var activeCodeScrollViewHeight: NSLayoutConstraint!
    @IBOutlet weak var activeCodeContentView: UIView!
    @IBOutlet weak var activeCodeContentViewHeight: NSLayoutConstraint!
    
    @IBOutlet weak var rewardsView: UIView!
    @IBOutlet weak var rewardsViewHeight: NSLayoutConstraint!
    
    @IBOutlet weak var rewardsLabel: UILabel!
    @IBOutlet weak var sumBadgeImage: UIImageView!
    @IBOutlet weak var sumBadgeLabel: UILabel!
    @IBOutlet weak var dfyBadgeImage: UIImageView!
    @IBOutlet weak var dfyBadgeLabel: UILabel!
    @IBOutlet weak var couponBadgeImage: UIImageView!
    @IBOutlet weak var couponBadgeLabel: UILabel!
    @IBOutlet weak var marketBadgeImage: UIImageView!
    @IBOutlet weak var marketBadgeLabel: UILabel!
    @IBOutlet weak var badgeLinesImage: UIImageView!
    
    public var coupons:Array<swiftApi.CouponItemModel> = swiftApi().getCouponList()
    public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons()
    public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
    public var profile:swiftApi.ProfileModel? = swiftApi().getConsumer()
    public var unifiedCoupons:Array<swiftApi.UnifiedCouponModel> = []
    public var smCoupons:Array<swiftApi.CouponItemModel> = [] // swiftApi().getSMCouponList()
    public var boxCoupons:Array<swiftApi.ActiveBoxCouponModel> = swiftApi().getActiveBoxCoupons()

    var timerWallet: DispatchSourceTimer?
    var seconds: Int = 0
    
    var totalCouponValue = swiftApi().getDealsCouponsSum()
    var totalCouponDiscount = Float(round(100 * swiftApi().getLoyaltyBadge()._value) / 100)
    var unifiedCouponsDiscount:Float = 0.0
    
    var forYouExpanded: Bool = false;
    var showSpinner: Bool = false;
    var showActiveCouponsBanners: Bool = false;
    var showEmptyView: Bool = false;
    
   
    public override func viewDidLoad() {
        super.viewDidLoad()
        
        self.hidesBottomBarWhenPushed = true
        
        SwiftEventBus.onBackgroundThread(self, name: "coupons_fetched") { result in

            DispatchQueue.main.async {
                self.coupons = swiftApi().getCouponList()
                self.totalCouponDiscount = Float(round(100 * swiftApi().getLoyaltyBadge()._value) / 100)
                self.loyaltyBadge = swiftApi().getLoyaltyBadge()
                
                self.handleSpinnerAndEmptyView()
                self.tableView.reloadData()
            }
        }
        
        SwiftEventBus.onBackgroundThread(self, name: "unified_coupons_fetched") { result in

            DispatchQueue.main.async {
                self.unifiedCoupons = swiftApi().getUnifiedCouponList()
                // TODO: Maybe add this
                // TODO: Uncomment if discounts are shown again in wallet
               self.matchOldSMCoupons()
               self.updateMarketBadge()
                self.handleSpinnerAndEmptyView()
                self.tableView.reloadData()
            }
        }
        
        SwiftEventBus.onBackgroundThread(self, name: "sm_coupons_fetched") { result in

            DispatchQueue.main.async {
                self.smCoupons = swiftApi().getSMCouponList()
                self.handleSpinnerAndEmptyView()
                self.tableView.reloadData()
            }
        }
        
        SwiftEventBus.onBackgroundThread(self, name: "vouchers_fetched") { result in

            DispatchQueue.main.async {
                print("=== vouchers_fetched event ===")
                
                self.handleSpinnerAndEmptyView()
//                self.showSpinner = false
                self.tableView.reloadData()
                
            }
        }
        
        SwiftEventBus.onBackgroundThread(self, name: "vouchers_service_unavailable") { result in

            DispatchQueue.main.async {
                print("=== vouchers_service_unavailable event ===")
                
                self.showVouchersFailureDialog()
                
            }
        }
        
        // TODO: DELETE ===>
//        let coupon = swiftApi.ActiveDFYCouponModel()
//        coupon._value = "12"
//     //    coupon._date = "2022-12-05 01:55:01"
//        coupon._date = "2022-10-26 23:59:01"
//        coupon._code = "123456789"
//
//        let coupon2 = swiftApi.ActiveDFYCouponModel()
//        coupon2._value = "23"
//        coupon2._date = "2022-11-05 01:55"
//        coupon2._code = "234567891"
//
//        let coupon3 = swiftApi.ActiveDFYCouponModel()
//        coupon3._value = "34"
//        coupon3._date = "2022-07-01 01:55"
//        coupon3._code = "345678912"
//
//        let couponsArray: Array<swiftApi.ActiveDFYCouponModel> = [coupon, coupon2, coupon3, coupon3, coupon3]
//
//         swiftApi().setActiveDFYCoupons(dfyCoupons: couponsArray)
//
//         dfyCoupons = swiftApi().getActiveDFYCoupons()
        // TODO: DELETE <===
        
        // TODO: Uncomment when UnifiedCoupons will be shown again
//        getCouponsSetsDealsRequest()
        
//        setBackButton("ic_close_3")
//        setNavigationTitle("My Rewards")
        
        tableView.delegate = self
        tableView.dataSource = self

        print("Active Gifts Count: " + String(coupons.count))

        // if ((profile != nil) && (profile?._nonTelco == true)) {
        if (swiftApi().getUserNonTelco() == true) {
            showDialog("Αδυναμία ενεργοποίησης", "Πρόσθεσε σύνδεση COSMOTE σταθερής, κινητής ή TV για να έχεις πρόσβαση στις προσφορές.");
        }
        
       headerImage.image = UIImage(named: "ic_background_straight", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        historyButtonImage.image = UIImage(named: "wallet_history", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
       dfyEarnImage.image = UIImage(named: "wallet_dfy_3", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
       couponEarnImage.image = UIImage(named: "wallet_coupons_4", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
       dfyLogoImage.image = UIImage(named: "dfy_logo_colored", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
       activeCodeImage.image = UIImage(named: "active_code_logo_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        
        if (profile != nil && !(profile?._image_url is NSNull) && profile?._image_url != nil && profile?._image_url != "") {
            
            profileImage.load(link: profile?._image_url ?? "", placeholder: UIImage(), cache: URLCache())
        } else {
           profileImage.image = UIImage(named: "default_profile_image_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        }
        
        profileImage.layer.cornerRadius = 19
        profileImage.layer.maskedCorners = [ .layerMinXMinYCorner, .layerMaxXMaxYCorner] // Top left, bottom right corner radius
        profileImage.layer.borderWidth = 1
        profileImage.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor

        print("Profile Name: " + (profile?._firstname ?? "") + " " + (profile?._lastname ?? ""))

        profileNameLabel.text = (profile?._firstname ?? "") + " " + (profile?._lastname ?? "")
        
        let userTag = swiftApi().getUserTag()
        print("User tag: " + userTag)
        if (userTag != "" && userTag != "undefined") {
            questionnaireButton.setTitle(userTag, for: .normal)
//            questionnaireButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
//            questionnaireButton.setTitleColor(.white, for: .normal)
//    //        questionnaireButton.sizeToFit()
//            questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 26)
//            questionnaireButton.applyGradient(colours: [UIColor(red: 0.40, green: 0.77, blue: 0.28, alpha: 1.00), UIColor(red: 0.10, green: 0.66, blue: 0.72, alpha: 1.00)], gradient: GradientOrientation.horizontal, cornerRadius: 7.0)
//            // Shadow Color
//            questionnaireButton.layer.shadowColor = UIColor(red: 0.33, green: 0.38, blue: 0.43, alpha: 1.00).cgColor
//            questionnaireButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
//            questionnaireButton.layer.shadowOpacity = 1.0
//            questionnaireButton.layer.shadowRadius = 0.0
//            questionnaireButton.layer.masksToBounds = false
//            questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 7, left: 10, bottom: 3, right: 10)
        } else {
            questionnaireButton.setTitle("+Προτιμήσεις", for: .normal)
//            questionnaireButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
//            questionnaireButton.setTitleColor(UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00), for: .normal)
//            questionnaireButton.backgroundColor = .clear
//            questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 26)
//            questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 10)
        }
        
        questionnaireButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
        questionnaireButton.setTitleColor(UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00), for: .normal)
        questionnaireButton.backgroundColor = .clear
        questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 42)
        questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 20, bottom: 12, right: 20)
        
        questionnaireButton.layer.cornerRadius = 16.0
        questionnaireButton.layer.borderWidth = 1
        questionnaireButton.layer.borderColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00).cgColor
        
        historyButtonView.backgroundColor = .clear
        historyButtonView.layer.cornerRadius = 16.0
        historyButtonView.layer.borderWidth = 1
        historyButtonView.layer.borderColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00).cgColor
        
        dfyEarnBannerInnerView.layer.cornerRadius = 16.5
        // dfyEarnBannerInnerView.layer.borderWidth = 1
        // dfyEarnBannerInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor

        // Add shadow
        dfyEarnBannerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
        dfyEarnBannerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
        dfyEarnBannerView.layer.shadowOpacity = 1.0
        dfyEarnBannerView.layer.shadowRadius = 1.0
        
//        var totalCouponValue = swiftApi().getDealsCouponsSum()

        if (totalCouponValue == 0.0) {
            dfyEarnBannerView.isHidden = true
            dfyEarnBannerHeight.constant = 0
//            dfyEarnBannerTopSpace.constant = 0
            
        } else {
            dfyEarnBannerView.isHidden = false
            dfyEarnBannerHeight.constant = 75
//            dfyEarnBannerTopSpace.constant = 30
            
        }

        totalCouponValue = Float(round(100 * totalCouponValue) / 100)
        var totalCouponValueString = "0"
        totalCouponValueString = String(format: "%.2f", totalCouponValue).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)

        // dfyEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponValueString + "€ με το DEALS for YOU!"

        let normalText1 = "Μέχρι τώρα έχεις κερδίσει "
        let boldText  = totalCouponValueString + "€"
        let normalText2 = " με το DEALS for YOU!"

        let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 14) ?? UIFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)]
        let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 14) ?? UIFont.boldSystemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)]
        
        let attributedString = NSMutableAttributedString(string:normalText1, attributes:attrRegular)
        let boldString = NSMutableAttributedString(string: boldText, attributes:attrBold)
        let normalString = NSMutableAttributedString(string:normalText2, attributes:attrRegular)

        attributedString.append(boldString)
        attributedString.append(normalString)
        dfyEarnLabel.attributedText = attributedString
        
        dfyEarnAmountLabel.text = totalCouponValueString + "€"
//        dfyEarnAmountLabel.font = UIFont(name: "PeridotPE-Bold", size: 14)

        let totalCouponValueIntCount = String(Int(totalCouponValue)).count
        if (totalCouponValueIntCount >= 3) {
            dfyEarnAmountLabel.font = UIFont(name: "PeridotPE-Bold", size: 11)
        } else {
            dfyEarnAmountLabel.font = UIFont(name: "PeridotPE-Bold", size: 13)
        }
        
        if (loyaltyBadge._couponCount == 0) {
            couponEarnView.isHidden = true
            couponEarnViewHeight.constant = 0
            couponEarnViewTopSpace.constant = 0
            
        } else {
            couponEarnView.isHidden = false
            couponEarnViewHeight.constant = 75
            if (totalCouponValue == 0.0) {
                couponEarnViewTopSpace.constant = 30
            } else {
                couponEarnViewTopSpace.constant = 15
            }
            
        }
        
        couponEarnInnerView.layer.cornerRadius = 16.5
        // couponEarnInnerView.layer.borderWidth = 1
        // couponEarnInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
        
        // Add shadow
        couponEarnView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
        couponEarnView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
        couponEarnView.layer.shadowOpacity = 1.0
        couponEarnView.layer.shadowRadius = 1.0
        
//        let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
        var totalCouponDiscountString = "0"
        totalCouponDiscountString  = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
        
        // couponEarnLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"

        let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
        let coupBoldText  = totalCouponDiscountString + "€"
        let coupNormalText2 = " σε προσφορές από "
        let coupBoldText2  = String(loyaltyBadge._couponCount)
        let coupNormalText3 = " κουπόνια!"

        let coupAttributedString = NSMutableAttributedString(string:coupNormalText1, attributes:attrRegular)
        let coupBoldString = NSMutableAttributedString(string: coupBoldText, attributes:attrBold)
        let coupNormalString2 = NSMutableAttributedString(string:coupNormalText2, attributes:attrRegular)
        let coupBoldString2 = NSMutableAttributedString(string: coupBoldText2, attributes:attrBold)
        let coupNormalString3 = NSMutableAttributedString(string:coupNormalText3, attributes:attrRegular)

        coupAttributedString.append(coupBoldString)
        coupAttributedString.append(coupNormalString2)
        coupAttributedString.append(coupBoldString2)
        coupAttributedString.append(coupNormalString3)
        couponEarnLabel.attributedText = coupAttributedString

        couponEarnAmountLabel.text = totalCouponDiscountString + "€"

        let totalCouponDiscountIntCount = String(Int(totalCouponDiscount)).count
        if (totalCouponDiscountIntCount >= 3) {
            couponEarnAmountLabel.font = UIFont(name: "PeridotPE-Bold", size: 11)
        } else {
            couponEarnAmountLabel.font = UIFont(name: "PeridotPE-Bold", size: 13)
        }
        
        print("Loyalty Badge Value: " + totalCouponDiscountString)
        print("Loyalty Badge Count: " + String(loyaltyBadge._couponCount))
        
        // activeCodeView
        activeCodeView.layer.cornerRadius = 5.0
        activeCodeView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor
        activeCodeView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
        activeCodeView.layer.shadowOpacity = 1.0
        activeCodeView.layer.shadowRadius = 6.0
        
        if (dfyCoupons.count > 0) {
            if (dfyCoupons.count == 1) {
                let dateFormatter = DateFormatter()
                dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
                // dateFormatter.dateFormat = "yyyy-MM-dd HH:mm"
                
                // sort dfyCoupons by date
                dfyCoupons.sort(by: {
                    let date1 = dateFormatter.date(from: $0._date)
                    let date2 = dateFormatter.date(from: $1._date)
                    
                    if ((date1 != nil) && (date2 != nil)) {
                        return date1!.compare(date2!) == .orderedAscending
                    } else {
                        return false
                    }
                    
                })
                
                // Get days from now of the most recet coupon
                var daysFromNow = ""
                let calendar = Calendar.current

                // Replace the hour (time) of both dates with 00:00
                let date1 = calendar.startOfDay(for: Date())
                if let date2 = dateFormatter.date(from: dfyCoupons[0]._date) {
                    let components = calendar.dateComponents([.day], from: date1, to: date2)
                    daysFromNow = (components.day) != nil ? String((components.day ?? 0) + 1) : ""
                }
                
                activeCodesCountLabel.text = "Ενεργός κωδικός:"
                // activeCodeLabel.text = dfyCoupons[0]._code
                let newLabel = CopyableLabel()
                newLabel.text = String(dfyCoupons[0]._code)
                newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19)
                newLabel.textColor = UIColor(rgb: 0x3C5365)
                newLabel.frame.size.width = newLabel.intrinsicContentSize.width
                newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight
                activeCodeContentView.addSubview(newLabel)
                // set the btn frame origin
                newLabel.frame.origin.x = 0
                newLabel.frame.origin.y = 0
                let scrollHeight = newLabel.intrinsicContentSize.height
                activeCodeContentViewHeight.constant = scrollHeight
                activeCodeScrollViewHeight.constant = scrollHeight

                activeCodeExpirationLabel.isHidden = false
                if (daysFromNow == "1") {
                    activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρα"
                } else {
                    activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρες"
                }
                
            } else {
                var tagHeight:CGFloat = 30
                let tagPadding: CGFloat = 0
                let tagSpacingX: CGFloat = 0
                let tagSpacingY: CGFloat = 2
                
                let containerWidth = activeCodeContentView.frame.size.width
                
                var currentOriginX: CGFloat = 0
                var currentOriginY: CGFloat = 0

                // var couponCodesString = ""
                for (index, item) in dfyCoupons.enumerated() {
                    let newLabel = CopyableLabel()
                    newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19)
                    newLabel.textColor = UIColor(rgb: 0x3C5365)

                    if (index == (dfyCoupons.endIndex - 1)) {
                        // couponCodesString += String(item._code)
                        newLabel.text = String(item._code)
                    } else {
                        // couponCodesString += String(item._code) + ", "
                        newLabel.text = String(item._code) + ", "
                    }
                    
                    newLabel.frame.size.width = newLabel.intrinsicContentSize.width + tagPadding
                    newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight
                    tagHeight = newLabel.intrinsicContentSize.height
                    activeCodeContentView.addSubview(newLabel)
                    
                    // if current X + label width will be greater than container view width
                    //  "move to next row"
                    if currentOriginX + newLabel.frame.width > containerWidth {
                        currentOriginX = 0
                        currentOriginY += tagHeight + tagSpacingY
                    }
                    
                    // set the btn frame origin
                    newLabel.frame.origin.x = currentOriginX
                    newLabel.frame.origin.y = currentOriginY
                    
                    // increment current X by btn width + spacing
                    currentOriginX += newLabel.frame.width + tagSpacingX
                }
                
                activeCodesCountLabel.text = String(dfyCoupons.count) + " Ενεργοί κωδικοί:"
                // activeCodeLabel.text = couponCodesString
                activeCodeExpirationLabel.isHidden = true

                // update container view height
                activeCodeContentViewHeight.constant = currentOriginY + tagHeight
                if ((currentOriginY + tagHeight) <= (2 * tagHeight + tagSpacingY)) {
                    activeCodeScrollViewHeight.constant = currentOriginY + tagHeight
                } else {
                    activeCodeScrollViewHeight.constant = 2 * tagHeight + tagSpacingY
                }
            }
        } else {
            activeCodeLabel.text = "-"
            activeCodeExpirationLabel.text = ""

            dfyLogoImage.isHidden = true
            activeCodeView.isHidden = true
            
            dfyLogoImageHeight.constant = 0
            activeCodeViewHeight.constant = 0
//            dfyLogoImageTopSpace.constant = 0
        }

        myPresentsLabel.text = "Τα δώρα μου"
        if (coupons.count > 0) {
            myPresentsLabel.isHidden = false
        } else {
            myPresentsLabel.isHidden = true
        }

        emptyImage.image = UIImage(named: "ic_empty_wallet_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
        emptyLabel.text = "Δεν έχεις κάποιον ενεργό κωδικό ή κουπόνι! Μπες τώρα στην ενότητα COSMOTE For You και βρες αποκλειστικές προσφορές!"
        
        // TODO: Uncomment if discounts are shown again in wallet
       matchOldSMCoupons()
       updateMarketBadge()
        
        // TODO: DELETE if emptyView is needed again
//        emptyView.isHidden = true
//        emptyViewHeight.constant = 0
        
        self.handleSpinnerAndEmptyView()
        
    }

    public override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        swiftApi().logTrackersEvent("screen", "LoyaltyWalletScreen")

        // addNavShadow()
        self.navigationController?.hideHairline()
        
        let userTag = swiftApi().getUserTag()
        if (questionnaireButton.currentTitle != userTag) {
            if (userTag != "" && userTag != "undefined") {
                questionnaireButton.setTitle(userTag, for: .normal)
//                questionnaireButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 14)
//                questionnaireButton.setTitleColor(.white, for: .normal)
//        //        questionnaireButton.sizeToFit()
//                questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 26)
//                questionnaireButton.applyGradient(colours: [UIColor(red: 0.40, green: 0.77, blue: 0.28, alpha: 1.00), UIColor(red: 0.10, green: 0.66, blue: 0.72, alpha: 1.00)], gradient: GradientOrientation.horizontal, cornerRadius: 7.0)
//                // Shadow Color
//                questionnaireButton.layer.shadowColor = UIColor(red: 0.33, green: 0.38, blue: 0.43, alpha: 1.00).cgColor
//                questionnaireButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
//                questionnaireButton.layer.shadowOpacity = 1.0
//                questionnaireButton.layer.shadowRadius = 0.0
//                questionnaireButton.layer.masksToBounds = false
//                questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 7, left: 10, bottom: 3, right: 10)
            } else {
                for layer in (questionnaireButton.layer.sublayers ?? []) {
                    if(layer.name == "linearGradientLayer"){
                        layer.removeFromSuperlayer()
                    }
                }
                questionnaireButton.layer.shadowOpacity = 0.0;
                questionnaireButton.setTitle("+Προτιμήσεις", for: .normal)
//                questionnaireButton.titleLabel?.font = UIFont(name: "PFSquareSansPro-Medium", size: 14)
//                questionnaireButton.setTitleColor(UIColor(red: 0.31, green: 0.62, blue: 0.18, alpha: 1.00), for: .normal)
//                questionnaireButton.backgroundColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00)
//                questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 26)
//            questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 10)
            }
            questionnaireButton.titleLabel?.font = UIFont(name: "PeridotPE-Bold", size: 15)
            questionnaireButton.setTitleColor(UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00), for: .normal)
            questionnaireButton.backgroundColor = .clear
            questionnaireButton.frame = CGRect(x: 0.0, y: 0.0, width: questionnaireButton.intrinsicContentSize.width, height: 42)
            questionnaireButton.contentEdgeInsets = UIEdgeInsets(top: 12, left: 20, bottom: 12, right: 20)
            
            questionnaireButton.layer.cornerRadius = 16.0
            questionnaireButton.layer.borderWidth = 1
            questionnaireButton.layer.borderColor = UIColor(red: 0.05, green: 0.65, blue: 0.00, alpha: 1.00).cgColor
        }

        self.coupons = swiftApi().getCouponList()
        // TODO: Uncomment when UnifiedCoupons will be shown again
        self.unifiedCoupons = swiftApi().getUnifiedCouponList()
        self.smCoupons = swiftApi().getSMCouponList()
        // TODO: Maybe add this
        self.matchOldSMCoupons()
        // <===
        // TODO: Uncomment if discounts are shown again in wallet
       self.updateMarketBadge()
        self.handleSpinnerAndEmptyView()
        self.tableView.reloadData()

        self.startTimer()
    }

    public override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)

        self.stopTimer()
        self.navigationController?.navigationBar.layer.shadowOpacity = 0.0
        
        if self.isMovingFromParent {
            // Clear ShowVouchersBanner state
            swiftApi().clearShowVouchersBanner();
        }
    }
    
    public override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        // TODO: Uncomment if header is needed again
//        if let headerView = tableView.tableHeaderView {
//            
//            let height = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
//            var headerFrame = headerView.frame
////            let height = 0.0
////            var headerFrame = CGRect(x: 0,y: 0,width: 0,height: 0)
//
//            //Comparison necessary to avoid infinite loop
//            if height != headerFrame.size.height {
//                headerFrame.size.height = height
//                headerView.frame = headerFrame
//                tableView.tableHeaderView = headerView
//            }
//        }
        
        // TODO: DELETE if header is needed again
        self.tableView.tableHeaderView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: self.tableView.bounds.size.width, height: 0.01))
    }

    // MARK: - Functions
    func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {

        let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
            switch action.style{
                case .default:
                    self.navigationController?.popViewController(animated: true)
                    // self.dismiss(animated: true, completion: {})
                
                case .cancel:
                print("cancel")
                
                case .destructive:
                print("destructive")
                
            }
        }))
        self.present(alert, animated: true, completion: nil)
    }
    
    func showVouchersFailureDialog() -> Void {

        let alert = UIAlertController(title: "Προσπάθησε ξανά αργότερα", message: "Προσωρινά μη διαθέσιμη πληροφορία.\nΠαρακαλούμε δοκίμασε ξανά σε λίγο.", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
            switch action.style{
                case .default:
//                    self.handleSpinnerAndEmptyView()
//                    self.tableView.reloadData()
                    self.navigationController?.popViewController(animated: true)
                    // self.dismiss(animated: true, completion: {})
                
                case .cancel:
                print("cancel")
                
                case .destructive:
                print("destructive")
                
            }
        }))
        self.present(alert, animated: true, completion: nil)
    }

    func startTimer() {
        print("========= MyRewards Timer Started! =========")

        let queue = DispatchQueue(label: Bundle.main.bundleIdentifier! + ".wallet.timer")
        timerWallet = DispatchSource.makeTimerSource(queue: queue)
        timerWallet!.schedule(deadline: .now(), repeating: .seconds(1))
        timerWallet!.setEventHandler { [weak self] in
            // do whatever stuff you want on the background queue here here
            print("========= MyRewards interval! =========")

            DispatchQueue.main.async {
                // update your model objects and/or UI here
                self?.seconds = (self?.seconds ?? 0) + 1

            }
        }
        timerWallet!.resume()
    }

    func stopTimer() {
        print("========= MyRewards Timer Stopped! =========")
        timerWallet?.cancel()
        timerWallet = nil

        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "time_spent_on_loyalty_sdk"
        firebaseEvent.setParameter = ("name", "MyRewards")
        firebaseEvent.setParameter = ("seconds", String(seconds))
        SwiftEventBus.post("firebase", sender: firebaseEvent)

        seconds = 0
    }
    
    func updateMarketBadge() {
        unifiedCouponsDiscount = 0.0
//        for smCouponSet in swiftApi().getCouponSetsDealsList() {
//            for oldCoupon in swiftApi().getAllOldCouponList() {
//                if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
//
//                    oldCoupon.setCouponSetData(smCouponSet);
//
//                     if let discountFloat = Float(oldCoupon.discount ?? "0.0") {
//                         unifiedCouponsDiscount += discountFloat
//                     }
//                    break;
//                }
//            }
//        }
        
        for coupon in swiftApi().getOldUnifiedCouponList() {
            if let discountFloat = Float(coupon.discount ?? "0.0") {
                unifiedCouponsDiscount += discountFloat
            }
        }
        
        // TODO: UNCOMMENT if emptyView is needed again
//        if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
//            emptyView.isHidden = false
//            emptyViewHeight.constant = emptyView.intrinsicContentSize.height
//        } else {
//            emptyView.isHidden = true
//            emptyViewHeight.constant = 0
//        }
    }
    
    func matchOldSMCoupons() {
        var oldUnifiedCouponsArray:Array<swiftApi.CouponItemModel> = []
        
        // TODO: Check - Old implementation
//        for smCouponSet in swiftApi().getCouponSetsDealsList() {
//            for oldCoupon in swiftApi().getAllOldCouponList() {
//                if (smCouponSet.uuid != "" && oldCoupon.couponset_uuid != "" && smCouponSet.uuid == oldCoupon.couponset_uuid) {
//                    
//                    oldCoupon.setCouponSetData(smCouponSet);
//                    oldUnifiedCouponsArray.append(oldCoupon);
//                    
//                    break;
//                }
//            }
//        }
        
        // TODO: DELETE - TEST
//        oldUnifiedCouponsArray = swiftApi().getAllOldCouponList().filter({ return $0.couponset_data?.couponset_type == "supermarket" })
        oldUnifiedCouponsArray = swiftApi().getSMOldCouponList()
        
        oldUnifiedCouponsArray.sort(by: {
            let date1 = $0.redeemed_date
            let date2 = $1.redeemed_date
            
            if ((date1 != nil) && (date2 != nil)) {
                return date1!.compare(date2!) == .orderedDescending
            } else {
                return false
            }
            
        })
        swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
        
    }
    
    func handleSpinnerAndEmptyView() {
        if (swiftApi().getShowVouchersBanner() == "") {
            self.emptyView.isHidden = true
            self.emptyViewHeight.constant = 0
            self.showEmptyView = false
            
            self.showSpinner = true
            
            if (self.dfyCoupons.count == 0 && self.unifiedCoupons.count == 0 && self.smCoupons.count == 0 && self.coupons.count == 0) {
                self.showActiveCouponsBanners = false
                
            } else {
                self.showActiveCouponsBanners = true
            }
            
        } else {
            self.showSpinner = false

            if (self.dfyCoupons.count == 0 && self.unifiedCoupons.count == 0 && self.smCoupons.count == 0 && self.coupons.count == 0) {
                self.showActiveCouponsBanners = false
                
                if (swiftApi().getShowVouchersBanner() == "null") {
                    // TODO: UNCOMMENT if emptyView is needed again
//                    self.emptyView.isHidden = false
//                    self.emptyViewHeight.constant = self.emptyView.intrinsicContentSize.height
                    let sumRedeemed = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
                    if (sumRedeemed == 0.0) {
                        self.showEmptyView = true
                    } else {
                        self.showEmptyView = false
                    }
//                    self.showEmptyView = true
                    
                } else {
                    self.emptyView.isHidden = true
                    self.emptyViewHeight.constant = 0
                    self.showEmptyView = false
                }
                
            } else {
                self.emptyView.isHidden = true
                self.emptyViewHeight.constant = 0
                self.showEmptyView = false
                
                self.showActiveCouponsBanners = true
            }
        }
    }
    
    
    // MARK: - API Functions
    func getCouponsSetsDealsRequest() {
        swiftApi().getCouponSetsDealsAsync(getCouponsSetsDealsCallback, failureCallback: {errorCode in
        })
    }
    
    func getCouponsSetsDealsCallback (_ couponsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
        if (couponsData != nil) {
            
            DispatchQueue.main.async {
                self.getUnifiedCouponsRequest()
            }
        } else {
        }
    }
    
    func getUnifiedCouponsRequest() {
        swiftApi().getUnifiedCouponsAsync(getUnifiedCouponsCallback, failureCallback: {errorCode in
            self.unifiedCoupons = []
        })
    }
    
    func getUnifiedCouponsCallback (_ couponsData: Array<swiftApi.UnifiedCouponModel>?) -> Void {
        if (couponsData != nil) {
            self.unifiedCoupons = couponsData ?? []
            
            DispatchQueue.main.async {
                self.matchOldSMCoupons()
                self.updateMarketBadge()
                self.handleSpinnerAndEmptyView()
                self.tableView.reloadData()
            }
        } else {
            self.unifiedCoupons = []
        }
    }
    
    // MARK: - Actions
    @IBAction func qustionnaireButtonAction(_ sender: Any) {
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "Questionnaire"))
        
        swiftApi().openQuestionnaire(self);
    }
    
    @IBAction func historyButtonAction(_ sender: Any) {
        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "did_tap_history_badge"
        firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
        SwiftEventBus.post("firebase", sender: firebaseEvent)
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyHistoryBadge"))
        
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
        let vc = storyboard.instantiateViewController(withIdentifier: "LoyaltyHistoryViewController") as! SwiftWarplyFramework.LoyaltyHistoryViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    @IBAction func dfyEarnButtonAction(_ sender: Any) {
        print("DFY coupon banner pressed!")
       // analysis_pressed event
       let dealsAnalysis = swiftApi.WarplyDealsAnalysisEventModel()
       dealsAnalysis._isPressed = true
       SwiftEventBus.post("analysis_pressed", sender: dealsAnalysis)

        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "did_tap_gifts_for_you_badge"
        firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
        SwiftEventBus.post("firebase", sender: firebaseEvent)
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "DealsBanner"))
    }
    @IBAction func couponEarnButtonAction(_ sender: Any) {

        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "did_tap_deals_for_you_badge"
        firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
        SwiftEventBus.post("firebase", sender: firebaseEvent)
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyBanner"))

        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
        let vc = storyboard.instantiateViewController(withIdentifier: "LoyaltyAnalysisViewController") as! SwiftWarplyFramework.LoyaltyAnalysisViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
    @IBAction func activeCodeButtonAction(_ sender: Any) {
        print("Active DFY coupon banner Tapped!")
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveDealsBanner"))
        
        let couponDetails = swiftApi.ActiveDFYCouponEventModel()
        couponDetails._isPressed = true
        SwiftEventBus.post("dfy_coupon_details", sender: couponDetails)
    }
    
    @IBAction func dfyBadgeButtonAction(_ sender: Any) {
        var totalCouponValue = swiftApi().getDealsCouponsSum()
        if (totalCouponValue > 0.0) {
            print("DFY coupon banner pressed!")
           // analysis_pressed event
           let dealsAnalysis = swiftApi.WarplyDealsAnalysisEventModel()
           dealsAnalysis._isPressed = true
           SwiftEventBus.post("analysis_pressed", sender: dealsAnalysis)

            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_gifts_for_you_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "DealsBanner"))
        }
    }
    
    @IBAction func couponBadgeButtonAction(_ sender: Any) {
        if (loyaltyBadge._couponCount > 0) {
            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_deals_for_you_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyBanner"))

            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
            let vc = storyboard.instantiateViewController(withIdentifier: "LoyaltyAnalysisViewController") as! SwiftWarplyFramework.LoyaltyAnalysisViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func marketBadgeButtonAction(_ sender: Any) {
        print("Market Badge pressed!")
        // TODO: add action - open marketHistory after check
        if (self.unifiedCouponsDiscount > 0.0) {
//            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
//            firebaseEvent._eventName = "did_tap_deals_for_you_badge"
//            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
//            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
//            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyBanner"))

            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
            let vc = storyboard.instantiateViewController(withIdentifier: "MarketLoyaltyAnalysisViewController") as! SwiftWarplyFramework.MarketLoyaltyAnalysisViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func sumBannerButtonAction(_ sender: Any) {
        if (!(self.totalCouponValue == 0.0 && self.loyaltyBadge._couponCount == 0 && self.unifiedCouponsDiscount == 0.0)) {
            self.forYouExpanded = !self.forYouExpanded
            self.tableView.reloadData()
        }
    }
    
    
    @IBAction func dfyBannerButtonAction(_ sender: Any) {
        var totalCouponValue = swiftApi().getDealsCouponsSum()
        if (totalCouponValue > 0.0) {
            print("DFY coupon banner pressed!")
           // analysis_pressed event
           let dealsAnalysis = swiftApi.WarplyDealsAnalysisEventModel()
           dealsAnalysis._isPressed = true
           SwiftEventBus.post("analysis_pressed", sender: dealsAnalysis)

//            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
//            firebaseEvent._eventName = "did_tap_gifts_for_you_badge"
//            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
//            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_deals_for_you_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "DealsBanner"))
        }
    }
    
    @IBAction func gfyBannerButtonAction(_ sender: Any) {
        if (loyaltyBadge._couponCount > 0) {
//            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
//            firebaseEvent._eventName = "did_tap_deals_for_you_badge"
//            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
//            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_gifts_for_you_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyBanner"))

            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
            let vc = storyboard.instantiateViewController(withIdentifier: "LoyaltyAnalysisViewController") as! SwiftWarplyFramework.LoyaltyAnalysisViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func marketBannerButtonAction(_ sender: Any) {
        if (self.unifiedCouponsDiscount > 0.0) {
            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_market_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "MarketBanner"))

            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
            let vc = storyboard.instantiateViewController(withIdentifier: "MarketLoyaltyAnalysisViewController") as! SwiftWarplyFramework.MarketLoyaltyAnalysisViewController
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    @IBAction func dfyActiveCouponsBannerButtonAction(_ sender: Any) {
        print("Active DFY coupon banner Tapped!")
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveDealsBanner"))
        
        let couponDetails = swiftApi.ActiveDFYCouponEventModel()
        couponDetails._isPressed = true
        SwiftEventBus.post("dfy_coupon_details", sender: couponDetails)
    }
    
    @IBAction func smActiveCouponsBannerButtonAction(_ sender: Any) {
        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "did_tap_market_active_badge"
        firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
        SwiftEventBus.post("firebase", sender: firebaseEvent)
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveMarketBanner"))
        
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
        let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponsViewController") as! SwiftWarplyFramework.UnifiedCouponsViewController
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    @IBAction func gfyActiveCouponsBannerButtonAction(_ sender: Any) {
        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
        firebaseEvent._eventName = "did_tap_gifts_for_you_active_badge"
        firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
        SwiftEventBus.post("firebase", sender: firebaseEvent)
        
        swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveLoyaltyBanner"))
        
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: SwiftWarplyFramework.CouponsViewController.self))
        if let vc = storyboard.instantiateViewController(withIdentifier: "CouponsViewController") as? SwiftWarplyFramework.CouponsViewController{
            self.navigationController?.pushViewController(vc,animated: true)
        }
    }
    
}

// MARK: - TableView
extension WalletViewController: UITableViewDelegate, UITableViewDataSource{
    
    public func numberOfSections(in tableView: UITableView) -> Int {
//        return 4
        return 5
    }
    
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        if (section == 0) {
//            // TODO: Uncomment when UnifiedCoupons will be shown again
////            if (self.totalCouponValue == 0.0 && self.loyaltyBadge._couponCount == 0 && self.unifiedCouponsDiscount == 0.0) {
////                return 0
////            } else {
//                return 1
////            }
//        } else if (section == 1) {
//            return self.unifiedCoupons.count
//        } else if (section == 2) {
//            if (self.dfyCoupons.count > 0) {
//                return 1
//            } else {
//                return 0
//            }
//        } else if (section == 3) {
//            return self.coupons.count
//        } else {
//            return 0
//        }
        
        if (section == 0) {
//            TODO: Uncomment if we want to hide empty tiles again
//            let sumRedeemed = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
//            if (self.dfyCoupons.count > 0 || self.unifiedCoupons.count > 0 || self.coupons.count > 0 || sumRedeemed > 0.0) {
                return 1
//            } else {
//                return 0
//            }
        } else if (section == 1) {
//            TODO: Uncomment if we want to show emptyView again
//            if (self.showEmptyView == true) {
//                return 1
//            } else {
                return 0
//            }
        } else if (section == 2) {
            return 1
        } 
//        else if (section == 2) {
//            let sumRedeemed = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
//            if (sumRedeemed > 0.0) {
//                return 1
//            } else {
//                return 0
//            }
//        } 
        else if (section == 3) {
            if (swiftApi().getShowVouchersBanner() == "true" || swiftApi().getShowVouchersBanner() == "false") {
                return 1
            } else {
                return 0
            }
        } else if (section == 4) {
            if (self.showSpinner == true) {
                return 1
            } else {
                return 0
            }
        } else {
            return 0
        }
    }
    
    public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        if (indexPath.section == 0) {
//            // TODO: Uncomment when UnifiedCoupons will be shown again
////            if (self.totalCouponValue == 0.0 && self.loyaltyBadge._couponCount == 0 && self.unifiedCouponsDiscount == 0.0) {
////                return 0.0
////            } else {
//                return UITableView.automaticDimension
////            }
//        } else if (indexPath.section == 1) {
//            if (self.unifiedCoupons.count > 0) {
//                return 130.0 + 8.0
//            } else {
//                return 0.0
//            }
//        } else if (indexPath.section == 2) {
//            if (self.dfyCoupons.count > 0) {
//                return UITableView.automaticDimension
//            } else {
//                return 0.0
//            }
//
//        } else if (indexPath.section == 3) {
//            if (self.coupons.count > 0) {
//                return 130.0 + 8.0
//            } else {
//                return 0.0
//            }
//        } else {
//            return 0.0
//        }
        
        if (indexPath.section == 0) {
//            TODO: Uncomment if we want to hide empty tiles again
//            let sumRedeemed = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
//            if (self.dfyCoupons.count > 0 || self.unifiedCoupons.count > 0 || self.coupons.count > 0 || sumRedeemed > 0.0) {
                return UITableView.automaticDimension
//            } else {
//                return 0.0
//            }
        } else if (indexPath.section == 1) {
//            TODO: Uncomment if we want to show emptyView again
//            if (self.showEmptyView == true) {
//                return UITableView.automaticDimension
//            } else {
                return 0.0
//            }
        } else if (indexPath.section == 2) {
            return UITableView.automaticDimension
        } 
//        else if (indexPath.section == 2) {
//            let sumRedeemed = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
//            if (sumRedeemed > 0.0) {
//                return UITableView.automaticDimension
//            } else {
//                return 0.0
//            }
//        } 
        else if (indexPath.section == 3) {
            if (swiftApi().getShowVouchersBanner() == "true" || swiftApi().getShowVouchersBanner() == "false") {
                return UITableView.automaticDimension
            } else {
                return 0.0
            }
        } else if (indexPath.section == 4) {
            if (self.showSpinner == true) {
                return UITableView.automaticDimension
            } else {
                return 0.0
            }
        } else {
            return 0.0
        }
    }
    
    public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//        if (section == 0){
//            return nil
//
//        } else if (section == 1) {
//            if (self.unifiedCoupons.count > 0) {
//                let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 75))
//                 view.backgroundColor =  .clear
//
//                let titleLabel = UILabel(frame: CGRect(x: 20, y: 40, width: view.frame.width - 40, height: 20))
//                titleLabel.font = UIFont(name: "BTCosmo-Bold", size: 19)
//                titleLabel.textColor = UIColor(red: 0.00, green: 0.65, blue: 0.89, alpha: 1.00)
//                titleLabel.text = "SUPERMARKET DEALS"
//
//                view.addSubview(titleLabel)
//                return view
//            } else {
//                return nil
//            }
//
//
//        } else if (section == 2) {
//            if (self.dfyCoupons.count > 0) {
//                let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 65))
//                 view.backgroundColor = .clear
//
//                let imageView = UIImageView(frame: CGRect(x: 20, y: 30, width: view.frame.width / 2, height: 25))
//                imageView.contentMode = .scaleAspectFit
////                imageView.backgroundColor = .red
//
//                if let dfyHeaderImage = UIImage(named: "dfy_logo_colored", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) {
//                    imageView.image = dfyHeaderImage
//                }
//                view.addSubview(imageView)
//
//                return view
//
//            } else {
//                return nil
//            }
//
//
//        } else if (section == 3) {
//            if (self.coupons.count > 0) {
//    //            let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 71))
//                let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 65))
//                 view.backgroundColor =  .clear
//
//    //            let titleLabel = UILabel(frame: CGRect(x: 20, y: 40, width: view.frame.width - 40, height: 21))
//                let titleLabel = UILabel(frame: CGRect(x: 20, y: 30, width: view.frame.width - 40, height: 20))
//                titleLabel.font = UIFont(name: "BTCosmo-Bold", size: 19)
//                titleLabel.textColor = UIColor(red: 0.00, green: 0.65, blue: 0.89, alpha: 1.00)
//                titleLabel.text = "GIFTS FOR YOU"
//
//                view.addSubview(titleLabel)
//                return view
//            } else {
//                return nil
//            }
//
//        } else {
//            return nil
//        }
        
        if (section == 0) {
//            if (self.dfyCoupons.count > 0 || self.unifiedCoupons.count > 0 || self.coupons.count > 0) {
//                let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 70))
//                 view.backgroundColor =  .clear
//
//                let titleLabel = UILabel(frame: CGRect(x: 20, y: 20, width: view.frame.width - 40, height: 25))
////                titleLabel.font = UIFont(name: "PeridotPE-SBold", size: 21)
//                titleLabel.font = UIFont(name: "BTCosmo-Bold", size: 19)
//                titleLabel.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
//                titleLabel.text = "Κουπόνια"
//
//                view.addSubview(titleLabel)
//                return view
//            } else {
                return nil
//            }
        } else if (section == 1) {
            return nil
        } else if (section == 2) {
            return nil
        } else if (section == 3) {
//            if (swiftApi().getShowVouchersBanner() == "true" || swiftApi().getShowVouchersBanner() == "false") {
//                let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 70))
//                 view.backgroundColor =  .clear
            
//                let separatorView = UIView(frame: CGRect(x: 20, y: 25, width: tableView.frame.width - 40, height: 1))
//                separatorView.backgroundColor =  UIColor(red: 0.62, green: 0.62, blue: 0.61, alpha: 1.00)
//
//                let titleLabel = UILabel(frame: CGRect(x: 20, y: 20, width: view.frame.width - 40, height: 25))
//                titleLabel.font = UIFont(name: "PeridotPE-SBold", size: 21)
//                titleLabel.textColor = UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)
//                titleLabel.text = "Υπόλοιπο επιδότησης"
//
//                view.addSubview(titleLabel)
//                return view
//            } else {
                return nil
//            }
        } else if (section == 4) {
            return nil
        } else {
            return nil
        }

    }

    public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//        if (section == 0) {
//            return 0.0
//
//        } else if (section == 1) {
//            if (self.unifiedCoupons.count > 0) {
//                return 75.0
//            } else {
//                return 0.0
//            }
//
//        } else if (section == 2) {
//            if (self.dfyCoupons.count > 0) {
//                return 68.0
//            } else {
//                return 0.0
//            }
//
//        } else if (section == 3) {
//            if (self.coupons.count > 0) {
//                return 65.0
//            } else {
//                return 0.0
//            }
//        } else {
//            return 0.0
//        }
        
        if (section == 0) {
//            if (self.dfyCoupons.count > 0 || self.unifiedCoupons.count > 0 || self.coupons.count > 0) {
//                return 70.0
//            } else {
                return 0.0
//            }
        } else if (section == 1) {
            return 0.0
        } else if (section == 2) {
            return 0.0
        } else if (section == 3) {
//            if (swiftApi().getShowVouchersBanner() == "true" || swiftApi().getShowVouchersBanner() == "false") {
//                return 70.0
//            } else {
                return 0.0
//            }
        } else if (section == 4) {
            return 0.0
        } else {
            return 0.0
        }
    }

    public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
//        return CGFloat.leastNormalMagnitude
        return 0.0
    }

    public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return nil
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
//        if (indexPath.section == 0) {
//            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletBannersTableViewCellId", for: indexPath) as! WalletBannersTableViewCell
//            cell.configureCell(totalCouponValue: self.totalCouponValue, totalCouponDiscount: self.totalCouponDiscount, unifiedCouponsDiscount: self.unifiedCouponsDiscount, forYouExpanded: self.forYouExpanded)
//            return cell
////            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletBadgesTableViewCellId", for: indexPath) as! WalletBadgesTableViewCell
////            cell.configureCell(totalCouponValue: self.totalCouponValue, totalCouponDiscount: self.totalCouponDiscount, unifiedCouponsDiscount: self.unifiedCouponsDiscount)
////            return cell
//        } else if (indexPath.section == 1) {
//            let cell = tableView.dequeueReusableCell(withIdentifier: "UnifiedCouponsTableViewCellId", for: indexPath) as! UnifiedCouponsTableViewCell
//            cell.configureCell(coupon: unifiedCoupons[indexPath.row])
//            return cell
//
//        } else if (indexPath.section == 2) {
//            let cell = tableView.dequeueReusableCell(withIdentifier: "ActiveCodeTableViewCellId", for: indexPath) as! ActiveCodeTableViewCell
////            cell.configureCell(coupon: coupons[indexPath.row])
//            return cell
//
//        } else {
//            let cell = tableView.dequeueReusableCell(withIdentifier: "CouponsTableViewCellId", for: indexPath) as! CouponsTableViewCell
//            cell.configureCell(coupon: coupons[indexPath.row])
//            return cell
//        }
        
        
        if (indexPath.section == 0) {
            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletActiveCouponsScrollTableViewCellId", for: indexPath) as! WalletActiveCouponsScrollTableViewCell
//            cell.configureCell(dfyCount: self.dfyCoupons.count, smCount: self.unifiedCoupons.count, gfyCount: self.coupons.count, boxCount: self.boxCoupons.count)
            let smCount = self.unifiedCoupons.count + self.smCoupons.count
            cell.configureCell(dfyCount: self.dfyCoupons.count, smCount: smCount, gfyCount: self.coupons.count, boxCount: 0)
            cell.parent = self
            return cell
            
        } else if (indexPath.section == 1) {
            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletEmptyViewTableViewCellId", for: indexPath) as! WalletEmptyViewTableViewCell
            return cell
        } else if (indexPath.section == 2) {
            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletQuestionnaireBannerTableViewCellId", for: indexPath) as! WalletQuestionnaireBannerTableViewCell
                cell.configureCell(isCentered: self.showEmptyView)
            return cell
        } 
//        else if (indexPath.section == 2) {
//            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletHistoryBannerTableViewCellId", for: indexPath) as! WalletHistoryBannerTableViewCell
//            return cell
//        } 
        else if (indexPath.section == 3) {
            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletVouchersBannerTableViewCellId", for: indexPath) as! WalletVouchersBannerTableViewCell
            cell.configureCell(showSeparator: self.showActiveCouponsBanners, active: swiftApi().getShowVouchersBanner() == "true")
            return cell
        } else {
            let cell = tableView.dequeueReusableCell(withIdentifier: "WalletSpinnerTableViewCellId", for: indexPath) as! WalletSpinnerTableViewCell
            return cell
        }
        
    }
    
    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        if (indexPath.section == 0) {
//            // Do nothing
//
//        } else if (indexPath.section == 1) {
//            // TODO: Add trackers
////            let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
////            let couponName = couponSetData?.name ?? ""
////            swiftApi().logTrackersEvent("click", ("Coupon:" + couponName))
//
//            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
//            let vc = storyboard.instantiateViewController(withIdentifier: "UnifiedCouponBarcodeViewController") as! SwiftWarplyFramework.UnifiedCouponBarcodeViewController
//            vc.coupon = unifiedCoupons[indexPath.row]
//            vc.isFromWallet = true
//            self.navigationController?.pushViewController(vc, animated: true)
//
//        } else if (indexPath.section == 2) {
//            print("Active DFY coupon banner Tapped!")
//
//            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "ActiveDealsBanner"))
//
//            let couponDetails = swiftApi.ActiveDFYCouponEventModel()
//            couponDetails._isPressed = true
//            SwiftEventBus.post("dfy_coupon_details", sender: couponDetails)
//
//        }  else if (indexPath.section == 3) {
//            let couponSetData: swiftApi.CouponSetItemModel? = coupons[indexPath.row].couponset_data
//            let couponName = couponSetData?.name ?? ""
//            swiftApi().logTrackersEvent("click", ("Coupon:" + couponName))
//
//            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
//            let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! SwiftWarplyFramework.CouponBarcodeViewController
//            vc.coupon = coupons[indexPath.row]
//            vc.isFromWallet = true
//            self.navigationController?.pushViewController(vc, animated: true)
//        } else {
//            // Do nothing
//        }
        
        if (indexPath.section == 0) {
            // Do nothing - Each button is handled differently
            
        } else if (indexPath.section == 1) {
            // Do nothing
        } else if (indexPath.section == 2) {
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "Questionnaire"))
            
            swiftApi().openQuestionnaire(self);
            
        } 
//        else if (indexPath.section == 2) {
//            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
//            firebaseEvent._eventName = "did_tap_history_badge"
//            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
//            SwiftEventBus.post("firebase", sender: firebaseEvent)
//            
//            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyHistoryBadge"))
//            
//            let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
//            let vc = storyboard.instantiateViewController(withIdentifier: "LoyaltyHistoryViewController") as! SwiftWarplyFramework.LoyaltyHistoryViewController
//            self.navigationController?.pushViewController(vc, animated: true)
//            
//        } 
        else if (indexPath.section == 3) {
            let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
            firebaseEvent._eventName = "did_tap_vouchers_badge"
            firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
            SwiftEventBus.post("firebase", sender: firebaseEvent)
            
            swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "VouchersBadge"))
            
            SwiftEventBus.post("vouchers_banner_pressed")
            
        } else if (indexPath.section == 4) {
            // Do nothing
        } else {
            // Do nothing
        }
        
    }
}