import { BaseComponent } from '@/shared/base/BaseComponent';
import { getAttribute } from '@/shared/utils/locator-utils';

export class SimpleCheckbox extends BaseComponent {
  private readonly icon = this.host.locator('.checkbox-icon');

  async set(state: boolean): Promise<void> {
    if (state === (await this.getCurrentState())) {
      return;
    }

    return this.icon.click();
  }

  private async getCurrentState(): Promise<boolean> {
    const classes = await getAttribute(this.icon, 'class');
    return classes?.includes('mdi-checkbox-marked') ?? false;
  }
}
