import {Component} from '@angular/core';

import {SelectionType} from '@swimlane/ngx-datatable';

import {
    ApplicationFilter,
    ApplicationSelectorConfig,
    ApplicationStatus,
    ClassifiableSelectorConfig,
    CONSTANTS,
    LayerConfig,
    LayerService,
    NavigationParams,
    NotificationService,
    SelectionTargetType,
    SourceRecordSelectorConfig,
    UserSelectorConfig
} from 'm2-core';
import {CdDemoComponent} from '../../../../abstract/CdDemoComponent';


@Component({
    templateUrl: './cd-layer-service-demo.component.html'
})
export class CdLayerServiceDemoComponent extends CdDemoComponent {

    constructor(
        private layerService: LayerService,
        private notificationService: NotificationService
    ) {
        super();
    }

    // region applicationSelector
    appTab = ApplicationFilter.Mine;
    appSelectionType = SelectionType.multi;
    appStatusFilter = ApplicationStatus.Completed;

    onSelectApplicationClick(): void {
        const config = new ApplicationSelectorConfig(this.appTab, null, this.appSelectionType, this.appStatusFilter);
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные заявки: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }
    // endregion applicationSelector


    // region userSelector
    async onSelectUserClick() {
        const config = new UserSelectorConfig();
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные пользователи: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }
    // endregion userSelector


    // region sourceRecordSelector
    systemId?: number;
    classId?: number;

    async onSelectSourceRecordClick() {
        const config = new SourceRecordSelectorConfig(this.systemId, this.classId);
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные импортированные позиции: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }
    // endregion sourceRecordSelector


    // region classifiableSelector
    async onSelectNodeClick() {
        const config = new ClassifiableSelectorConfig(SelectionTargetType.NODE);
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные группы: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }

    async onSelectItemClick() {
        const config = new ClassifiableSelectorConfig(SelectionTargetType.ITEM);
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные позиции: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }

    async onSelectNodeOrItemClick() {
        const config = new ClassifiableSelectorConfig(SelectionTargetType.ANY);
        config.handler = ids => {
            this.notificationService.success($localize`Выбранные объекты: ${ids}`);
        };
        this.layerService.activateSelector(config);
    }
    // endregion classifiableSelector


    // region layerConfig
    navigable = new NavigationParams(CONSTANTS.GREETING_ROUTER_LINK);
    url = 'https://yandex.ru/map-widget/v1/-/CCU5y-tB-A';

    async onOpenNavigableClick() {
        const config = new LayerConfig(this.navigable, null, {  });
        this.layerService.activateLayer(config);
    }

    async onOpenUrlClick() {
        const config = new LayerConfig(this.url, null, { header: 'Карта Москвы' });
        this.layerService.activateLayer(config);
    }
    // endregion layerConfig

}
