export const Usermanager = (superClass) => {
    return class extends superClass {

        constructor() {
            super();
            this.fontObjHeader = null;
            this.fontObjBody = null;
            this.fontObjTitle = null;
            this.accSeqApi = window.sigApi.accessSequence;
            this.constApi = (window.sigApi && window.sigApi.SIG_CONST) ? window.sigApi.SIG_CONST : null;
        }

        disconnectedCallback() {
            super.disconnectedCallback();
            this.fontObjHeader = null;
            this.fontObjBody = null;
            this.fontObjTitle = null;
            this.accSeqApi = null;
        }

        _setPropertyText(property, text) {
            console.warn('This method is obsolete not implemented.');
        }

        _getTextObj(text = '', param = [], textList = this.controlTextList) {
            return {
                text: text,
                textList: textList,
                param: param
            };
        }

        _hasNoErrors(result) {
            return (result.status || result.message || result.stack) ? false : true;
        }

        _showAlert(message = '', title = '', status = 0, style = undefined) {
            return this.wmApi.systemWindow_alert(message, title, status, style);
        }

        _showConfirm(message = '', title = '', status = 0, style = undefined) {
            return this.wmApi.systemWindow_confirm(message, title, status, style);
        }

        _showPrompt(message = '', title = '', promptValue = '', status = 0, style = undefined) {
            return this.wmApi.systemWindow_prompt(message, title, promptValue, status, style);
        }

        sigApplyFontObject(propName, fontObj) {
            super.sigApplyFontObject(propName, fontObj);
            if (propName === 'sig-control-listview thead') {
                this.fontObjHeader = fontObj;
            } else if (propName === 'sig-control-listview tbody') {
                this.fontObjBody = fontObj;
            } else if (propName === 'sig-control-titlebar') {
                this.fontObjTitle = fontObj;
            }
            this._applFontObjects();
        }

        _applFontObjects() {
            let _listView = null;
            let _titleBar = null;
            if (this.$) {
                _listView = this.$.listview;
                _titleBar = this.$.titlebar;
            }
            if (!(_listView instanceof HTMLElement) && !(_titleBar instanceof HTMLElement)) return;

            if (this.fontObjHeader) _listView.fontobjectheader = this.fontObjHeader;
            else _listView.fontobjectheader = {};
            if (this.fontObjBody) _listView.fontobjectbody = this.fontObjBody;
            else _listView.fontobjectbody = {};
            if (this.fontObjTitle) _titleBar.fontobjecttitle = this.fontObjTitle;
            else _titleBar.fontobjecttitle = {};
        }

        _checkAccess(accessNumber, userId) {
            return (this.accSeqApi) ? this.accSeqApi.checkAccess(accessNumber, userId) : false;
        }

        _checkReadAccess(accessNumber, userId) {
            return (this.accSeqApi) ? this.accSeqApi.checkReadAccess(accessNumber, userId) : false;
        }

        _disableButton(button) {
            if (button instanceof HTMLElement) button.classList.add('disabled');
        }

        _enableButton(button) {
            if (button instanceof HTMLElement) button.classList.remove('disabled');
        }

        _updateSelfPermissions(permissions = this.permissions) {
            return permissions.updateOwnUsername || permissions.updateOwnPW || permissions.updateOwnInfo;
        }

        _validateAccessNumberFormat(accessNumber) {
            return !isNaN(accessNumber) && /^(0|[1-9][0-9]*)$/.test(accessNumber) &&
                Number(accessNumber) >= 0 && Number(accessNumber) <= this.constApi.USER_ACCESS_NUMBER;
        }
    };
};
