import { Button, VerticalBox ,TextEdit, HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox, LineEdit, ScrollView, ComboBox, Slider} from "std-widgets.slint";
import {SelectableTableView} from "selectable_tree_view.slint";
import {LeftSidePanel} from "left_side_panel.slint";
import {MainList} from "main_lists.slint";
import {CurrentTab, ProgressToSend} from "common.slint";
import { ActionButtons } from "action_buttons.slint";
import { Progress } from "progress.slint";
import {MainListModel} from "common.slint";
import {Settings} from "settings.slint";
import {Callabler} from "callabler.slint";
import { BottomPanel } from "bottom_panel.slint";
import {ColorPalette} from "color_palette.slint";
import {GuiState} from "gui_state.slint";
import { Preview } from "preview.slint";
import {PopupNewDirectories} from "popup_new_directories.slint";
import {TextComponent} from "settings_list.slint";

component ComboBoxWrapper inherits HorizontalLayout {
    in-out property <string> text;
    in-out property <[string]> model;
    in-out property <int> current_index;
    in-out property <string> current_value;
    spacing: 5px;
    Text {
        text <=> root.text;
        vertical_alignment: TextVerticalAlignment.center;
    }
    ComboBox {
        model: root.model;
        current_index <=> root.current_index;
        current_value <=> root.current_value;
    }
}

component CheckBoxWrapper inherits CheckBox {
    
}

component SubsettingsHeader inherits Text {
    text: "Subsettings";
    font-size: 15px;
}

component SliderWrapper inherits HorizontalLayout {
    in-out property <float> maximum;
    in-out property <float> value;
    in-out property <string> text;
    in-out property <string> end_text;
    in-out property <length> end_text_size;
    spacing: 5px;
    Text {
        text: root.text;
    }
    Slider {
        min-width: 30px;
        minimum: 0;
        maximum <=> root.maximum;
        value <=> root.value;
    }
    Text {
        text: root.end_text;
        width: root.end_text_size;
    }
}

export component ToolSettings {
    ScrollView {
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.SimilarImages;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            ComboBoxWrapper {
                text: "Hash size";
                model: Settings.similar_images_sub_available_hash_size;
                current_index <=> Settings.similar_images_sub_hash_size_index;
                current_value <=> Settings.similar_images_sub_hash_size_value;
            }
            ComboBoxWrapper {
                text: "Resize Algorithm";
                model: Settings.similar_images_sub_available_resize_algorithm;
                current_index <=> Settings.similar_images_sub_resize_algorithm_index;
                current_value <=> Settings.similar_images_sub_resize_algorithm_value;
            }
            ComboBoxWrapper {
                text: "Hash type";
                model: Settings.similar_images_sub_available_hash_type;
                current_index <=> Settings.similar_images_sub_hash_alg_index;
                current_value <=> Settings.similar_images_sub_hash_alg_value;
            }
            CheckBoxWrapper {
                text: "Ignore same size";
                checked <=> Settings.similar_images_sub_ignore_same_size;
            }
            SliderWrapper {
                text: "Max difference";
                end_text: "(" + round(Settings.similar_images_sub_current_similarity) + "/" + round(Settings.similar_images_sub_max_similarity) + ")";
                end_text_size: 40px;
                maximum <=> Settings.similar_images_sub_max_similarity;
                value <=> Settings.similar_images_sub_current_similarity;
            }
            Rectangle {}
        }
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.DuplicateFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            ComboBoxWrapper {
                text: "Check method";
                model: Settings.duplicates_sub_check_method;
                current_index <=> Settings.duplicates_sub_check_method_index;
                current_value <=> Settings.duplicates_sub_check_method_value;
            }
            ComboBoxWrapper {
                text: "Hash type";
                model: Settings.duplicates_sub_available_hash_type;
                current_index <=> Settings.duplicates_sub_available_hash_type_index;
                current_value <=> Settings.duplicates_sub_available_hash_type_value;
            }
            CheckBoxWrapper {
                text: "Case Sensitive(only name modes)";
                checked <=> Settings.duplicates_sub_name_case_sensitive;
            }
            Rectangle {}
        }
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.BigFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            ComboBoxWrapper {
                text: "Checked files";
                model: Settings.biggest_files_sub_method;
                current_index <=> Settings.biggest_files_sub_method_index;
                current_value <=> Settings.biggest_files_sub_method_value;
            }
            TextComponent {
                name: "Number of files";
                model <=> Settings.biggest_files_sub_number_of_files;
            }
            Rectangle {}
        }
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.SimilarVideos;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            SliderWrapper {
                text: "Max difference";
                end_text: "(" + round(Settings.similar_videos_sub_current_similarity) + "/" + round(Settings.similar_videos_sub_max_similarity) + ")";
                end_text_size: 40px;
                maximum <=> Settings.similar_videos_sub_max_similarity;
                value <=> Settings.similar_videos_sub_current_similarity;
            }
            CheckBoxWrapper {
                text: "Ignore same size";
                checked <=> Settings.similar_images_sub_ignore_same_size;
            }
            Rectangle {}
        }
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.SimilarMusic;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            ComboBoxWrapper {
                text: "Audio check type";
                model: Settings.similar_music_sub_audio_check_type;
                current_index <=> Settings.similar_music_sub_audio_check_type_index;
                current_value <=> Settings.similar_music_sub_audio_check_type_value;
            }
            // A little bit of a hack
            // Mode should be set with a enum, not index, but it's not possible in slint(maybe yet)
            if Settings.similar_music_sub_audio_check_type_index == 0: VerticalLayout {
                spacing: 5px;
                CheckBoxWrapper {
                    text: "Approximate Tag Comparison";
                    checked <=> Settings.similar_music_sub_approximate_comparison;
                }
                Text {
                    text: "Compared tags";
                    font-size: 12px;
                }
                CheckBoxWrapper {
                    text: "Title";
                    checked <=> Settings.similar_music_sub_title;
                }
                CheckBoxWrapper {
                    text: "Artist";
                    checked <=> Settings.similar_music_sub_artist;
                }
                CheckBoxWrapper {
                    text: "Bitrate";
                    checked <=> Settings.similar_music_sub_bitrate;
                }
                CheckBoxWrapper {
                    text: "Genre";
                    checked <=> Settings.similar_music_sub_genre;
                }
                CheckBoxWrapper {
                    text: "Year";
                    checked <=> Settings.similar_music_sub_year;
                }
                CheckBoxWrapper {
                    text: "Length";
                    checked <=> Settings.similar_music_sub_length;
                }
            }
            if Settings.similar_music_sub_audio_check_type_index == 1: VerticalLayout {
                spacing: 5px;
                SliderWrapper {
                    text: "Max difference";
                    end_text: "(" + round(Settings.similar_music_sub_maximum_difference_value) + "/" + round(Settings.similar_music_sub_maximum_difference_max) + ")";
                    end_text_size: 40px;
                    maximum <=> Settings.similar_music_sub_maximum_difference_max;
                    value <=> Settings.similar_music_sub_maximum_difference_value;
                }
                SliderWrapper {
                    text: "Minimal fragment duration";
                    end_text: round(Settings.similar_music_sub_minimal_fragment_duration_value);
                    end_text_size: 40px;
                    maximum <=> Settings.similar_music_sub_minimal_fragment_duration_max;
                    value <=> Settings.similar_music_sub_minimal_fragment_duration_value;
                }

            }
            Rectangle {}
        }
        VerticalLayout {
            visible: GuiState.active_tab == CurrentTab.BrokenFiles;
            spacing: 5px;
            padding: 10px;
            SubsettingsHeader { }
            Text {
                text: "Type of files to check";
                font-size: 12px;
            }
            CheckBoxWrapper {
                text: "Audio";
                checked <=> Settings.broken_files_sub_audio;
            }
            CheckBoxWrapper {
                text: "Pdf";
                checked <=> Settings.broken_files_sub_pdf;
            }
            CheckBoxWrapper {
                text: "Archive";
                checked <=> Settings.broken_files_sub_archive;
            }
            CheckBoxWrapper {
                text: "Image";
                checked <=> Settings.broken_files_sub_image;
            }
            
            Rectangle {}
        }
    }
}