const { setTranslateBoxState,setOtherBoxState } = require("./js/util");

(function(){

    // $('.test-btn').on('click', () => {
    //     ipcRenderer.send('saveFile', {path: 'test/文件夹2', fileName: "VTOL UAVS MODELING, ATTITUDE STATE.pdf", fileData: Buffer.from('测试222')})
    // })

    // 切换翻译弹窗状态
    $('.trans-state').on('click', () => {
        const isFloat = localStorage.getItem('transState') == 'float';
        const transState = isFloat ? 'static' : 'float';

        localStorage.setItem("transState", transState);

        setTranslateBoxState(isFloat)
    })
    $('.other-state').on('click', () => {
        const isFloat = localStorage.getItem('otherState') == 'float';
        const otherState = isFloat ? 'static' : 'float';

        localStorage.setItem("otherState", otherState);

        setOtherBoxState(isFloat)
    })

    let startX = 0;
    let hasStart = false;

    let startX1 = 0;
    let hasStart1 = false;

    $('#trans-warp .drag-handle').on('mousedown', (e) => {
        hasStart = true;
        startX = e.clientX || e.pageX;
    })

    $('#otherUrl-warp .drag-handle').on('mousedown', (e) => {
        hasStart1 = true;
        startX1 = e.clientX || e.pageX;
    })

    $(document).on('mousemove', e => {
        if(hasStart) {
            const x = e.clientX || e.pageX;
            const offsetX = startX - x;
            const $ele = $('#trans-warp');
            const width = $ele.width() + offsetX;
            $ele.css({width})
            startX = x;
        }
        if(hasStart1) {
            const x = e.clientX || e.pageX;
            const offsetX = startX1 - x;
            const $ele = $('#otherUrl-warp');
            const width = $ele.width() + offsetX;
            $ele.css({width})
            startX1 = x;
        }

    })

    const onEndMove = e => {
        if(hasStart) {
            startX = 0;
            hasStart = false;
        }
        if(hasStart1) {
            startX1 = 0;
            hasStart1 = false;
        }
    }

    $(document).on('mouseup', onEndMove);
    $(document).on('mouseleave', onEndMove);



    const initAllConfig = () => {
        const isFloat = localStorage.getItem('transState') == 'float';
        setTranslateBoxState(!isFloat)
    }
    const initConfig = () => {
        const isFloat = localStorage.getItem('otherState') == 'float';
        setOtherBoxState(!isFloat)
    }

    initAllConfig();
    initConfig()
})();