/*
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import {Layout, WordDefinition} from '../domain/layout';

const es_la: WordDefinition = {1: [1, 2, 6, 7]};
const son_las: WordDefinition = {1: [2, 3, 4, 6, 7, 8]};
const y: WordDefinition = {7: [6]};
const menos: WordDefinition = {7: [7, 8, 9, 10, 11]};
const media: WordDefinition = {10: [1, 2, 3, 4, 5]};
const cinco: WordDefinition = {9: [7, 8, 9, 10, 11]};
const diez: WordDefinition = {8: [8, 9, 10, 11]};
const cuarto: WordDefinition = {10: [6, 7, 8, 9, 10, 11]};
const veinte: WordDefinition = {8: [2, 3, 4, 5, 6, 7]};
const veinticinco: WordDefinition = {9: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]};

export const Layout_es: Layout = {
    code: 'es',
    getHour: (time: Date) => {
        const hour = time.getHours();
        if (time.getMinutes() >= 35) {
            return (hour + 1) % 24;
        }
        return hour;
    },

    hours: {
        '0,12': [son_las, {7: [1, 2, 3, 4]}],
        '1,13': [es_la, {1: [9, 10, 11]}],
        '2,14': [son_las, {2: [1, 2, 3]}],
        '3,15': [son_las, {2: [5, 6, 7, 8]}],
        '4,16': [son_las, {3: [1, 2, 3, 4, 5, 6]}],
        '5,17': [son_las, {3: [7, 8, 9, 10, 11]}],
        '6,18': [son_las, {4: [1, 2, 3, 4]}],
        '7,19': [son_las, {4: [6, 7, 8, 9, 10]}],
        '8,20': [son_las, {5: [1, 2, 3, 4]}],
        '9,21': [son_las, {5: [5, 6, 7, 8, 9]}],
        '10,22': [son_las, {6: [3, 4, 5, 6]}],
        '11,23': [son_las, {6: [8, 9, 10, 11]}]
    },
    letters: [
        'ESONELASUNA',
        'DOSITRESORE',
        'CUATROCINCO',
        'SEISASIETEN',
        'OCHONUEVEYO',
        'LADIEZSONCE',
        'DOCELYMENOS',
        'OVEINTEDIEZ',
        'VEINTICINCO',
        'MEDIACUARTO'
    ],
    minutes: {
        '5,6,7,8,9': [y, cinco],
        '10,11,12,13,14': [y, diez],
        '15,16,17,18,19': [y, cuarto],
        '20,21,22,23,24': [y, veinte],
        '25,26,27,28,29': [y, veinticinco],
        '30,31,32,33,34': [y, media],
        '35,36,37,38,39': [menos, veinticinco],
        '40,41,42,43,44': [menos, veinte],
        '45,46,47,48,49': [menos, cuarto],
        '50,51,52,53,54': [menos, diez],
        '55,56,57,58,59': [menos, cinco]
    },
    permanent: null,
    prettyName: 'EspaƱol',
    version: 2
};

$.fritteli.uhr.register(Layout_es);

declare namespace $ {
    const fritteli: Fritteli.Fritteli;
}
declare namespace Fritteli {
    interface Fritteli {
        uhr: Uhr;
    }

    interface Uhr {
        register: (layout: Layout) => void;
    }
}