"use strict";

import {util} from "../../../../../util/util.js";

class base {
    constructor(data) {
        this.data = data;
        //给当前对象创建一个id，同时该id也是对象的domid
        if(util.isNull(data.uuid)){
            this.eleID = util.getUUID();
            this.objID = this.eleID + 'div';
            this.uuid = this.eleID;
        }else{
            this.uuid = data.uuid;
            this.eleID = data.uuid;
            this.objID = data.uuid + 'div';
        }
    }
    remove() {
        $('#' + this.objID).remove();
    }
    getData() {
        return this.data;
    }
    getObjID() {
        return this.objID;
    }
    getEleID() {
        return this.eleID;
    }
    getValue() {//获取存储到数据库的值
        return document.getElementById(this.eleID).value;
    }
    setValue(value) {
        document.getElementById(this.eleID).value = util.toOldChar(value);
    }
    setDisabled(){
        let that=this;
        let eleObj = document.getElementById(that.getEleID());
        eleObj.disabled=true;
        that.disabled=true;

    }
    removeDisabled(){
        let that=this;
        let eleObj = document.getElementById(that.getEleID());
        eleObj.disabled=false;
        that.disabled=false;

    }
    scrollToElement() {
        let that = this;
        const div = document.getElementById(that.data.parentObj.data.buildFormStartDivID);  // 获取滚动的 div
        const targetElement = document.getElementById(that.objID);  // 获取目标元素

        if (div && targetElement) {
            // 获取目标元素相对于 div 的偏移量
            const targetOffsetTop = targetElement.offsetTop;

            // 直接通过原生 scrollTop 滚动
            div.scrollTop = targetOffsetTop;

            // 更新 PerfectScrollbar
            const ps = new PerfectScrollbar(div);
            ps.update();
        } else {
            console.warn(`Element with id "${that.data.parentObj.buildFormStartDivID}" or "${that.objID}" not found.`);
        }
    }
}
export { base }