# Copyright (C) 2026 BoundWare LLC. All rights reserved.
# SnacTrac is licensed under the Apache License, Version 2.0
# See Licenses/LICENSE.txt for details.


import PySimpleGUI as sg
from asset_image_icon_snactrac import *
from asset_image_qr_donate import *
from get_version import *
from move_window_center import *
from play_sound import *


# Handle test window interaction.
def window_donate():

    timeout = 0

    layout = [
        [
            sg.Frame(
                title=None,
                layout=[],
                size=(0, 20),
                pad=(0, 0),
            ),
        ],
        [
            sg.Push(),
            sg.Text(
                text="DONATE",
                font=("Roboto", 19, "bold"),
                pad=(0, 0),
            ),
            sg.Push(),
        ],
        [
            sg.Push(),
            sg.Frame(
                title=None,
                layout=[],
                size=(7, 0),
                pad=(0, 0),
            ),
            sg.Text(
                text="Scan the QR code below to support the project!",
                font=("Roboto", 12, "bold"),
                pad=(0, 0),
            ),
            sg.Frame(
                title=None,
                layout=[],
                size=(6, 0),
                pad=(0, 0),
            ),
            sg.Push(),
        ],
        [
            sg.Frame(
                title=None,
                layout=[],
                size=(0, 31),
                pad=(0, 0),
            ),
        ],
        [
            sg.Push(),
            sg.Image(
                source=qr_donate,
                key="-IMAGE_QR_DONATE-",
                size=(338, 338),
                pad=(0, 0),
                enable_events=False,
                ),
            sg.Push(),
        ],
        [
            sg.Frame(
                title=None,
                layout=[],
                size=(0, 21),
                pad=(0, 0),
            ),
        ],
        [
            sg.Push(),
            sg.Button(
                button_text="Close [ENTER]",
                font=("Roboto", 13, "bold"),
                key="-BUTTON_CLOSE-",
            ),
            sg.Push(),
        ],
    ]

    window = sg.Window(
        title="SnacTrac %s - Donate" % get_version(),
        size=(1095, 721),
        layout=layout,
        finalize=True,
        modal=True,
        enable_close_attempted_event=True,
        icon=icon_snactrac,
    )

    while True:

        event, values = window.read(timeout)

        if timeout == None and (
            event == "-BUTTON_CLOSE-" or event == sg.WIN_CLOSE_ATTEMPTED_EVENT
        ):

            play_sound("tick")

            window.close()

            return "admin"

        if timeout == 0:

            window.bind("<Return>", "-BUTTON_CLOSE-")

            move_window_center(window)

            timeout = None

            play_sound("pop")