'use strict';

import * as lodash from "../../lodash/lodash-core.js";

import * as sol from "../../solight/sol.js";


const process_data = (scheduleFile) =>
    sol.processScheduleFile(scheduleFile);


const event_modus_string = (event) => {
    const questionId = 1392;
    const answers = sol.eventAnswers(event);
    const answer = answers.filter(a => a.get('question') === questionId);
    const modus = answer.length > 0 ? answer[0].get('answer') : '???';
    return modus;
};


const trackIndexMap = new Map([
    ['Andere', 0],
    ['Ethik, Wissenschaft, Kultur & Gesellschaft', 1],
    ['Recht & Politik', 2],
    ['Netzwerke, Security, Hard- & Software', 3],
    ['Digitale Selbstverteidigung', 4]]);

const track_index = (track) =>
      trackIndexMap.get(track);

const sort_tracks = (tracks) =>
      lodash.sortBy(tracks, track_index);


const person_names_concat = (persons) =>
      // persons.map(p => sol.personName(p)).join(', ');
      // persons.map(p => sol.personName(p)).join(' & ');
      persons.map(p => sol.personName(p)).join(' · ');


const ndash_fix_regexp = RegExp('\\s+-\\s+');
const ndash_fix_replacement = ' – ';

const fix_dash = (string) =>
    string.replace(ndash_fix_regexp, ndash_fix_replacement);


export {
    process_data,
    event_modus_string,
    track_index,
    sort_tracks,
    person_names_concat,
    fix_dash
}
