import { Button, VerticalBox , HorizontalBox, TabWidget, ListView, StandardListView, StandardTableView, CheckBox} from "std-widgets.slint";
import {SelectableTableView} from "selectable_tree_view.slint";
import {LeftSidePanel} from "left_side_panel.slint";
import {CurrentTab, TypeOfOpenedItem} from "common.slint";
import {MainListModel} from "common.slint";
import {SettingsList} from "settings_list.slint";
import {GuiState} from "gui_state.slint";
import {About} from "about.slint";

export component MainList {
    in-out property <[MainListModel]> duplicate_files_model: [];
    in-out property <[MainListModel]> empty_folder_model: [
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["kropkarz", "/Xd1", "24.10.2023"], val_int: []} ,
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> big_files_model: [];
    in-out property <[MainListModel]> empty_files_model: [
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["kropkarz", "/Xd1", "24.10.2023"], val_int: []} ,
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> temporary_files_model: [];
    in-out property <[MainListModel]> similar_images_model: [
        {checked: false, selected_row: false, header_row: true, filled_header_row: false, val_str: ["Original", "500KB", "100x100", "kropkarz", "/Xd1", "24.10.2023"], val_int: []},
        {checked: false, selected_row: false, header_row: false, filled_header_row: false, val_str: ["Similar", "500KB", "100x100", "witasphere", "/Xd1/Imagerren2", "25.11.1991"], val_int: []},
        {checked: true, selected_row: false, header_row: false, filled_header_row: false, val_str: ["Similar", "500KB", "100x100", "lokkaler", "/Xd1/Vide2", "01.23.1911"], val_int: []}
    ];
    in-out property <[MainListModel]> similar_videos_model: [];
    in-out property <[MainListModel]> similar_music_model: [];
    in-out property <[MainListModel]> invalid_symlinks_model: [];
    in-out property <[MainListModel]> broken_files_model: [];
    in-out property <[MainListModel]> bad_extensions_model: [];

    callback changed_current_tab();
    callback released_key(string);

    out property <length> path_px: 350px;
    out property <length> name_px: 100px;
    out property <length> mod_px: 150px;
    out property <length> size_px: 75px;
    
    duplicates := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.DuplicateFiles;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Size", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, size_px, name_px, path_px, mod_px];
        values <=> duplicate_files_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    empty_folders := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.EmptyFolders;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Folder Name", "Path", "Modification Date"];
        column-sizes: [35px, name_px, path_px, mod_px];
        values <=> empty-folder-model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    big_files := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.BigFiles;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Size", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, size_px, name_px, path_px, mod_px];
        values <=> big_files_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    empty_files := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.EmptyFiles;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, name_px, path_px, mod_px];
        values <=> empty-files-model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    temporary_files := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.TemporaryFiles;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, name_px, path_px, mod_px];
        values <=> temporary_files_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    similar_images := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.SimilarImages;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Similarity", "Size", "Dimensions", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, 80px, 80px, 80px, name_px, path_px, mod_px];
        values <=> similar-images-model;
        parentPathIdx: 5;
        fileNameIdx: 4;
    }

    similar_videos := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.SimilarVideos;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Size", "File Name", "Path", "Modification Date"];
        column-sizes: [35px, size_px, name_px, path_px, mod_px];
        values <=> similar_videos_model;
        parentPathIdx: 3;
        fileNameIdx: 2;
    }

    similar_music := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.SimilarMusic;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Size", "File Name", "Title","Artist", "Year", "Bitrate", "Length", "Genre", "Path", "Modification Date"];
        column-sizes: [35px, size_px, name_px, 80px, 80px, 80px, 80px, 80px, 80px, path_px, mod_px];
        values <=> similar_music_model;
        parentPathIdx: 9;
        fileNameIdx: 2;
    }

    invalid_symlink := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.InvalidSymlinks;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "Symlink Name", "Symlink Folder", "Destination Path", "Modification Date"];
        column-sizes: [35px, name_px, path_px, path_px, mod_px];
        values <=> invalid_symlinks_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    broken_files := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.BrokenFiles;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "File Name", "Path", "Type of Error", "Size", "Modification Date"];
        column-sizes: [35px, name_px, path_px, 200px, size_px, mod_px];
        values <=> broken_files_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    bad_extensions := SelectableTableView {
        visible: GuiState.active_tab == CurrentTab.BadExtensions;
        min-width: 200px;
        height: parent.height;
        columns: ["Selection", "File Name", "Path", "Current Extension", "Proper Extension"];
        column-sizes: [35px, name_px, path_px, 40px, 200px];
        values <=> bad_extensions_model;
        parentPathIdx: 2;
        fileNameIdx: 1;
    }

    settings_list := SettingsList {
        visible: GuiState.active_tab == CurrentTab.Settings;
    }

    about_app := About {
        visible: GuiState.active_tab == CurrentTab.About;
    }

    focus_item := FocusScope {
        width: 0px; // Hack to not steal first click from other components - https://github.com/slint-ui/slint/issues/3503
        // Hack not works https://github.com/slint-ui/slint/issues/3503#issuecomment-1817809834 because disables key-released event

        key-released(event) => {
            if (!self.visible || !self.has-focus) {
                return accept;
            }
            if (GuiState.active_tab == CurrentTab.EmptyFiles) {
                empty_files.released_key(event);
            } else if (GuiState.active_tab == CurrentTab.EmptyFolders) {
                empty-folders.released_key(event);
            } else if (GuiState.active_tab == CurrentTab.SimilarImages) {
                similar-images.released_key(event);
            } else {
                debug("Non handled key in main_lists.slint");
            }
            accept
        }
    }
    changed_current_tab() => {
        empty_folders.deselect_selected_item();
        empty_files.deselect_selected_item();
        similar_images.deselect_selected_item();
    }
}
