import { LineEdit, StandardListView, Button } from "std-widgets.slint";
import { Style } from "globals.slint";
import { IconButton } from "widgets/icon-button.slint";

export component UsersView inherits HorizontalLayout {
    padding: Style.spacing;
    spacing: Style.spacing;
    callback edit_user(username: string, new: bool);
    VerticalLayout {
        spacing: Style.spacing * 2;
        VerticalLayout {
            spacing: Style.spacing;
            Text {
                text: "Add new user:";
            }

            line_edit_site_pw := LineEdit {
                input-type: InputType.text;
                placeholder-text: "Full Name";
                accepted(text) => {
                    edit_user(text, true);
                }
            }
        }

        VerticalLayout {
            spacing: Style.spacing;
            Text {
                text: "Edit existing user:";
            }

            FocusScope {
                forward-focus: list_view_sites;
                key-pressed(event) => {
                    if event.text == "\u{0D}" /* enter */ || event.text == " " /* space */ {
                        edit_user(list_view_sites.current-item, false);
                        EventResult.accept
                    } else {
                        EventResult.reject
                    }
                }
                list_view_sites := StandardListView { }
            }
        }
    }

    VerticalLayout {
        spacing: Style.spacing;
        IconButton {
            icon: @image-url("images/key.svg");
        }

        IconButton {
            icon: @image-url("images/trash-2.svg");
        }
    }
}
