THEME_COLOR = "#375362"
from tkinter import *
from quiz_brain import QuizBrain

class QuizzInterface:

    def __init__(self, quiz_brain: QuizBrain):
        self.quiz = quiz_brain
        self.window= Tk()
        self.window.title("Trivia")
        self.window.config(padx= 20, pady=20, bg=THEME_COLOR)

        self.score_label = Label(text="Score: 0", fg="white", bg= THEME_COLOR)
        self.score_label.grid(column=1, row=0)

        self.canvas= Canvas(width= 300, height=250, bg="white")
        self.canvas.grid(column= 0, row =1, columnspan= 2, pady=50)
        self.question_text = self.canvas.create_text(150,125,text="text comes here", width=280,  font=("Arial", 20, "italic"))

        false_img = PhotoImage(file="images/false.png")
        self.false_button= Button(image=false_img, highlightthickness= 0, command=self.red_button)
        self.false_button.grid(column= 1, row =2)
        true_img= PhotoImage(file="images/true.png")
        self.true_button = Button(image=true_img, highlightthickness= 0, command=self.green_button)
        self.true_button.grid(column=0, row=2)
        self.get_next_question()

        self.get_next_question()

        self.window.mainloop()

    def get_next_question(self):
        self.canvas.config(bg="white")
        if self.quiz.still_has_questions():
            self.score_label.config(text=f"Score:{self.quiz.score}")
            q_text= self.quiz.next_question()
            self.canvas.itemconfig(self.question_text, text=q_text)
        else:
            self.canvas.itemconfig(self.question_text, text= "This is the end of the quiz")
            self.false_button(state="diasbled")
            self.true_button(state="disabled")

    def green_button(self):
        is_right= self.quiz.check_answer("True")
        self.give_feedback(is_right)


    def red_button(self):
        is_right= self.quiz.check_answer("False")
        self.give_feedback(is_right)



    def give_feedback(self, is_right):
        if is_right:
            self.canvas.config(bg="green")
        else:
            self.canvas.confif(bg="red")

        self.window.after(1000, self.get_next_question )

