# a = 5
# b = 3
# print(int(a)+b)

# imie = "Piotr"
# wzrost = 1.7
# wiek = 14
# if wiek>=18:
#     pelnoletni=True
# else:
#     pelnoletni=False

# print("Czyli masz na imię", imie , "masz ", wzrost , "m wzrostu masz", wiek, "lat i jesteś pełnoletni", pelnoletni)
import json
import os

tasks = []

def load_tasks():
    global tasks
    if os.path.exists("tasks.json"):
        with open("tasks.json", "r") as row:
            tasks = json.load(row)

def save_tasks():
    with open("tasks.json", "w") as row:
        json.dump(tasks, row, indent=4)

def add_task(desc):
    tasks.append({"description": desc, "done": False})

def show_tasks():
    if not tasks:
        print("Brak zadań")
    else:
        for i, task in enumerate(tasks):
            status = "[x]" if task["done"] else "[ ]"
            print(f"{i+1}. {status} {task["description"]}")

def mark_done(index):
    if 0 <= index < len(tasks):
        tasks[index]["done"] = True
        print("Zadanie oznaczone jako wykonane")
    else:
        print("@@ Nie ma takiego zadania @@")

def delete_task(index):
    if 0 <= index < len(tasks):
        removed = tasks.pop(index)
        print("Zadanie", {removed['description']} ,"zostało wykonane")
    else:
        print("@@ Nie ma takiego zadania @@")

def menu():
    load_tasks()
    while True:
        print("1. Dodaj zadanie")
        print("2. Wyświetl listę")
        print("3. Oznacz jako wykonane")
        print("4. Usuń zadanie")
        print("5. Zapisz i wyjdź")


        choice = input("Wybierz opcję (1-5): ")

        if choice == "1":
            desc = input("Podaj opis zadania: ")
            add_task(desc)
        elif choice =="2":
            show_tasks()
        elif choice =="3":
            index = input("Podaj numer zadania: ")
            mark_done(int(index)-1)
        elif choice =="4":
            index = input("Podaj numer zadania: ")
            delete_task(int(index)-1)
        elif choice =="5":
            save_tasks()
            print("Zadania zapisane. Do zobaczenia")
            break
        
menu()