
import { ApplicationSettings } from '@nativescript/core';
import { USER_ROLE, USER_UNIT_ID } from './../../../constants/login-constants';


const allowedEventFunctionTypes = [
    'vedoucí/admin',
    'správce akcí',
];
export enum AuthEventType {
    CAMP, EDU, GEN, CONG,
}

const allowedEventCampFunctionTypes = [
    'vedoucí/admin',
    'správce akcí',
    'správce dotací',
    'hospodář',
]
export default function canEditEvent(eventUnitId?: number, type: AuthEventType = AuthEventType.EDU) {
    let result = false;
    const role = ApplicationSettings.getString(USER_ROLE)
    switch (type) {
        case AuthEventType.EDU:
            const userUnitId = ApplicationSettings.getNumber(USER_UNIT_ID);
            result = allowedEventFunctionTypes.some(r => role.includes(r)) && userUnitId === eventUnitId
            break;
        case AuthEventType.CAMP:
            result = allowedEventCampFunctionTypes.some(r => role.toLowerCase().includes(r))
            break;
    }
    return result

}