// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT

import { ComboBox, HorizontalBox, VerticalBox, Switch } from "std-widgets.slint";
import { Page } from "page.slint";

export global SettingsData {
    in-out property <bool> integer_scaling;
    in-out property <bool> ssaa;
    in-out property <bool> fullscreen;
    in-out property <bool> widescreen;
    in-out property <bool> vsync;
    in-out property <bool> apply_crt_shader;
    in-out property <bool> overclock_n64_cpu;
    in-out property <bool> disable_expansion_pak;
    in-out property <int> resolution;
    in-out property <bool> emulate_usb;
    in-out property <bool> rewind;
    in-out property <bool> emulate_vru;
    in-out property <string> rom_dir;
}

export component Settings inherits Page {
    title: @tr("Settings");

    VerticalBox {
        alignment: start;
        HorizontalBox {
            alignment: center;
            VerticalBox {
                alignment: start;
                HorizontalBox {
                    alignment: start;
                    Text {
                        text: @tr("Resolution:");
                        vertical-alignment: center;
                    }

                    ComboBox {
                        model: ["1x", "2x", "4x", "8x"];
                        current-index: SettingsData.resolution;
                        selected => {
                            SettingsData.resolution = self.current-index;
                        }
                    }
                }

                Switch {
                    text: @tr("SSAA downscaling");
                    checked: SettingsData.ssaa;
                    toggled => {
                        SettingsData.ssaa = self.checked;
                    }
                }

                Switch {
                    text: @tr("Integer Scaling");
                    checked: SettingsData.integer_scaling;
                    toggled => {
                        SettingsData.integer_scaling = self.checked;
                    }
                }

                Switch {
                    text: @tr("Fullscreen");
                    checked: SettingsData.fullscreen;
                    toggled => {
                        SettingsData.fullscreen = self.checked;
                    }
                }

                Switch {
                    text: @tr("Widescreen (stretch)");
                    checked: SettingsData.widescreen;
                    toggled => {
                        SettingsData.widescreen = self.checked;
                    }
                }

                Switch {
                    text: @tr("VSync");
                    checked: SettingsData.vsync;
                    toggled => {
                        SettingsData.vsync = self.checked;
                    }
                }

                Switch {
                    text: @tr("Apply CRT shader");
                    checked: SettingsData.apply_crt_shader;
                    toggled => {
                        SettingsData.apply_crt_shader = self.checked;
                    }
                }

                Rectangle {
                    height: 20px;
                }

                Switch {
                    text: @tr("Overclock N64 CPU (may cause bugs)");
                    checked: SettingsData.overclock_n64_cpu;
                    toggled => {
                        SettingsData.overclock_n64_cpu = self.checked;
                    }
                }

                Switch {
                    text: @tr("Disable Expansion Pak");
                    checked: SettingsData.disable_expansion_pak;
                    toggled => {
                        SettingsData.disable_expansion_pak = self.checked;
                    }
                }

                Switch {
                    text: @tr("Enable Rewind");
                    checked: SettingsData.rewind;
                    toggled => {
                        SettingsData.rewind = self.checked;
                    }
                }

                Switch {
                    text: @tr("Emulate UNFLoader");
                    checked: SettingsData.emulate_usb;
                    toggled => {
                        SettingsData.emulate_usb = self.checked;
                    }
                }

                Switch {
                    text: @tr("Emulate VRU");
                    checked: SettingsData.emulate_vru;
                    toggled => {
                        SettingsData.emulate_vru = self.checked;
                    }
                }
            }
        }
    }
}
