from tkinter import *
from tkinter import *
from PIL import Image, ImageTk

from db_app import DB
from data_alfons import LocalDB

klienti = LocalDB(
        cesta='C:\\Users\\verca\\OneDrive\\Plocha\\bakalarka_data.json'
    )



databaze = DB(
    secret_file_path='client_secret.json',
    spread_sheet= 'MindCheck_data'
)

def raise_frame(frame):
    frame.tkraise()

root = Tk()
root.title('MindCheck')
root.geometry('400x711')

f0 = Frame(root, bg='#c2e2e1',width=400, height=711)
f1 = Frame(root, bg='#c2e2e1',width=400, height=711)
f2 = Frame(root, bg='#c2e2e1',width=400, height=711)
f3 = Frame(root, bg='#c2e2e1',width=400, height=711)

for frame in (f0, f1, f2, f3):
    frame.grid(row=0, column=0, sticky='news')

### FRAME 1 ###########
#########################################
#########################################
C = Canvas(f1, bg="blue", height=711, width=400)
filename = PhotoImage(file = 'C:\\Users\\verca\\OneDrive\\Plocha\\pozadi_menu.png')
background_label = Label(f1, image=filename)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
C.pack()

def registrace():
    raise_frame(f2)
    print(ID)
    ID['text']=klienti.vyberID()

reg = Button(f1, text='Registrace nového klienta', bg= '#509ece', font= 'Arial 15',height=2, width=25, command=registrace)
reg.place(x=50,y=250)
Button(f1, text='Současní klienti',bg= '#509ece', font= 'Arial 15',height=2, width=25,command=lambda:raise_frame(f3)).place(x=50,y=350)

### FRAME 2 ###########
#########################################
#########################################
D = Canvas(f2, bg="blue", height=711, width=400)
filename2 = PhotoImage(file='C:\\Users\\verca\\OneDrive\\Plocha\\pozadi_menu.png')
background_label2 = Label(f2, image=filename2)
background_label2.place(x=0, y=0, relwidth=1, relheight=1)
D.pack()
nadpis = Label(f2, text='Registrace uživatele ', bg='#c2e2e1', font='Arial 25')
nadpis.place(x=50, y=150)

jmeno_text = Label(f2, text='Jméno: ', bg='#c2e2e1', font='Arial 15')
jmeno_text.place(x=10, y=200)
jmeno_dopln = Entry(f2, font='Arial 15', text='')
jmeno_dopln.place(x=100, y=200)

prijmeni_text = Label(f2, text='Příjmení: ', bg='#c2e2e1', font='Arial 15')
prijmeni_text.place(x=10, y=250)
prijmeni_dopln = Entry(f2, font='Arial 15', text='')
prijmeni_dopln.place(x=100, y=250)

pohlavi_text = Label(f2, text='Pohlaví: ', bg='#c2e2e1', font='Arial 15')
pohlavi_text.place(x=10, y=300)
vyber_pohlavi = [
    'muz',
    'zena'
]
clicked_pohl = StringVar()
clicked_pohl.set(vyber_pohlavi[0])
pohlavy_dopln = OptionMenu(f2, clicked_pohl, *vyber_pohlavi)
pohlavy_dopln.place(x=100, y=300)

fakulta_text = Label(f2, text='Fakulta: ', bg='#c2e2e1', font='Arial 15')
fakulta_text.place(x=10, y=350)
vyber_fakulty = [
    'FEKT',
    'FIT',
    'FSI',
    'FAST',
    'FA',
    'FCH',
    'FAVU',
    'USI',
    'CESA',
    'FP'
]
clicked_fak = StringVar()
clicked_fak.set(vyber_fakulty[0])
fakulta_dopln = OptionMenu(f2, clicked_fak, *vyber_fakulty)
fakulta_dopln.place(x=100, y=350)

ID_text = Label(f2, text='ID:', font='Arial 15', bg='#c2e2e1')
ID_text.place(x=10, y=400)
ID = Label(f2, text='x', font='Arial 15', bg='#c2e2e1')
ID.place(x=100, y=400)


def ukladani_new_klient():
    klienti.pridat_klienta(jmeno_dopln.get(), prijmeni_dopln.get(), clicked_pohl.get(), clicked_fak.get(),
                           klienti.vyberID())
    raise_frame(f1)

uloz = Button(f2, text='Uložit', command=ukladani_new_klient, bg='#509ece', font='Arial 15')
uloz.place(x=50, y =500)
zpet2 = Button(f2, text='Zpět do menu', bg='#509ece', font='Arial 15', command=lambda: raise_frame(f1))
zpet2.place(x=200, y = 500)

### FRAME 3 ###########
#########################################
#########################################
E = Canvas(f3, bg="blue", height=711, width=400)
filename3 = PhotoImage(file='C:\\Users\\verca\\OneDrive\\Plocha\\pozadi_menu.png')
background_label3 = Label(f3, image=filename3)
background_label3.place(x=0, y=0, relwidth=1, relheight=1)
E.pack()
Label(f3, text='Vyberte klienta', bg='#c2e2e1', font= 'Arial 15').place(x=120, y= 150)

List1 = Listbox(f3, font= 'Arial 15', height=10, width= 20)
List1.place(x=80, y= 200)
jmena= []
ID_sez=[]

for klient in klienti.nacist():
   jmena.append(klient['jmeno'] + ' ' + klient[ 'prijmeni'])
   ID_sez.append(klient['ID'])


for item in jmena:
    List1.insert(END, item)

def click():
    user=List1.get(ANCHOR)
    jmeno, prijmeni = user.split()
    jm = (klienti.ziskejID(jmeno,prijmeni))
    #jm=int(ID_dopln.get())
    #tst=clicked.get()
    #datas = databaze.uzivatel(jm,tst)
    #print(datas)
    import matplotlib.pyplot as plt
    fig1 = plt.figure(1)

    ax_plot1 = fig1.add_subplot(4, 4, 1)
    ax_plot1.plot(databaze.uzivatel(jm,'psychika'))
    ax_plot1.invert_yaxis()
    ax_plot1.set_ylim([60,0])
    ax_plot1.set_title('Psychika')

    ax_plot2 = fig1.add_subplot(4, 4, 2)
    ax_plot2.plot(databaze.uzivatel(jm,'pamet'))
    ax_plot2.set_ylim([1, 11])
    ax_plot2.set_title('Paměť')

    ax_plot3 = fig1.add_subplot(4, 4, 3)
    ax_plot3.plot(databaze.uzivatel(jm, 'pozornost'))
    ax_plot3.set_title('Pozornost')

    ax_plot4 = fig1.add_subplot(4, 4, 4)
    ax_plot4.plot(databaze.uzivatel(jm,'nalada'))
    ax_plot4.invert_yaxis()
    ax_plot4.set_ylim([5, 1])
    ax_plot4.set_title('Nálada')

    ax_plot5 = fig1.add_subplot(4, 4, 5)
    ax_plot5.plot(databaze.uzivatel(jm,'stabilita'))
    ax_plot5.invert_yaxis()
    ax_plot5.set_ylim([5, 1])
    ax_plot5.set_title('Stabilita nálady')

    ax_plot6 = fig1.add_subplot(4, 4, 6)
    ax_plot6.plot(databaze.uzivatel(jm, 'spanek'))
    ax_plot6.invert_yaxis()
    ax_plot6.set_ylim([5, 1])
    ax_plot6.set_title('Spánek')

    ax_plot7 = fig1.add_subplot(4, 4, 7)
    ax_plot7.plot(databaze.uzivatel(jm,'uzkost'))
    ax_plot7.invert_yaxis()
    ax_plot7.set_ylim([5, 1])
    ax_plot7.set_title('Úzkost')

    ax_plot8 = fig1.add_subplot(4, 4, 8)
    ax_plot8.plot(databaze.uzivatel(jm,'suicidalni myslenky'))
    ax_plot8.invert_yaxis()
    ax_plot8.set_ylim([5, 1])
    ax_plot8.set_title('Suicidální myšlenky')

    ax_plot9 = fig1.add_subplot(4, 4, 9)
    ax_plot9.plot(databaze.uzivatel(jm, 'skola pamet'))
    ax_plot9.invert_yaxis()
    ax_plot9.set_ylim([5, 1])
    ax_plot9.set_title('Škola paměť')

    ax_plot10 = fig1.add_subplot(4, 4, 10)
    ax_plot10.plot(databaze.uzivatel(jm,'soustredeni'))
    ax_plot10.invert_yaxis()
    ax_plot10.set_ylim([5, 1])
    ax_plot10.set_title('Soustředění')

    ax_plot11 = fig1.add_subplot(4, 4, 11)
    ax_plot11.plot(databaze.uzivatel(jm,'orientace'))
    ax_plot11.invert_yaxis()
    ax_plot11.set_ylim([5, 1])
    ax_plot11.set_title('Orientace')

    ax_plot12 = fig1.add_subplot(4, 4, 12)
    ax_plot12.plot(databaze.uzivatel(jm, 'narocnost'))
    ax_plot12.invert_yaxis()
    ax_plot12.set_ylim([5, 1])
    ax_plot12.set_title('Náročnost')

    ax_plot13 = fig1.add_subplot(4, 4, 13)
    ax_plot13.plot(databaze.uzivatel(jm, 'kolektiv'))
    ax_plot13.invert_yaxis()
    ax_plot13.set_ylim([5,1])
    ax_plot13.set_title('Kolektiv')

    plt.tight_layout()
    plt.show()
    #if tst == 'pamet':
     #   plt.plot(datas)
      #  plt.title(tst)
       # plt.show()
    #else:
     #   plt.plot(datas)
      #  plt.gca().invert_yaxis()
       # plt.title(tst)
        #plt.show()
    #pozdrav=Label(root, text= 'ahoj '+jmeno_dopln.get()).grid(row=3, column=0)

potvrd= Button(f3, text='OK', font= 'Arial 15', command=click)
potvrd.place(x=50, y= 500)
potvrd.configure(bg='#509ECE')
zpet3= Button(f3, text='zpět do menu', font= 'Arial 15',command=lambda:raise_frame(f1))
zpet3.place(x=250, y= 500)






raise_frame(f1)
root.mainloop()