<commit_before>import { HttpClient } from '@angular/common/http';
import { Component, EventEmitter, Inject, Input, OnDestroy, OnInit, Optional, Output, Self } from '@angular/core';
import { FormControl, FormGroupDirective, NgControl } from '@angular/forms';
import { Subscription } from 'rxjs';
import { IDecodedCaptcha } from './decoded.captcha';
import { IEncodedCaptcha } from './encoded.captcha';

@Component({
    selector: 'ngx-recaptcha',
    templateUrl: './ngx-recaptcha.component.html',
    styleUrls: ['./ngx-recaptcha.component.scss']
})
export class NgxRecaptchaComponent implements OnInit, OnDestroy {

    @Input() url: string;
    @Output() readonly resolved = new EventEmitter<IDecodedCaptcha>();
    readonly subscription = new Subscription();
    readonly formControl = new FormControl();
    audio?: HTMLAudioElement;
    captcha?: IEncodedCaptcha;

    constructor(
        @Inject(HttpClient) private http: HttpClient,
        @Optional() @Self() @Inject(NgControl) private ngControl?: NgControl,
        @Optional() @Inject(FormGroupDirective) private parentFormGroup?: FormGroupDirective,
    ) { }

    ngOnInit(): void {
        this.getCaptcha();
        this.subscription.add(this.parentFormGroup && this.parentFormGroup.ngSubmit.subscribe(() => {
            this.ngControl.control.markAsDirty();
            this.ngControl.control.markAsTouched();
            this.ngControl.control.updateValueAndValidity();
        }));
        this.subscription.add(this.control.valueChanges.subscribe(this.emitDecodedCaptcha));
    }

    ngOnDestroy(): void {
        this.reset();
        this.subscription.unsubscribe();
    }

    get paused() {
        return this.audio && this.audio.paused;
    }

    get control() {
        return this.ngControl && this.ngControl.control || this.formControl;
    }

    private setCaptcha = (model: IEncodedCaptcha): void => {
        if (model) {
            this.captcha = model;
            this.setAudio(model.sound);
        }
    }

    private play = () => this.audio && this.audio.play();

    private pause = () => this.audio && this.audio.pause();

    toggleAudio = () => this.paused ? this.play() : this.pause();

    getCaptcha = () => {
        if (this.http && this.url) {
            this.reset();
            this.http.get<IEncodedCaptcha>(this.url)
                .subscribe(this.setCaptcha);
        }
    }

    setAudio = (src: string): void => {
        if (typeof Audio !== 'undefined') {
            this.audio = new Audio(src);
        }
    }

    reset = (): void => {
        this.pause();
        this.captcha = null;
    }

    emitDecodedCaptcha = (captcha: string): void => this.resolved.emit({ captcha, hash: this.captcha && this.captcha.hash });
}<commit_msg>added modifications of access<commit_after>import { HttpClient } from '@angular/common/http';
import { Component, EventEmitter, Inject, Input, OnDestroy, OnInit, Optional, Output, Self } from '@angular/core';
import { FormControl, FormGroupDirective, NgControl } from '@angular/forms';
import { Subscription } from 'rxjs';
import { IDecodedCaptcha } from './decoded.captcha';
import { IEncodedCaptcha } from './encoded.captcha';

@Component({
    selector: 'ngx-recaptcha',
    templateUrl: './ngx-recaptcha.component.html',
    styleUrls: ['./ngx-recaptcha.component.scss']
})
export class NgxRecaptchaComponent implements OnInit, OnDestroy {

    @Input() url: string;
    @Output() readonly resolved = new EventEmitter<IDecodedCaptcha>();
    readonly subscription = new Subscription();
    readonly formControl = new FormControl();
    audio?: HTMLAudioElement;
    captcha?: IEncodedCaptcha;

    constructor(
        @Inject(HttpClient) private http: HttpClient,
        @Optional() @Self() @Inject(NgControl) private ngControl?: NgControl,
        @Optional() @Inject(FormGroupDirective) private parentFormGroup?: FormGroupDirective,
    ) { }

    ngOnInit(): void {
        this.getCaptcha();
        this.subscription.add(this.parentFormGroup && this.parentFormGroup.ngSubmit.subscribe(() => {
            this.ngControl.control.markAsDirty();
            this.ngControl.control.markAsTouched();
            this.ngControl.control.updateValueAndValidity();
        }));
        this.subscription.add(this.control.valueChanges.subscribe(this.emitDecodedCaptcha));
    }

    ngOnDestroy(): void {
        this.reset();
        this.subscription.unsubscribe();
    }

    get paused() {
        return this.audio && this.audio.paused;
    }

    get control() {
        return this.ngControl && this.ngControl.control || this.formControl;
    }

    private setCaptcha = (model: IEncodedCaptcha): void => {
        if (model) {
            this.captcha = model;
            this.setAudio(model.sound);
        }
    }

    private play = () => this.audio && this.audio.play();

    private pause = () => this.audio && this.audio.pause();

    private setAudio = (src: string): void => {
        if (typeof Audio !== 'undefined') {
            this.audio = new Audio(src);
        }
    }

    private emitDecodedCaptcha = (captcha: string): void => this.resolved.emit({ captcha, hash: this.captcha && this.captcha.hash });

    toggleAudio = () => this.paused ? this.play() : this.pause();

    getCaptcha = (): void => {
        if (this.http && this.url) {
            this.reset();
            this.http.get<IEncodedCaptcha>(this.url)
                .subscribe(this.setCaptcha);
        }
    }

    reset = (): void => {
        this.pause();
        this.captcha = null;
    }
}
{'fraction_non_alphanumeric': 0.14154345474215652, 'fraction_numerical': 0.0, 'mean_word_length': 2.8019191226867717, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4827689', 'n_tokens_mistral': 1648, 'n_tokens_neox': 1616, 'n_words': 328}