import { HashObject } from "../HashObject";
/**
 * 事件类,引擎中一切事件的基类
 * @class Event
 * @extends AObject
 * @public
 * @since 1.0.0
 */
export class Event extends HashObject {
    /**
     * 舞台尺寸发生变化时触发
     * @Event
     * @property RESIZE
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static RESIZE: string = "onResize";

    /**
     * Scroll组件滑动到开始位置事件
     * @property SCROLL_TO_HEAD
     * @static
     * @since 1.1.0
     * @type {string}
     */
    public static SCROLL_TO_HEAD: string = "onScrollToHead";
    /**
     * Scroll组件停止滑动事件
     * @property SCROLL_STOP
     * @static
     * @since 1.1.0
     * @type {string}
     */
    public static SCROLL_STOP: string = "onScrollStop";
    /**
     * Scroll组件开始滑动事件
     * @property SCROLL_START
     * @static
     * @since 1.1.0
     * @type {string}
     */
    public static SCROLL_START: string = "onScrollStart";
    /**
     * Scroll组件滑动到结束位置事件
     * @property SCROLL_TO_END
     * @static
     * @since 1.1.0
     * @type {string}
     */
    public static SCROLL_TO_END: string = "onScrollToEnd";
    /**
     * Scroll组件滚动时触发
     */
    public static SCROLLING: string = "onScrolling";
    /**
     * 舞台初始化完成后会触发的事件
     * @property INIT_STAGE
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static INIT_STAGE: string = "onInitStage";
    /**
     * 显示对象加入到舞台事件
     * @Event
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static ADDED_TO_STAGE: string = "onAddedToStage";
    /**
     * 显示对象从舞台移出事件
     * @Event
     * @property REMOVED_FROM_STAGE
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static REMOVED_FROM_STAGE: string = "onRemovedFromStage";
    /**
     * 显示对象 循环帧事件
     * @Event
     * @property ENTER_FRAME
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static ENTER_FRAME: string = "onEnterFrame";
    /**
     * AnimationClip 播放完成事件
     * @Event
     * @property END_FRAME
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static END_FRAME: string = "onEndFrame";
    /**
     * 完成事件
     * @Event
     * @property COMPLETE
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static COMPLETE: string = "onComplete";
    /**
     * 加载过程事件
     * @Event
     * @property PROGRESS
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static PROGRESS: string = "onProgress";
    /**
     * 出错事件
     * @Event
     * @property ERROR
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static ERROR: string = "onError";
    /**
     * 输入框失去焦点事件
     * @Event
     * @property BLUR
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static BLUR: string = "onBlur";
    /**
     * 输入框聚焦事件
     * @Event
     * @property FOCUS
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static FOCUS: string = "onFocus";
    /**
     * 输入框输入事件
     * @Event
     * @property INPUT
     * @type {string}
     * @static
     * @public
     * @since 1.0.0
     */
    public static INPUT: string = "onInput";
    /**
     * 事件类型名
     * @property type
     * @type {string}
     * @public
     * @since 1.0.0
     */
    public type: string = "";
    /**
     * 触发此事件的对象
     * @property target
     * @public
     * @since 1.0.0
     * @type {any}
     */
    public target: any = null;
    /**
     * 随着事件一起附带的信息对象
     * 所有需要随事件一起发送的信息都可以放在此对象中
     * @property data
     * @public
     * @since 1.0.0
     * @type {any}
     * @default null
     */
    public data: any = null;

    /**
     * @method Event
     * @param {string} type 事件类型
     * @public
     * @since 1.0.0
     */
    public constructor(type: string) {
        super();
        this._instanceType = "Event";
        this.type = type;
    }

    /**
     * 防止对事件流中当前节点的后续节点中的所有事件侦听器进行处理。
     * 冒泡和捕获都有用
     * @method stopPropagation
     * @public
     * @since 2.0.0
     * @return {void}
     */
    public stopPropagation(): void {
        this._pd = true;
    }
    /**
     * 是否阻止事件向下冒泡
     * @property _pd
     * @type {boolean}
     * @private
     * @since 1.0.0
     */
    private _pd: boolean = false;

    public destroy(): void {
        let s = this;
        s.target = null;
        s.data = null;
    }

    /**
     * 重置事件
     * @method reset
     * @param {string} type
     * @param target
     * @since 2.0.0
     * @return {void}
     * @public
     */
    public reset(type: string, target: any): void {
        let s = this;
        s.target = target;
        s._pd = false;
        s.type = type;
        s.data = null;//最好加上，不然可能带上原来的数据
    }
}
