import { Component, OnInit } from '@angular/core';
import { ModalDialogParams } from '@nativescript/angular';
import { Picker } from '~/pages/event/util';

export interface UnitSearchForm {
    name: string
    registrationNumber: string;
    location: string;
    regNumberStart: boolean;
    accountNumber: string;
    ic: string;
    alignment: string;
}
export enum UnitAlignment {
    IRRELEVANT = "",
    RELIGIOUS = '1',
    WATER = '2',
}
export const formattedAlignments: Array<Picker> = [
    { key: UnitAlignment.IRRELEVANT, label: 'nezáleží' },
    { key: UnitAlignment.RELIGIOUS, label: 'Rozšířená náboženská výchova' },
    { key: UnitAlignment.WATER, label: 'Vodní' },
];

@Component({
    selector: 'UnitSearchModalComponent',
    moduleId: module.id,
    templateUrl: './unit-search-modal.component.html',
})
export class UnitSearchModalComponent implements OnInit {

    searchParams: UnitSearchForm;
    formattedAlignments: Picker[];
    constructor(
        private params: ModalDialogParams,
    ) {
        this.formattedAlignments = formattedAlignments;
    }

    ngOnInit(): void {
        const alignment = this.params.context.alignment
        this.searchParams = { ...this.params.context, alignment: alignment && alignment.toString() };
    }

    close() {
        this.params.closeCallback();
    }

    submit() {
        this.params.closeCallback({ ...this.searchParams, alignment: parseInt(this.searchParams.alignment, 10) || null });
    }

    onBackButton(): void {
        this.params.closeCallback();
    }
}