import { InterFont } from "@kit-fonts/inter.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { KitRouter, KitScreen, KitButton, KitCard, RouteChange, KitTheme, KitThemes } from "@kit";
// In an application, Rust owns the stack with `Router<R>` and projects `route`, `change` and `can-go-back`.
export enum DemoRoute { projects, details, edit }

export component Example inherits Window {
    in-out property <string> status;
    default-font-family: InterFont.family;
    title: "KitScreen example";
    preferred-width: 520px;
    preferred-height: 310px;
    max-width: 100000px;
    max-height: 100000px;
    background: root.theme.canvas;
    in-out property <KitTheme> theme: KitThemes.light;
    in-out property <DemoRoute> route: DemoRoute.projects;
    in-out property <RouteChange> change: RouteChange.replace;
    out property <bool> can-go-back: root.route != DemoRoute.projects;

    KitRouter {
        can-go-back: root.can-go-back;
        back => { root.change = RouteChange.pop; root.route = root.route == DemoRoute.edit ? DemoRoute.details : DemoRoute.projects; }
        KitScreen {
            theme: root.theme; active: root.route == DemoRoute.projects; change: root.change;
            VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
                Text { text: "Projets"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
                KitButton { theme: root.theme; text: "Ouvrir Atlas"; activated => { root.change = RouteChange.push; root.route = DemoRoute.details; } }
            }
        }
        KitScreen {
            theme: root.theme; active: root.route == DemoRoute.details; change: root.change;
            VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
                Text { text: "Atlas"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
                Text { text: "Appuyez sur Échap ou Retour pour revenir à la liste."; color: root.theme.text-secondary; wrap: word-wrap; }
                KitButton { theme: root.theme; text: "Modifier"; activated => { root.change = RouteChange.push; root.route = DemoRoute.edit; } }
            }
        }
        KitScreen {
            theme: root.theme; active: root.route == DemoRoute.edit; change: root.change;
            VerticalLayout { padding: 24px; spacing: 16px; alignment: start;
                Text { text: "Modifier Atlas"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
                KitButton { theme: root.theme; text: "Retour"; activated => { root.change = RouteChange.pop; root.route = DemoRoute.details; } }
            }
        }
    }
}
