"use strict";
var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var LotteryType_1 = require("./../../libs/tw/enum/LotteryType");
var Panel_1 = require("../views/Panel");
var DataManager_1 = require("../../libs/tw/manager/DataManager");
var NetManager_1 = require("../../libs/tw/manager/NetManager");
var panelCtrl_1 = require("../ctrls/panelCtrl");
var PrizePanel = (function (_super) {
    __extends(PrizePanel, _super);
    function PrizePanel(data) {
        var _this = _super.call(this, data) || this;
        _this.mdata = data;
        if (_this.mdata) {
            _this.lottery = _this.mdata.lottery;
        }
        return _this;
    }
    Object.defineProperty(PrizePanel.prototype, "skinKey", {
        get: function () { return 'PrizePanel'; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(PrizePanel.prototype, "groupName", {
        get: function () { return 'prize_panel'; },
        enumerable: true,
        configurable: true
    });
    PrizePanel.prototype.onSkinComplete = function () {
        _super.prototype.onSkinComplete.call(this);
        this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
        if (this.stage) {
            this.onLoad();
        }
        this.effectImg.visible = true;
        this.showAct(function () {
            this.effectImg.visible = true;
            egret.Tween.get(this.effectImg, { loop: true }).to({ rotation: 360 }, 5000);
        }.bind(this));
    };
    PrizePanel.prototype.start = function () {
        this.percentHeight = 100;
    };
    PrizePanel.prototype.initEvents = function () {
        _super.prototype.initEvents.call(this);
        this.iknowBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        if (this.mdata && this.mdata.lottery) {
            this.prizeImg.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        }
    };
    PrizePanel.prototype.removeEvents = function () {
        _super.prototype.removeEvents.call(this);
        this.iknowBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        if (this.mdata && this.mdata.lottery) {
            this.prizeImg.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        }
    };
    PrizePanel.prototype.onLoad = function () {
        return __awaiter(this, void 0, void 0, function () {
            var url, url;
            return __generator(this, function (_a) {
                if (this.mdata && this.mdata.lottery) {
                    url = this.lottery.img;
                    this.prizeNameLb.text = this.lottery.name; //511 239
                    this.prizeImg.source = url;
                    this.prizeImg.addEventListener(egret.Event.COMPLETE, function () {
                        if (this.prizeImg.width > 300) {
                            this.prizeImg.x = 88;
                            this.prizeImg.x = 307;
                            this.prizeImg.width = 511;
                            this.prizeImg.height = 239;
                        }
                        else {
                            this.prizeImg.x = 225;
                            this.prizeImg.y = 307;
                            this.prizeImg.width = 250;
                            this.prizeImg.height = 250;
                        }
                        console.log(this.prizeImg.width, this.prizeImg.height);
                    }.bind(this), this);
                }
                else {
                    url = window['prizeImg'] ? window['prizeImg'] : 'getPrizeBtn_png';
                    this.prizeNameLb.text = window['prizeName'] ? window['prizeName'] : '送你一份小礼物！';
                    this.prizeImg.source = url;
                }
                return [2 /*return*/];
            });
        });
    };
    PrizePanel.prototype.onTap = function () {
        panelCtrl_1.default.instance.btnDelay(this.iknowBtn);
        this.hidePanel();
        //获取游戏信息
        // Loading.instace.show();
        // NetManager.ins.getInfo((success: boolean) => {
        //     if (success) {
        //         if (this.mdata) {
        //             this.mdata.callback();
        //         }
        //     } else {
        //         //提示用户，返回上一层，重新进入活动？？？？？
        //         PanelCtrl.instance.showMsg('okBtn', 4, null, null, '请刷新重试！');
        //     }
        //     Loading.instace.hide();
        // });
    };
    PrizePanel.prototype.onUse = function () {
        if (this.mdata && this.mdata.lottery) {
            var lottery = this.lottery;
            // if (lottery.type == LotteryType.COUPON || lottery.type == LotteryType.LUCKY) {
            if (lottery.type == LotteryType_1.LotteryType.LUCKY) {
                window["downloadAppConfig"] =
                    {
                        openUrl: lottery.openUrl,
                        iosDownloadUrl: lottery.iosDownloadUrl,
                        androidDownloadUrl: lottery.androidDownloadUrl,
                        confirm: lottery.confirm ? lottery.confirm : false
                    };
                window["downloadApp"]();
                if (lottery.type == "lucky") {
                    NetManager_1.NetManager.ins.spmclick(DataManager_1.DataManager.ins.getPlugOrderStatusData.exposure);
                }
            }
            else {
                console.log("\u9886\u5956\u94FE\u63A5\uFF1A" + lottery.link);
                window.location.href = lottery.link;
            }
        }
        else {
            this.onTouchTap();
        }
    };
    PrizePanel.prototype.onTouchTap = function () {
        _super.prototype.onTouchTap.call(this);
        if (this['closeBtn']) {
            panelCtrl_1.default.instance.btnDelay(this['closeBtn']);
        }
        this.onTap();
    };
    return PrizePanel;
}(Panel_1.default));
exports.default = PrizePanel;
__reflect(PrizePanel.prototype, "\"/Users/chiwang/Desktop/\u5151\u5427\u5DE5\u4F5C/newGame/saolei19.03.06/db-game-template/egret/src/prizePanel/PrizePanel\".PrizePanel");
//# sourceMappingURL=PrizePanel.js.map