import {LocalDataControl} from "./LocalDataControl";
import { TimeUtils } from "../Time/TimeUtils";
import {UserDataInfo} from "../Data/UserDataInfo";
import { TimesTamper } from "../Time/TimesTamper";

export class DateControl{
    public static Fresh:boolean;
    
    private static ins:DateControl;
    constructor(){
        DateControl.ins = this;
    }

    public static get  Instance():DateControl
    {
        if( DateControl.ins == null )
        {
            return new DateControl();
        }
        return DateControl.ins;
    }

/************************************************************** */
    private loadUI():void {
        Laya.loader.load(["res/threeDimen/ui/button.png"], Laya.Handler.create(this, function():void {
            var button = Laya.stage.addChild(new Laya.Button("res/threeDimen/ui/button.png", "关闭HDR")) as Laya.Button;
            button.size(200, 40);
            button.labelBold = true;
            button.labelSize = 30;
            button.sizeGrid = "4,4,4,4";
            button.scale(Laya.Browser.pixelRatio, Laya.Browser.pixelRatio);
            button.pos(Laya.stage.width / 2 - button.width * Laya.Browser.pixelRatio / 2, Laya.stage.height - 60 * Laya.Browser.pixelRatio);
            button.on(Laya.Event.CLICK, this, function():void {
                var enableHDR:Boolean = this.camera.enableHDR;
                if (enableHDR)
                    button.label = "开启HDR";
                else
                    button.label = "关闭HDR";
					this.camera.enableHDR = !enableHDR;
            });
        
        }));
    }
    /************************************************ */

    public SetSelf():void
    {
        var lastday:string = LocalDataControl.Instance.getstr( UserDataInfo.lastDay )
        var nowday:string = TimeUtils.formatYearMonthDate1( TimesTamper.Instance.serverTime );
        if( lastday != nowday )
        {
            LocalDataControl.Instance.addstr( UserDataInfo.lastDay,nowday );
            DateControl.Fresh = true;
        }
        else
        {
            DateControl.Fresh = false;
        }
    }
}