import { Label, Theme } from "base.slint";
import { Button } from "button.slint";
import { Icons } from "icons.slint";
import { UiCue } from "audio.slint";
export component Link {
    in property <string> text;
    in property <color> color: Theme.link;
    in property <bool> underline: true;
    in property <bool> wrap-text;
    callback clicked();
    out property <bool> hovered: touch.has-hover;
    preferred-width: label.preferred-width; preferred-height: root.wrap-text ? label.preferred-height : 20px;
    // Titillium kerns // by -281/1000 em. A display-only hair space separates the glyphs.
    label := Label { width: root.width; height: root.height; vertical-alignment: center;
        text: root.text.replace-all("//", "/\u{200a}/"); color: root.color; wrap: root.wrap-text ? word-wrap : no-wrap; }
    if root.underline: Rectangle { x: 0px; y: root.height / 2 + 7px; height: 1px; width: min(root.width, label.preferred-width); background: root.color; }
    touch := TouchArea { width: root.width; height: root.height; mouse-cursor: pointer; clicked => { root.clicked(); } }
}
export component DependencyLine {
    in property <string> text;
    in property <bool> optional: true;
    in property <bool> required;
    in property <bool> incompatible;
    in property <bool> underline: false;
    // Required and not active, or an incompatible mod that is active: drawn red like the game.
    in property <bool> red;
    in property <bool> installed;
    in property <bool> wrap-text;
    callback clicked();
    callback manage-focus();
    callback hover-changed(bool);
    preferred-height: max(28px, link.preferred-height);
    property <bool> hovered: link.hovered;
    changed hovered => { root.hover-changed(root.hovered); }
    Button { sound: UiCue.tool; x: 0px; y: (root.height - 16px)/2; width: 16px; min-width: 0px; height: 16px; min-height: 0px; clicked => { root.clicked(); } }
    Image { x: 4px; y: (root.height - 8px)/2; width: 8px; height: 8px; source: Icons.dependency-arrow; image-rendering: pixelated; }
    if root.installed: Rectangle { x: 24px; y: (root.height - 16px)/2; width: 16px; height: 16px;
        Button { sound: UiCue.tool; x: 0px; y: 0px; width: parent.width; height: parent.height; clicked => { root.manage-focus(); } }
        Image { x: 2px; y: 2px; width: 12px; height: 12px; source: @image-url("../../../assets/ui/table.svg"); }
    }
    link := Link { x: root.installed ? 48px : 24px; width: root.width - self.x; height: root.height; wrap-text: root.wrap-text; text: root.text; color: root.red || root.incompatible ? #ff8e8e : root.required ? Theme.text : root.optional ? Theme.orange : Theme.link; underline: root.underline; clicked => { root.clicked(); } }
}
export component Separator {
    in property <bool> vertical: false;
    Image { width: root.width; height: root.height; source: root.vertical ? @image-url("../../../assets/game/pieces/1/line_vertical_line-default-base.png") : @image-url("../../../assets/game/pieces/1/line_horizontal_line-default-base.png"); image-fit: fill; image-rendering: pixelated; }
}
