# n = True
# print(type(n))

# a = "5"
# b = 3

# print(int(a)+b)

# imie = "Janek"
# wzrost = 1.78
# wiek = 15
# pelnoletni = True 

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("@@ Nieprawidłowy numer zadania. @@") 

def delete_task(index):
    if 0 <= index < len(tasks):
        removed = tasks.pop(tasks)
        print(f"!!! Zadanie {removed['description']} jako wykonane !!!")
    else:
        print("@@ Nieprawidłowy numer 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 zobczenia!")
            break
menu()
 
