import { globalLookup } from "./global";

const MAX_SCALE = 10.0;
const MIN_SCALE = 0.0;

/**
 * 
 * @param {HTMLElement} element 
 * @param {WheelEvent} event 
 */
function windowsKeydown(element, event) {
    const svg = globalLookup.netlistRender.selection;
    if (!svg) {
        return;
    }
    
    const { deltaX, deltaY } = event;
    if (event.ctrlKey) {
        if (deltaY < 0) {
            // scale up


        } else if (deltaY > 0) {
            // scale down

        }

        event.preventDefault();
    } else if (event.shiftKey) {
        event.preventDefault();
    } else if (deltaX !== 0 && deltaY === 0) {
        if (deltaX > 0) {
            // scroll left

        } else {
            // scroll right

        }

        event.preventDefault();
    } else if (deltaX === 0 && deltaY !== 0) {
        if (deltaY > 0) {
            // scroll up

        } else {
            // scroll down

        }

        event.preventDefault();
    }
}

/**
 * 
 * @param {HTMLElement} element 
 * @param {WheelEvent} event 
 */
function linuxKeydown(element, event) {

}

/**
 * 
 * @param {HTMLElement} element 
 * @param {WheelEvent} event 
 */
function macOsKeydown(element, event) {

}

/**
 * @description 注册滚轮事件
 * @param {HTMLElement} element 
 * @returns {(event: WheelEvent) => void}
 */
export function registerWheelEvent(element) {
    const platform = navigator.platform;
    if (platform.startsWith('Win')) {
        return event => windowsKeydown(element, event);
    } else if (platform.startsWith('Linux')) {
        return event => linuxKeydown(element, event);
    } else if (platform.startsWith('Mac')) {
        return event => macOsKeydown(element, event);
    } else {
        throw Error('不支持的操作系统！');
    }
}
