export { KitFormValidation, HtmlInputKind, NumberInputFormat, KitInputConstraints, KitValidationResult, KitValidityState } from "@kit/kit.slint";
// SPDX-License-Identifier: GPL-3.0-or-later
import { KitInputGroup, KitInputGroupText, KitTheme, KitThemes } from "@kit/kit.slint";

export component App inherits Window {
    title: "KitInputGroupText example";
    preferred-width: 420px;
    preferred-height: 180px;
    max-width: 100000px;
    max-height: 100000px;
    background: root.theme.canvas;
    in-out property <KitTheme> theme: KitThemes.light;
    in-out property <string> draft-0: "129.95";
    VerticalLayout {
        padding: 24px; spacing: 16px; alignment: start;
        Text { text: "Input Group Text"; color: root.theme.text-primary; font-size: 20px * root.theme.text-scale; font-weight: 600; }
        KitInputGroup {
            theme: root.theme; focused: editor.has-focus;
            HorizontalLayout {
                spacing: 8px;
                KitInputGroupText { theme: root.theme; text: "USD"; }
                Rectangle {
                    horizontal-stretch: 1; min-width: 0px; clip: true;
                    viewport := Flickable {
                        interactive: false;
                        content-width: max(self.width, editor.preferred-width + 2px);
                        content-height: self.height;
                        editor := TextInput {
                            width: viewport.content-width; height: viewport.height;
                            single-line: true; input-type: InputType.decimal;
                            accessible-label: "Amount";
                            font-size: 14px * root.theme.text-scale;
                            horizontal-alignment: left; vertical-alignment: center;
                            text <=> root.draft-0; color: root.theme.text-primary;
                            cursor-position-changed(position) => {
                                if (position.x + viewport.content-x < 0px) {
                                    viewport.content-x = -position.x;
                                } else if (position.x + 2px + viewport.content-x > viewport.width) {
                                    viewport.content-x = viewport.width - position.x - 2px;
                                }
                            }
                        }
                    }
                }

            }
        }
    }
}
