import Form from "./form";
import Tooltips from '@core/component/toast/tooltips';
import BlockingElementsM from './BlockingElementsM';
import DefaultDatasM from './DefaultDatasM';
const SDKForm = (($) => {
    const DefaultConfig = {
        blockingElements: BlockingElementsM,
        defaultDatas: DefaultDatasM,
        isSDK: true,
        linglongTemplateState: window['page_data'].template && window['page_data'].template.templateGrade == 4
    };
    class SDKForm extends Form{
        constructor(config) {
            super(config);
            console.log(this.config);
            this.blockingEvents();
        }
        
        getConfig(config) {
            config = super.getConfig(config);
            return $.extend(true, {asyncHandler: ()=>{
                    this.blockingEvents();
                }}, DefaultConfig, config);
        }
        
        blockingEvents() {
            if (!this.config.isSDK){
                return;
            }
            if(this.config.linglongTemplateState && this.config.domData && this.config.domData[0].properties[0].datasource === "J_ADV_MATERIAL"){
                return
            }
            const {blockingElements} = this.config;
            for (let key in blockingElements) {
                let path = window.location.hostname + window.location.pathname;
                if(path == 'sdk.conecli.com/m'){
                    if(key == '.J_add_link'){
                        continue;
                    }
                }
                let nodeObj = blockingElements[key];
                if (!$.isEmptyObject(nodeObj)) {
                    let tips = nodeObj.tips;
                    if (tips) {
                        let tipsNode = $(tips.elem);
                        tipsNode.attr({
                            'data-tooltips': '',
                            'data-content': tips.content,
                            'data-direction': tips.direction,
                        });
                    }
                    
                    if (nodeObj.preventDefault) {
                        $(key).removeAttr('type');
                    }
                    
                    let elemEvents = null;
                    $(key).each((i, el) => {
                        let node = $(el);
                        elemEvents = $._data(node[0], 'events');
                        if (elemEvents) {
                            for (let evtKey in elemEvents) {
                                node.off(evtKey);
                            }
                        } else {
                            
                            node.on('click', () => {
                                return false;
                            });
                        }
                    });
                    new Tooltips();
                }
            }
        }
    }
    return SDKForm;
})($);
export default SDKForm;