// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT

import { Button, HorizontalBox, VerticalBox, GroupBox } from "std-widgets.slint";
import { Page } from "page.slint";
import { AboutData, NewVersionButton } from "about_page.slint";

export global State {
    in-out property <bool> game_running;
    in-out property <bool> is_android;
    in-out property <[{a:string, b:string}]> recent_roms;
}

export component LocalGame inherits Page {
    callback open_rom_button_clicked;
    callback saves_folder_button_clicked;
    callback newversion_button_clicked;
    callback recent_rom_button_clicked(string);
    title: @tr("Local Game");

    VerticalBox {
        alignment: start;
        HorizontalBox {
            alignment: center;
            Button {
                text: @tr("Open ROM");
                enabled: !State.game_running;
                clicked => {
                    open_rom_button_clicked();
                }
            }
        }

        if !State.is_android:HorizontalBox {
            alignment: center;
            Button {
                text: @tr("Open Saves Folder");
                clicked => {
                    saves_folder_button_clicked();
                }
            }
        }

        if AboutData.has_update:NewVersionButton {
            newversion_button_clicked => {
                newversion_button_clicked();
            }
        }
        Rectangle { }

        if State.recent_roms.length>0:HorizontalBox {
            alignment: center;
            GroupBox {
                title: @tr("Recent ROMs");
                VerticalLayout {
                    alignment: space-between;
                    for rom in State.recent_roms: Button {
                        text: rom.b;
                        enabled: !State.game_running;
                        clicked => {
                            recent_rom_button_clicked(rom.a);
                        }
                    }
                }
            }
        }
    }
}
