class Card {
    constructor(picItem, cardId, doubuleId) {
        //单个具体内容   一对的内容   一组的内容
        this.cardId = cardId;
        this.cardDid = doubuleId;
        this.type = CardManager.TYPE_NULL;
        if (picItem.radioValue == "A") {
            if (picItem.title) {
                this.txt = picItem.title;
                this.type = CardManager.TYPE_TXT;
            }
        } else if (picItem.radioValue == "B") {
            if (picItem.pic_url) {
                this.img = picItem.pic_url;
                this.type = CardManager.TYPE_IMG;
            }
        } else if (picItem.radioValue == "C") {
            if (picItem.audio_url) {
                this.audio = picItem.audio_url;
                this.type = CardManager.TYPE_MP3;
            }
        }
        // this.type = CardManager.TYPE_MP3;
    }
    // 具体去怎么分配  按照不同的分配逻辑去走
}
//最大的星星  一二三星    卡片组  卡片对  卡片    卡片内数据
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.testletId = 0;
        this.pageId = 0;
    }
    initCards(obj) {
        console.log(obj);
        let picArr = obj.contentObj.picArr;
        this._cardArray = [];
        let doubuleId = 0;
        let cardId = 0;
        for (let m = 0; m < picArr.length; m++) {
            let testlet = [];
            for (let n = 0; n < picArr[m].length; n++) {
                let page = [];
                for (let i = 0; i < picArr[m][n].length; i++) {
                    doubuleId++;
                    let pic = picArr[m][n][i];
                    let left = pic.left;
                    let right = pic.right;
                    cardId++;
                    let card1 = new Card(left, cardId, doubuleId);
                    cardId++;
                    let card2 = new Card(right, cardId, doubuleId);
                    if (card1.type == CardManager.TYPE_NULL || card2.type == CardManager.TYPE_NULL) {
                        doubuleId--;
                        continue;
                    }
                    page.push(card1, card2);
                }
                testlet.push(page);
            }
            this._cardArray.push(testlet);
        }
    }
    getTestlet() {
        return this._cardArray.length - 1;
    }
    getPage() {
        if (this._cardArray[this.testletId] && this._cardArray[this.testletId][this.pageId]) {
            return this._cardArray[this.testletId][this.pageId];
        } else {
            return null;
        }
    }
    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 radArray = [];
        for (let m = 0; m < this._cardArray.length; m++) {
            for (let n = 0; n < this._cardArray[m].length; n++) {
                let arr = [];
                while (this._cardArray[m][n].length > 0) {
                    let rand = Math.floor(Math.random() * this._cardArray[m][n].length);
                    arr.push(this._cardArray[m][n][rand]);
                    this._cardArray[m][n].splice(rand, 1);
                }
                this._cardArray[m][n] = arr;
            }
        }
    }
}
export default CardManager;