"use strict";
import { util } from '../../../util/util.js'
import {config} from "../../../config.js";
class queryButtons {
    constructor(data) {
        
        this.data = data;
        this.parentObjID=data.parentObjID;
        this.eleID = util.getUUID();
        this.objID = this.eleID + 'div';
        this.buttons = data.queryButtonArray
        this.buttonsInfo = { buttons: this.buttons, parentObjID: this.parentObjID }

    }
    getObjID(){
        return this.objID;
    }
    render() {
        let html = '<div class="demo-inline-spacing mt-1" style="margin-left:20px" id=' + this.objID + '>';
        let buttons = this.buttons;
        for (let i = 0; i < buttons.length; i++) {
            let button = buttons[i];
            let buttonCss='';
            let colorClassName=config.getConfigJson().defaultColorClassJson[button.button_class];
            if(colorClassName){
                colorClassName=colorClassName['bfColor']
            }else{
                let backgroundColor=util.getColorByName(button.button_class);
                let color=util.dynamicColor(backgroundColor);
                buttonCss+=`background:${backgroundColor};color:${color}`;
            }
            html += `<button type="button" name="${button.button_name}" 
                    style="margin: 0.375rem 0.375rem 0.375rem 0 !important; ${buttonCss}" 
                    class="btn btn- ladda-button ${colorClassName}" data-style="slide-down">${button.button_title}</button>`;
        }
        html += '</div>';
        document.getElementById(this.parentObjID+'manager').insertAdjacentHTML("beforeEnd", html);
        let that=this;
        for (let i = 0; i < buttons.length; i++) {
            let button = buttons[i];
            if (!util.isNull(button.button_method)) {
                let buttonEle = document.getElementById(this.objID).querySelector('button[name="' + button.button_name + '"]');
                Ladda.bind( buttonEle, { timeout: 1000 } );//按钮loading动画效果
                buttonEle.addEventListener(button.button_event,  () =>{
                    let jsonConfig={objID:that.parentObjID,button_method:button.button_method}
                    let buttonParams={buttonUuid:button.uuid}
                    jsonConfig.buttonParams=buttonParams;
                    if (util.isNull(button.js_path)) {
                        util.import2023(config.getConfigJson().queryActionPath,jsonConfig);
                    } else {
                        util.import2023(button.js_path,jsonConfig);
                    }
                })
            }
        }

    }
  
}
export { queryButtons }



