class Card {
    constructor(picItem, cardId) {
        this.cardId = cardId;
        this.type = CardManager.TYPE_IMG;
        this.right = picItem.radioValue == "1";
        this.img = picItem.pic_url;
        this.audio = picItem.audio_url;
    }
}
class CardManager {
    static TYPE_NULL = 0;
    static TYPE_TXT = 1;
    static TYPE_IMG = 2;
    static TYPE_MP3 = 3;

    static instance;
    static getIns() {
        if (!CardManager.instance) CardManager.instance = new CardManager();
        return CardManager.instance;
    }
    _cardArray;//所有卡片的组
    testletId;//组id
    pageId;//页id
    constructor() {
        this._cardArray = [];//组 页 
        this._audio_url = "";
        this.testletId = 0;
        this.pageId = 0;
    }
    initCards(obj) {
        console.log(obj);
        let picArr = obj.contentObj.picArr;
        let id = 0;
        this._cardArray = picArr.list.map(cd => {
            return new Card(cd, id++);
        });
        this._audio_url = picArr.audio_url
    }
    getTestlet() {
        return this._cardArray.length - 1;
    }
    getPage() {
        return this._cardArray;
    }
    getAudio() {
        return this._audio_url;
    }
    allRightNum() {
        return this._cardArray.filter(c => c.right).length;
    }
    addPageNum() {
        this.pageId++;
        if (!this.getPage()) {
            this.pageId = 0;
            this.testletId++;
            if (!this.getPage()) {
                return 2;//游戏结束
            }
            return 1;//组结束
        } else {
            return 0;//页结束
        }
    }
    resetPageNum() {
        this.testletId = 0;
        this.pageId = 0;
    }
    randomPageCards() {
        //页面内部数字要打乱   0 1 2 3 4 5 6 7 8  每次动态取出一个值 然后动态处理
        let arr = [];
        while (this._cardArray.length > 0) {
            let rand = Math.floor(Math.random() * this._cardArray.length);
            arr.push(this._cardArray[rand]);
            this._cardArray.splice(rand, 1);
        }
        this._cardArray = arr;
    }
}
export default CardManager;