<commit_before>import {
    animate,
    AnimationBuilder,
    AnimationFactory,
    AnimationPlayer,
    style} from "@angular/animations";
import {
    ChangeDetectorRef,
    Component,
    Directive,
    ElementRef,
    EventEmitter,
    HostBinding,
    HostListener,
    Input,
    NgModule,
    OnDestroy,
    OnInit,
    Optional,
    Output
} from "@angular/core";
import { IgxNavigationService, IToggleView } from "../../core/navigation";

@Directive({
    exportAs: "toggle",
    selector: "[igxToggle]"
})
export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {

    @Output()
    public onOpen = new EventEmitter();

    @Output()
    public onClose = new EventEmitter();

    @Input()
    public collapsed = true;

    @Input()
    public id: string;

    public get element() {
        return this.elementRef.nativeElement;
    }

    @HostBinding("class.igx-toggle--hidden")
    public get hiddenClass() {
        return this.collapsed;
    }

    @HostBinding("class.igx-toggle")
    public get defaultClass() {
        return !this.collapsed;
    }

    private _id: string;

    constructor(
        private elementRef: ElementRef,
        private builder: AnimationBuilder,
        private cdr: ChangeDetectorRef,
        @Optional() private navigationService: IgxNavigationService) { }

    public open(fireEvents?: boolean, handler?) {
        if (!this.collapsed) { return; }

        const player = this.animationActivation();
        player.onStart(() => this.collapsed = !this.collapsed);
        player.onDone(() =>  {
            player.destroy();
            if (fireEvents) {
                this.onOpen.emit();
            }
        });

        player.play();
    }

    public close(fireEvents?: boolean, handler?) {
        if (this.collapsed) { return; }

        const player = this.animationActivation();
        player.onDone(() => {
            this.collapsed = !this.collapsed;
            // When using directive into component with OnPush it is necessary to
            // trigger detection again when close animation ends. Due to late updated @collapsed property.
            this.cdr.markForCheck();
            player.destroy();
            if (fireEvents) {
                this.onClose.emit();
            }
        });

        player.play();

    }

    public toggle(fireEvents?: boolean) {
        this.collapsed ? this.open(fireEvents) : this.close(fireEvents);
    }

    public ngOnInit() {
        if (this.navigationService && this.id) {
            this.navigationService.add(this.id, this);
        }
    }

    public ngOnDestroy() {
        if (this.navigationService && this.id) {
            this.navigationService.remove(this.id);
        }
    }

    private animationActivation() {<commit_msg>docs(toggle): update comment when using toggle with onpush<commit_after>import {
    animate,
    AnimationBuilder,
    AnimationFactory,
    AnimationPlayer,
    style} from "@angular/animations";
import {
    ChangeDetectorRef,
    Component,
    Directive,
    ElementRef,
    EventEmitter,
    HostBinding,
    HostListener,
    Input,
    NgModule,
    OnDestroy,
    OnInit,
    Optional,
    Output
} from "@angular/core";
import { IgxNavigationService, IToggleView } from "../../core/navigation";

@Directive({
    exportAs: "toggle",
    selector: "[igxToggle]"
})
export class IgxToggleDirective implements IToggleView, OnInit, OnDestroy {

    @Output()
    public onOpen = new EventEmitter();

    @Output()
    public onClose = new EventEmitter();

    @Input()
    public collapsed = true;

    @Input()
    public id: string;

    public get element() {
        return this.elementRef.nativeElement;
    }

    @HostBinding("class.igx-toggle--hidden")
    public get hiddenClass() {
        return this.collapsed;
    }

    @HostBinding("class.igx-toggle")
    public get defaultClass() {
        return !this.collapsed;
    }

    private _id: string;

    constructor(
        private elementRef: ElementRef,
        private builder: AnimationBuilder,
        private cdr: ChangeDetectorRef,
        @Optional() private navigationService: IgxNavigationService) { }

    public open(fireEvents?: boolean, handler?) {
        if (!this.collapsed) { return; }

        const player = this.animationActivation();
        player.onStart(() => this.collapsed = !this.collapsed);
        player.onDone(() =>  {
            player.destroy();
            if (fireEvents) {
                this.onOpen.emit();
            }
        });

        player.play();
    }

    public close(fireEvents?: boolean, handler?) {
        if (this.collapsed) { return; }

        const player = this.animationActivation();
        player.onDone(() => {
            this.collapsed = !this.collapsed;
            // When using directive into component with OnPush it is necessary to
            // trigger change detection again when close animation ends
            // due to late updated @collapsed property.
            this.cdr.markForCheck();
            player.destroy();
            if (fireEvents) {
                this.onClose.emit();
            }
        });

        player.play();

    }

    public toggle(fireEvents?: boolean) {
        this.collapsed ? this.open(fireEvents) : this.close(fireEvents);
    }

    public ngOnInit() {
        if (this.navigationService && this.id) {
            this.navigationService.add(this.id, this);
        }
    }

    public ngOnDestroy() {
        if (this.navigationService && this.id) {
            this.navigationService.remove(this.id);
        }
    }

    private animationActivation() {
{'fraction_non_alphanumeric': 0.11352313167259787, 'fraction_numerical': 0.0, 'mean_word_length': 2.188315371525808, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6876323', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1520, 'n_words': 360}