GiftsViewController.swift 23.1 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
//
//  GiftsViewController.swift
//  swift_example
//
//  Created by Manos Chorianopoulos on 5/5/22.
//

import UIKit
import SwiftWarplyFramework

@objc public class GiftsViewController: UIViewController {
    @IBOutlet weak var mainView: UIView!
    @IBOutlet weak var tableView: UITableView!
    
    public var coupons:Array<swiftApi.CouponItemModel> = []
    public var couponSets:Array<swiftApi.CouponSetItemModel> = []
    public var campaigns:Array<swiftApi.CampaignItemModel> = swiftApi().mergeGFYCCMSLoyaltyCampaigns(campaigns: swiftApi().getCCMSLoyaltyCampaigns())
    // TODO: ADD
    public var seasonalList:Array<swiftApi.LoyaltyGiftsForYouPackage> = swiftApi().getSeasonalList()
    
//    var response:swiftApi.VerifyTicketResponseModel?
    // var profile: swiftApi.ProfileModel?
    
    let uiscreen: CGRect = UIScreen.main.bounds
    
    let hasOpenedGifts = UserDefaults.standard.bool(forKey: "hasOpenedGifts")
    
    // if(!hasOpenedGifts)
    // UserDefaults.standard.set(true, forKey: "hasOpenedGifts")

    public override func viewDidLoad() {
        super.viewDidLoad()
        
        self.hidesBottomBarWhenPushed = true
        
        // TODO: DELETE ===>
        let seasonal1 = swiftApi.LoyaltyGiftsForYouPackage()
        seasonal1._title = "test1"
        seasonal1._imageUrl = "https://warply.s3.amazonaws.com/artworks/ea0f7ca82b2e478394c4608c213f7c10/default.png"
        seasonal1._loyaltyPackageId = "id1"
        
        let seasonal2 = swiftApi.LoyaltyGiftsForYouPackage()
        seasonal2._title = "test2"
        seasonal2._imageUrl = "https://warply.s3.amazonaws.com/artworks/ea0f7ca82b2e478394c4608c213f7c10/default.png"
        seasonal2._loyaltyPackageId = "id2"
        
        let seasonalArray:Array<swiftApi.LoyaltyGiftsForYouPackage> = [seasonal1, seasonal2]
        swiftApi().setSeasonalList(seasonalArray)
        // TODO: DELETE <===
        
        // TODO: ADD
        if (seasonalList.count > 0) {
            for seasonalItem in seasonalList {
                let newCampaign = swiftApi.CampaignItemModel()
                newCampaign._title = seasonalItem._title
                newCampaign._logo_url = seasonalItem._imageUrl
                newCampaign._loyaltyPackageId = seasonalItem._loyaltyPackageId
                campaigns.append(newCampaign)
            }
        }
        
        
//        getCouponsRequest()
//        getCouponSetsRequest()
        // TODO: DELETE
//        getCampaignsRequest()
//        getProfileRequest()
//        verifyTicketAsyncRequest(guid: "6009615311", ticket: "eyJraWQiOiIxNSIsInR5cCI6IkpXVCIsImFsZyI6IlJTNTEyIn0.eyJhdWQiOiJnYXBwIiwic3ViIjoiNjAwOTYxNTMxMSIsInVzZXJJbmZvIjp7Imd1aWQiOiI2MDA5NjE1MzExIiwiZW1haWwiOiJkaW1pdHJpc2trQHdhcnAubHkiLCJmaXJzdG5hbWUiOiJUZXN0IiwibGFzdG5hbWUiOiJUZXN0Iiwib3RlUG9ydGFsU3RhdHVzIjoiMSIsIm90ZVBvcnRhbGlzQ29ycG9yYXRlIjoiMCIsIm90ZVBvcnRhbFVzZXJMZXZlbCI6InJlc2lkZW50aWFsIiwib3RlZ3JvdXBQYXNzd29yZERhdGUiOiIyMDIxLTA2LTA4Iiwib3RlZ3JvdXBTdGF0dXMiOiJhY3RpdmUiLCJvdGVncm91cFJlZ2lzdHJhdGlvbkRhdGUiOiIyMDIwLTA1LTE2Iiwib3RlZ3JvdXBBbHRlcm5hdGl2ZU1TSVNETiI6IjY5Nzg0NTMwNDUiLCJleHRndWlkIjoiMEo5bDJMUklqRngxTnJOcDRmRWJ4Zz09IiwiaW1hZ2VVUkwiOiJodHRwczovL2FjY291bnQuY29zbW90ZS5nci9pbWFnZS91c2VyX2ZlbWFsZV9wb3J0cmFpdD9pbWdfaWQ9MCZpbWdfaWRfdG9rZW49Tk9jckh2eEc5cCUyQmR0SVJWV3ZGc0VsM0k5SVklM0QmdD0xNjUxNzIwMjQ2NjA0IiwiY29udGFjdEluZm9FbWFpbFJlc3AiOltdLCJjb250YWN0SW5mb1Bob25lUmVzcCI6W10sInNob3dEYXRhUmVtaW5kZXIiOmZhbHNlLCJ2ZXJpZmllZFJlY0RhdGEiOnRydWV9LCJuYmYiOjE2NTIxMDA5OTEsInJvbGVzIjpbXSwic2NvcGUiOlsidXNlckluZm8iLCJzZXJ2aWNlcyIsInJvbGVzIl0sImtpZCI6MTUsImlzcyI6IlBVQkxJQ19DQUxMRVIiLCJzZXJ2aWNlcyI6W10sImV4cCI6MTY1MjEwMjc5MSwiaWF0IjoxNjUyMTAwOTkxfQ.ORJuVx-ggFL-hHcioyKI7GYUDufRd8oY7EJrCYMR6HnGKZAQF-eQe62MdFZpqi2vqUQs3ga8496EK344vDfkEV9hhEZDhK-1LXMNY24MBe_ssIxGG5zzb-sRSeGvWGYEIr6yme6LQ0Dn8-93I-mvxfxrPzHQiSeGi7KkJENxTtyIhoe3qIj-0a-dcdOYzzQDDJGIMVINv89iNBaxj6wFA4Z6B307vgeJzBJkPsV3xclRHNofATBnpBFKdJIizA-OpAFtnLux7YQcbEyM0SuQMn9BnQhnXa7LXK1yXbEe6rlNoIbrP9Hp_WRR2ezY2LnfOm60eQ9PiGepxtvHiZsYTg")

        setBackButton()
        setNavigationTitle("GIFTS for YOU")
        
        tableView.delegate = self
        tableView.dataSource = self
        
        tableView.clipsToBounds = true
        tableView.layer.cornerRadius = 30
        tableView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
        tableView.contentInset.top = 50
        
//        setNavRightButton(false)
        
        // Add Linear Gradient
//        let gradient = CAGradientLayer()
//        gradient.frame = mainView.bounds
//        gradient.colors = [UIColor(red: 0.10, green: 0.68, blue: 0.80, alpha: 1.00).cgColor, UIColor(red: 0.43, green: 0.74, blue: 0.48, alpha: 1.00).cgColor]
//        gradient.startPoint = CGPoint(x: 0.5, y: 0)
//        gradient.endPoint = CGPoint(x: 0.5, y: 1)
//        mainView.layer.insertSublayer(gradient, at: 0)
        
        // Add Top left corner radius
        mainView.clipsToBounds = true
        mainView.layer.cornerRadius = 30
        mainView.layer.maskedCorners = [ .layerMinXMinYCorner] // Top left corner radius
        mainView.backgroundColor = UIColor(red: 0.22, green: 0.32, blue: 0.40, alpha: 1.00)
        
    }
    
    
    // Add navigation right button
//    func setNavRightButton(_ isSelected: Bool) -> (){  //  -> UIButton
//        // Location Button
//        let locationButton = UIButton(type: UIButton.ButtonType.custom) as UIButton
//        locationButton.frame = CGRect(x: 0, y: 0, width: self.uiscreen.height * 0.04, height: self.uiscreen.height * 0.04)
//        locationButton.setBackgroundImage(UIImage(named:"location_icon"), for: UIControl.State())
//
//        locationButton.translatesAutoresizingMaskIntoConstraints = false
//        // Add width, height constraints
//        let widthContraints =  NSLayoutConstraint(item: locationButton, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: self.uiscreen.height * 0.04)
//        let heightContraints = NSLayoutConstraint(item: locationButton, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: nil, attribute: NSLayoutConstraint.Attribute.notAnAttribute, multiplier: 1, constant: self.uiscreen.height * 0.04)
//        NSLayoutConstraint.activate([heightContraints,widthContraints])
//
//        locationButton.addTarget(self, action: #selector(self.locationButtonTapped(_:)), for: .touchUpInside)
//        let LocationButtonItem: UIBarButtonItem = UIBarButtonItem(customView: locationButton)
//        self.navigationItem.setRightBarButton(LocationButtonItem, animated: false)
//
////        Add an array of items at the  right of the nav bar
////        self.navigationItem.setRightBarButtonItems([LocationButtonItem], animated: false)
////        return locationButton
//    }
    
    func getCouponsRequest() {
        swiftApi().getCouponsAsync(getCouponsCallback)
    }
    
    func getCouponsCallback (_ couponsData: Array<swiftApi.CouponItemModel>?) -> Void {
        if (couponsData != nil) {
            let activeCouponData = swiftApi().filterActiveCoupons(couponsData ?? [])
            
            self.coupons = activeCouponData
            
            DispatchQueue.main.async {
//                self.tableView.reloadData()
                
                // TODO: Rerender screen
                
                print("========= DispatchQueue couponsData SUCCESSSS =========")
                print(activeCouponData)
                print("========= DispatchQueue couponsData SUCCESSSS =========")
            }
        } else {
            self.coupons = []
        }
    }
    
    
    func getCouponSetsRequest() {
        swiftApi().getCouponSetsAsync(getCouponSetsCallback)
    }

    func getCouponSetsCallback (_ couponSetsData: Array<swiftApi.CouponSetItemModel>?) -> Void {
        if (couponSetsData != nil) {
            
            self.couponSets = couponSetsData ?? []
            
            DispatchQueue.main.async {
//                self.tableView.reloadData()
                
                // TODO: Rerender screen
                
                print("========= DispatchQueue couponSetsData SUCCESSSS =========")
                print(couponSetsData)
                print("========= DispatchQueue couponSetsData SUCCESSSS =========")
            }
        } else {
            self.couponSets = []
        }
    }
    
    
    // TODO: DELETE =====>
    func getCampaignsRequest() {
        swiftApi().getCampaignsAsync(getCampaignsCallback)
    }
    
    func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void {
        if (campaignsData != nil) {
            
            
            DispatchQueue.main.async {
                // TODO: Rerender screen
                swiftApi().setUniqueCampaignList(campaignsData ?? [])
                
                
                // TODO: DELETE TESTING ===>
                let ccmsCampaign1 = swiftApi.LoyaltyContextualOfferModel(sessionId: "", eligibleAssets: [], id: "", businessAdditionalId: "", treatmentCode: "", offerName: "", productType: "", provDuration: "", noOfRecurrance: "", price: "", discount: "", voiceCategory: "", dataCategory: "", minsValue: "", dataValue: "", provStepValueMins: "", postpayProduct: "", notificationMessage: "", loyaltyCampaignId: "1", businessService: "", uaciOfferTrackingCode: "", offerCode1: "", score: "", zone: "", wave: "", validity: "", offerAudienceLevel: "")
                let ccmsCampaign2 = swiftApi.LoyaltyContextualOfferModel(sessionId: "", eligibleAssets: ["1","2","3"], id: "", businessAdditionalId: "", treatmentCode: "", offerName: "", productType: "", provDuration: "", noOfRecurrance: "", price: "", discount: "", voiceCategory: "", dataCategory: "", minsValue: "", dataValue: "", provStepValueMins: "", postpayProduct: "", notificationMessage: "", loyaltyCampaignId: "8eb71c4ceaff409c896e2d1f6f1c20f3", businessService: "", uaciOfferTrackingCode: "", offerCode1: "", score: "", zone: "", wave: "", validity: "", offerAudienceLevel: "")
                let ccmsCampaignsArray: Array<swiftApi.LoyaltyContextualOfferModel> = [ccmsCampaign1, ccmsCampaign2]
                swiftApi().setCCMSLoyaltyCampaigns(campaigns: ccmsCampaignsArray)
                // TODO: DELETE TESTING <===
                
                self.campaigns = swiftApi().getCampaignList().filter { $0.offer_category == "gifts_for_you" }

                for campaign in self.campaigns {
                    print("================")
                    print(campaign.session_uuid)
                    print(campaign.ccms_offer)
                    print(campaign.title)
                }
//                self.campaigns = campaignsData?.filter {
//                    let tempCampaign = $0
//                    let isGFY = tempCampaign.offer_category == "gifts_for_you"
//                    let hasExtraFields = (tempCampaign.hasExtraFields != nil) && (tempCampaign.hasExtraFields == true)
//                    let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
//
//                    let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
//                    let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == tempCampaign.session_uuid }
//                    return isGFY && (!hasExtraFields || (isCcmsOffer && loyaltyCampaignIdExists))
//
//                } ?? []
                
//                swiftApi().openQuestionnaire(self)
                
                print("========= DispatchQueue campaignsData SUCCESSSS =========")
                print(campaignsData)
                print("========= DispatchQueue campaignsData SUCCESSSS =========")
                print("========= getCampaignList =========")
                print(swiftApi().getCampaignList())
                print("========= getCampaignList =========")
                print("========= getCampaignList count =========")
                print(swiftApi().getCampaignList().filter { $0.offer_category == "gifts_for_you" }.count)
                print("========= getCampaignList count =========")
                
                
                // TODO: DELETE ===>
                let seasonal1 = swiftApi.LoyaltyGiftsForYouPackage()
                seasonal1._title = "test1"
                seasonal1._imageUrl = "https://warply.s3.amazonaws.com/artworks/ea0f7ca82b2e478394c4608c213f7c10/default.png"
                seasonal1._loyaltyPackageId = "id1"
                
                let seasonal2 = swiftApi.LoyaltyGiftsForYouPackage()
                seasonal2._title = "test2"
                seasonal2._imageUrl = "https://warply.s3.amazonaws.com/artworks/ea0f7ca82b2e478394c4608c213f7c10/default.png"
                seasonal2._loyaltyPackageId = "id2"
                
                let seasonalArray:Array<swiftApi.LoyaltyGiftsForYouPackage> = [seasonal1, seasonal2]
                swiftApi().setSeasonalList(seasonalArray)
                self.seasonalList = swiftApi().getSeasonalList()
                
                if (self.seasonalList.count > 0) {
                    for seasonalItem in self.seasonalList {
                        let newCampaign = swiftApi.CampaignItemModel()
                        newCampaign._title = seasonalItem._title
                        newCampaign._logo_url = seasonalItem._imageUrl
                        self.campaigns.append(newCampaign)
                    }
                }
                // TODO: DELETE <===
                
                self.tableView.reloadData()
                    
            }
        } else {
            self.campaigns = []
        }
    }
    // TODO: DELETE <=====
    
    
    func getProfileRequest() {
        swiftApi().getProfileAsync(getProfileCallback)
    }

    func getProfileCallback (_ profileData: swiftApi.ProfileModel?) -> Void {
        if (profileData != nil) {
            
        //    self.profile = profileData ?? nil
            
            DispatchQueue.main.async {
//                self.tableView.reloadData()
                
                // TODO: Rerender screen
                
                print("========= DispatchQueue profileData SUCCESSSS =========")
                print(profileData)
                print("========= DispatchQueue profileData SUCCESSSS =========")
            }
        } else {
        //    self.profile = nil
        }
    }
    
    
    
    func verifyTicketAsyncRequest(guid: String, ticket: String) {
        swiftApi().verifyTicketAsync(guid: guid, ticket: ticket, verifyTicketCallback)
    }

    func verifyTicketCallback (_ verifyTicketData: swiftApi.VerifyTicketResponseModel?) -> Void {
        if (verifyTicketData != nil) {
            
        //    self.response = verifyTicketData
            
            DispatchQueue.main.async {
//                self.tableView.reloadData()
                
                // TODO: Rerender screen
                
                print("========= DispatchQueue verifyTicketData SUCCESSSS =========")
                print(verifyTicketData)
                print("========= DispatchQueue verifyTicketData SUCCESSSS =========")
//                self.response = verifyTicketData
                print("========= DispatchQueue verifyTicketData SUCCESSSS =========")
                print(verifyTicketData?.getResult ?? "")
                print(verifyTicketData?.getStatus ?? "")
//                print(self.response.result ?? "")
//                print(verifyTicketData?["result"] ?? "")
                print("========= DispatchQueue verifyTicketData SUCCESSSS =========")
            }
        } else {
        //    self.response = nil
        }
    }
    
    
    
    /// Get Accounts
//    func getCouponsRequest(){
////        progress.showLoader(onView: self.view, isNeedBlueSpinner: true)
//        
////        var coupons = swiftApi().getCoupons()
//        
//        
//        AccountsModel.sharedInstance.getAccounts(){(result) in
////            DispatchQueue.main.async {
////                self.progress.dismissLoader()
////            }
//            
//            if let response = result {
//                if(response.statusId == "1"){
//                    self.accounts = response.accounts
//
//                    DispatchQueue.main.async {
//                        self.tableView.reloadData()
//                    }
//                }
//            }
//            
//        }
//    }
    

    
    // MARK: - Actions
    @objc func locationButtonTapped(_ sender: Any) {
        print("Location Button Tapped!")
    }

}

// MARK: - TableView
extension GiftsViewController: UITableViewDelegate, UITableViewDataSource{
    
    public func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.campaigns.count
    }
    
    public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 140.0 + 10.0
//        return UITableViewAutomaticDimension
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "InboxTableViewCellId", for: indexPath) as! InboxTableViewCell
        
        cell.configureCell(campaign: campaigns[indexPath.row])
        
        return cell
    }
    
    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        // TODO: DELETE - TEST SwiftEventBus
//        SwiftEventBus.post("couponBarcodePressed", sender: coupons[indexPath.row])

        // firebase event
//        let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
//        firebaseEvent._eventName = "abc"
//        firebaseEvent.setParameter = ("1", "asd")
//        SwiftEventBus.post("firebase", sender: firebaseEvent)
//
//        // ccms event
//        let ccms = swiftApi.LoyaltyContextualOfferModel()
//        SwiftEventBus.post("ccms", sender: ccms)
//
//        // gifts event
//        let gift = swiftApi.LoyaltyGiftsForYouOfferClickEvent()
//        gift._title = "testTitle"
//        SwiftEventBus.post("gifts", sender: gift)
        
//        // pacing_visible event
//        let pacingEvent = swiftApi.WarplyPacingCardEventModel()
//        pacingEvent._isVisible = true
//        SwiftEventBus.post("pacing_visible", sender: pacingEvent)
        
//        // pacing_service event
//        let pacingService = swiftApi.WarplyPacingCardServiceEnabledModel()
//        pacingService._isEnabled = true
//        SwiftEventBus.post("pacing_service", sender: pacingService)
        
//        // analysis_pressed event
//        let dealsAnalysis = swiftApi.WarplyDealsAnalysisEventModel()
//        dealsAnalysis._isPressed = true
//        SwiftEventBus.post("analysis_pressed", sender: dealsAnalysis)
        
//        // ccms_enabled event
//        let ccmsEnabled = swiftApi.WarplyCCMSEnabledModel()
//        ccmsEnabled._isActivated = true
//        SwiftEventBus.post("ccms_enabled", sender: ccmsEnabled)
        // ===
        
        // TODO: navigate to CouponBarcode
        
//       let storyboard = UIStoryboard(name: "Main", bundle: nil)
//       let vc = storyboard.instantiateViewController(withIdentifier: "CouponBarcodeViewController") as! CouponBarcodeViewController
//       vc.coupon = coupons[indexPath.row]
//       self.navigationController?.pushViewController(vc, animated: true)
        
//        openQuestionnaire(self)
        
        // CouponViewController
//        let storyboard = UIStoryboard(name: "Main", bundle: nil)
//        let vc = storyboard.instantiateViewController(withIdentifier: "CouponViewController") as! CouponViewController
//        vc.couponset = coupons[indexPath.row].couponset_data
//        self.navigationController?.pushViewController(vc, animated: true)
        
//        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
//        let vc = storyboard.instantiateViewController(withIdentifier: "CouponViewController") as! CouponViewController
//        vc.couponset = couponSets[indexPath.row]
//        self.navigationController?.pushViewController(vc, animated: true)
        
       // TODO: ADD
        if (campaigns[indexPath.row].session_uuid != nil && campaigns[indexPath.row].session_uuid != "") {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "CampaignWebviewViewController") as! CampaignWebviewViewController
            var url = ""
   //        let hasExtraFields = (campaigns[indexPath.row].hasExtraFields != nil) && (campaigns[indexPath.row].hasExtraFields == true)
           let isCcmsOffer = (campaigns[indexPath.row].ccms_offer != nil) && (campaigns[indexPath.row].ccms_offer != "") && (campaigns[indexPath.row].ccms_offer == "true")
   //         let hasLoyaltyCampaignId = campaigns[indexPath.row].loyaltyCampaignId != nil && campaigns[indexPath.row].loyaltyCampaignId != ""
           
           if (isCcmsOffer) {
               let ccmsCampaigns = swiftApi().getCCMSLoyaltyCampaigns()
               let loyaltyCampaignIdExists = ccmsCampaigns.contains { $0._loyaltyCampaignId == campaigns[indexPath.row].session_uuid }

               if (loyaltyCampaignIdExists == true) {
                   var ccmsCampaignFound:swiftApi.LoyaltyContextualOfferModel = swiftApi.LoyaltyContextualOfferModel()
                   for item in ccmsCampaigns {
                       if (item._loyaltyCampaignId == campaigns[indexPath.row].session_uuid) {
                           ccmsCampaignFound = item
                       }
                   }
                   url = swiftApi().constructCcmsUrl(campaigns[indexPath.row], ccmsCampaignFound)
               } else { // will never enter
                   url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
               }

           } else {
               url = swiftApi().constructCampaignUrl(campaigns[indexPath.row])
           }
            
   //         let url = swiftApi().constructCampaignUrlForShare("5765a6aa4a604fa39a70bd4a0af6f53e", "12345")

   // //        vc.campaignUrl = "https://www.google.com"
            
            print("==== url ====")
            print(url)
            print("CampaignUrl url onclick: " + url)
            vc.campaignUrl = url
            self.navigationController?.pushViewController(vc, animated: true)
            
        } else {
            print("===== seasonal ====")
            print(campaigns[indexPath.row]._title ?? "")
            // gifts event
            let seasonalEvent = swiftApi.LoyaltyGiftsForYouOfferClickEvent()
            seasonalEvent._title = campaigns[indexPath.row]._title ?? ""
            seasonalEvent._imageUrl = campaigns[indexPath.row]._logo_url ?? ""
            seasonalEvent._loyaltyPackageId = campaigns[indexPath.row]._loyaltyPackageId ?? ""
//            SwiftEventBus.post("seasonal", sender: seasonalEvent)
        }
        
//        let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
//        let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! CampaignViewController
//        vc.campaignUrl = "https://www.google.com"
//        self.navigationController?.pushViewController(vc, animated: true)
    }
    
}