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

export component UserEditView inherits HorizontalLayout {
    padding: Style.spacing;
    spacing: Style.spacing;
    in property <string> username;
    in-out property <string> identicon;
    callback compute_identicon(encrypted_key: string, password: string);
    callback confirm(encrypted_key: string);
    callback cancel <=> button_cancel.clicked;
    VerticalLayout {
        spacing: Style.spacing;
        Rectangle { }

        Text {
            text: "Enter " + username + "'s encrypted key and press Enter:";
        }

        line_edit_encrypted_key := LineEdit {
            input-type: InputType.text;
            placeholder-text: "Encrypted key";
            edited(text) => {
                root.identicon = "";
            }
            accepted(text) => {
                line_edit_password.focus();
            }
        }

        line_edit_password := LineEdit {
            input-type: InputType.text;
            placeholder-text: "Password";
            edited(text) => {
                root.identicon = "";
            }
            accepted(text) => {
                compute_identicon(line_edit_encrypted_key.text, text);
            }
        }

        Text {
            text: identicon.is-empty ? "" : ("Check the identicon: " + identicon);
        }

        HorizontalLayout {
            spacing: Style.spacing;
            button_cancel := Button {
                text: "Cancel";
            }

            button_confirm := Button {
                text: "Confirm";
                enabled: !identicon.is-empty;
                clicked => {
                    confirm(line_edit_encrypted_key.text);
                }
            }
        }

        Rectangle { }
    }
}
