// Controller 是基类，用于各种根窗口或者非应用程序预览窗口的窗口, 实现了设计文档中预览窗口类中的大部分函数的转发接口；
// TabletAppController 是应用程序预览窗口控制器类，实现了点击窗口时激活的接口和删除应用程序预览窗口的接口。
// ClearAllController 是全部清除按钮控制器类，实现了清除所有窗口的接口和设置按钮按下状态的接口。
// 控制器基类
class Controller {
    constructor(model, view, manager, acceptedTypeSet) {
        this.model = model;
        this.view = view;
        this.manager = manager;
        this.acceptedTypeSet = acceptedTypeSet;
    }

    initViewAnimation() {
        // default screen is 0
        if (this.model.getAppWindowList(this.model.getCurrentDesktop(), 0).length === 0)
        {
            // no app window
            // calling no window animation
            this.view.startNoWindowTipsAnimation();
            // view will call disappear animation itself.
            // view will call close function then.
        }
        else
        {
            // call AllClear Button animation
            this.view.startSequentialLoadWindowTimer();
        }
    }

    //点击空白处关闭多任务视图
    viewSpacingClickedController()
    {
        if (this.model.isTabletMode) {
            this.manager.showDesktop(true);
        }
        this.view.viewSpacingClickedController()
    }

    // 关闭多任务视图
    closeMultitaskView() {
         this.manager.close();
    }

    // 窗口点击事件处理
    onWindowClicked(windowId) {
    }

    startClearAllBtnDisappearAni()
    {
        this.view.startClearAllBtnDisappearAni();
    }

    // 删除预览窗口
    removePreviewWindow(windowId) {}

    // 设置默认态
    setDefaultStatus() {
        this.view.setDefaultStatus();
    }

    // 设置 Hover 态
    setHoverStatus() {
        this.view.setHoverStatus();
    }

    //设置长按状态
    setPressStatus()
    {
        this.view.setHoverStatus();
    }

    // 设置拖拽态
    setDragStatus() {
        this.view.setDragStatus();
    }

    // 设置拖拽接收态
    setReceiveStatus() {
        this.view.setReceiveStatus();
    }

    startSpaceClickedPreWindowAnimation()
    {
        this.view.startSpaceClickedPreWindowAnimation();
    }
}

class TabletAppController extends Controller {
    constructor(model, view, manager, acceptedTypeSet) {
        super(model, view, manager, acceptedTypeSet);
    }

    // 窗口点击事件处理
    onWindowClicked(windowId) {
        // activate windowId
        this.model.activateAppWindow(windowId);
        if (this.model.isTabletMode)
        {
            this.view.startActiveWindowAnimation();
            // view will call close function
        }
    }

    // 向上滑动确认关闭
    slideUpCloseWindow() {
        this.view.startCloseWindowAnimation();
    }

    // 向上滑动取消关闭
    startResumeWindowAnimation() {
        this.view.startResumeWindowAnimation();
    }

    // 删除预览窗口
    removePreviewWindow(windowId) {
        if (this.model.hasModalChildWindow(windowId))
        {
            this.onWindowClicked(windowId);
            // If window has modal child window,
            // controller calls close force.
            this.closeMultitaskView();
        }
        else
        {
            // delete app
            this.model.removeAppWindow(windowId);
        }
    }

    startClearAllWindowAnimation(/*unused*/) {
        this.view.startClearAllWindowAnimation();
    }

    removeAppWindowOnDesktop()
    {
        this.model.removeAllAppWindowOnDesktop(this.model.getCurrentDesktop());
        this.closeMultitaskView();
    }
}

class CloseButtonController extends Controller {
    constructor(model, view, manager, acceptedTypeSet) {
        super(model, view, manager, acceptedTypeSet);
    }
}

class ClearAllController extends Controller {
    constructor(model, view, manager, acceptedTypeSet) {
        super(model, view, manager, acceptedTypeSet);
    }

    // 窗口点击事件处理
    onWindowClicked(/*unused*/) {
        this.view.startClearAllWindowAnimation();
    }
    removeAllAppWindowOnDesktop()
    {
        this.model.removeAllAppWindowOnDesktop(this.model.getCurrentDesktop());
        this.closeMultitaskView();
    }

    // 窗口按下事件处理
    setPressStatus() {
        this.view.setPressStatus();
    }
}
