# n = 11
# print(type(n))

# a = "5"
# b = 3

# print(int(a)+b)

# imie = "Krz"
# wzrost = 1.81
# wiek = 15
# pelnoletni = "tak"
# wiekMental = 45

# print(imie, wzrost, wiek, wiekMental)

# import calendar
# yy = 2025
# mm = 9
# print(calendar.month(yy, mm))
import json
import os

tasks = []

def load_tasks():
    global tasks
    if os.path.exist("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("!!! Oznaczono jako wykonane !!!")
    else:
        print("@@ Nieprawidłowy numer zadania @@")

def delete_task(index):
    if 0 <= index < len(tasks):
        removed = tasks.pop(index)
        print(f"!!! Zadanie {removed['description']} Usuniete !!!")
    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 zadaia: ")
            add_task(desc)
        elif choice =="2":
            show_tasks()
        elif choice =="3":
            index = input("Podaj nr zadania: ")
            mark_done(int(index)-1)
        elif choice =="4":
            index = input("Podaj nr zadania: ")
            delete_task(int(index)-1)
        elif choice =="5":
            save_tasks()
            print("Zadanie zapisane.")
            break
menu()

