import { BaseSelfControl } from './BaseSelfControl';

export class SelfImage extends BaseSelfControl<
  string,
  string,
  string,
  HTMLButtonElement
  > {

  isValueEmpty = () => {
    return typeof this.#value === 'string' && this.#value !== '';
  }
  isValueNotEmpty = () => {
    return !this.isValueEmpty();
  }

  public validate = () => {
    this.validation = true;
  };

  public cleaningClassInitializer = () => {
    this.hasChange = false;
    this.defaultValue = undefined;
    this.initializeListener = false;
    this.initializeProperties = false;
    this.validation = true;
  };

  public refreshHasChange = () => {
    if (this.showHasChangeFlag) {
      this.hasChange = this.defaultValue !== this.#value;
    }
  };
  public restartDefaultValue = () => {
    this.defaultValue = this.value;
    this.refreshHasChange();
  };

  #value: string;
  public get value() {
    return this.#value;
  }
  public set value(value: any) { }

  public setValue = (value: string) => {
    this.#value = value;
    this.refreshHasChange();
  };

  public deserialize = (value: string) => {
    this.#value = value;
    this.restartDefaultValue();
  };

  constructor(value: string) {
    super();
    this.#value = value;

    this.restartDefaultValue();
  }

  static empty(): SelfImage {
    return new SelfImage('');
  }
  static deserialize(value?: string): SelfImage {
    const image = new SelfImage(value ? value : '');
    return image;
  }
  static createCopy(old: SelfImage) {
    const image = new SelfImage('');
    image.#value = old.#value ? old.#value : '';
    return image;
  }
}
