import { ElementFactory } from "../Page/ElementsOfFormFactory/ElementFactory";
import { IMainStateFactory } from "../Types";

export type ButtonType =
    | 'none'
    | 'ok'
    | 'view'
    | 'edit'
    | 'new'
    | 'cancel'
    | 'delete'
    | 'print'
    | 'select'
    | 'error';

export class ButtonFactory extends ElementFactory {
    public forceUpdate = () => { };
    #value: string | null;
    public get value() {
        return this.#value;
    }

    public setValue = (value: string) => {
        this.#value = value;
        this.refreshHasChange();
        this.forceUpdate();
    };
    public deseriallize = (_e: any) => {

    }

    public clearData = () => {
        this.#value = null;
        this.#defaultValue = null;
        this.validation = true;
        this._hasChange = false;
    }

    #defaultValue: string | null;
    public get defaultValue() {
        return this.#defaultValue;
    }

    public focusToElement = () => {
        this.mainStateFactory.elementsOfForm.focuseToThisElement(this);
    }

    constructor(
        _mainStateFactory: IMainStateFactory,
        _fieldName: string,
        _dispose: () => void,
        public caption: string,
        public disabled: boolean,
        public tabIndex?: number,
        public type: ButtonType = 'none'
    ) {
        super(_mainStateFactory, _fieldName, _dispose);
        this.#value = null;
        this.#defaultValue = null;
    }

    public restartDefaultValue = () => {
        this.#defaultValue = this.value;
        this.refreshHasChange();
    };

    public refreshHasChange = () => {
    };

    public validate = () => {
    }

}