from card import PictoCard
from language import PictoLanguage
from imagehandler import PictoImageHandler
from manager import PictoManager

import random


class PictoInterface():
    color_map = {
        # adjective
        'ADJ':      ((255,255,255), (0,0,0)),
        
        # adposition
        'ADP':      ((255,255,255), (0,0,0)),

        # adverb
        'ADV':      ((255,255,255), (0,0,0)),

        # auxiliary
        'AUX':      ((255,255,255), (0,0,0)),

        # conjunction
        'CONJ':     ((255,255,255), (0,0,0)),

        # coordinating conjunction
        'CCONJ':    ((255,255,255), (0,0,0)),

        # determiner
        'DET':      ((219,0,0), (255,255,255)),

        # interjection
        'INTJ':     ((0,0,255), (0,0,0)),

        # noun
        'NOUN':     ((0,0,0), (255,255,255)),

        # numeral
        'NUM':      ((255,255,255), (0,0,0)),

        # particle
        'PART':     ((255,255,255), (0,0,0)),

        # pronoun
        'PRON':     ((255,255,255), (0,0,0)),

        # proper noun
        'PROPN':    ((255,255,255), (0,0,0)),

        # punctuation
        'PUNCT':    ((255,255,255), (0,0,0)),

        # subordinating conjunction
        'SCONJ':    ((255,255,255), (0,0,0)),

        # symbol
        'SYM':      ((255,255,255), (0,0,0)),

        # verb
        'VERB':     ((255,255,255), (0,0,0)),

        # other
        'X':        ((255,255,255), (0,0,0)),

        # space -- note: tokenizer deletes this
        'SPACE':    ((255,255,255), (0,0,0))
    }

    def __init__(self, language, image_handler):
        self.__language = language
        self.__image_handler = image_handler

    def tokens_to_cards(self, tokens):
        cards = []
        for token in tokens:
            picto_route = PictoManager.get_picto(token.get_lemma())
            card = PictoCard(token.get_print(), \
                picto_route, \
                token.get_pos())
            
            cards.append(card)
        
        return cards

    def to_img(self, sentence):
        tokenized = self.__language.tokenize(sentence)
        cards = self.tokens_to_cards(tokenized)
        self.__image_handler.generate_cards(cards)
    
    def get_cards(self, sentence):
        tokenized = self.__language.tokenize(sentence)
        return self.tokens_to_cards(tokenized)
    
    def get_literal(self, text):
        return PictoManager.get_picto(text, append_default=False)