import { _decorator, ccenum, Component, Label, Node, Vec3 } from 'cc';
import { LevelPageNavigator } from './LevelPageNavigator';
import { Level } from './Level';
import { LevelLabel } from './LevelLabel';
const { ccclass, property } = _decorator;

export enum LevelPageType
{
    Page1,
    Page2,
    Page3
}
ccenum(LevelPageType);

@ccclass('LevelPage')
export class LevelPage extends Component 
{
    @property({type: LevelPageType})
    public pageType: LevelPageType;

    @property({type: Node})
    private levelViewNodes: Node[] = [];

    @property({type: Node})
    private labelsParent: Node;

    @property({type: Vec3})
    public pagePos: Vec3;
    
    private levels: Level[];
    private levelLabels: LevelLabel[] = [];
    private levelPageNavigator: LevelPageNavigator;

    private totalLevels: number;

    public get GetTotalLevels(): number 
    {
        return this.totalLevels;
    }

    public get GetLevelLabelComps() : LevelLabel[]
    {
        return this.levelLabels;
    }

    public get GetLevelComps() : Level[]
    {
        return this.levels;
    }

    protected onLoad(): void 
    {
        this.pagePos = this.node.position;
    }

    public fn_Init(): void 
    {
        this.labelsParent.getComponentsInChildren(LevelLabel).forEach(label => this.levelLabels.push(label));

        if (this.levels == null || this.levels.length < 1)
            this.levels = new Array(this.levelViewNodes.length);

        for (let i = 0; i < this.levelViewNodes.length; i++) 
            this.levels[i] = this.levelViewNodes[i].getComponent(Level);
    }

    public fn_InitLevelPageNavigator(levelPageNavigator: LevelPageNavigator)
    {
        this.levelPageNavigator = levelPageNavigator;
    }

    public fn_UpdateLevelData()
    {
        this.levelPageNavigator.currentMiddlePage;
    }

    public fn_SetLevelsCount(levels: number) 
    {
        this.totalLevels = levels;
    }
}


