# Copyright (C) 2017-2026 Arun Sivaraman <arunsivaramanneo@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import sys
import gi
gi.require_version('Gtk','4.0')
gi.require_version(namespace='Adw', version='1')

from gi.repository import Gtk,GdkPixbuf,GObject,Gio,Adw,GLib
from Common import ExpandDataObject, setup_expander,bind_expander,setup,bind1,add_tree_node, ExpandDataObject2,add_tree_node2,bind2,bind3,bind4,fetchContentsFromCommand
from itertools import islice

Adw.init()

import const
import Filenames
import subprocess
from Common import copyContentsFromFile, getGpuImage,create_scrollbar, getRamInGb,createSubTab,getDriverVersion,getDeviceSize, setMargin,fetchContentsFromCommand,getVulkanVersion,createMainFile,getLogo

def VulkanVideo(videoTab):



    tab_spinners = {}
    tab_content_containers = {}
    tabs_loading_count = {"count": 0}

    def hide_spinner_for_tab(tab_name):
        if tab_name in tab_spinners and tab_name in tab_content_containers:
            def update_ui():
                spinner = tab_spinners[tab_name]
                content_box, spinner_box = tab_content_containers[tab_name]
                spinner.set_spinning(False)
                spinner_box.set_visible(False)
                content_box.set_visible(True)
                tabs_loading_count["count"] -= 1
                return False
            GLib.idle_add(update_ui)

    def vProfiles(gpu):
        from concurrent.futures import ThreadPoolExecutor
        def run_cmd(cmd):
            return fetchContentsFromCommand(cmd)

        with ThreadPoolExecutor(max_workers=2) as pool:
            f1 = pool.submit(run_cmd, r"vulkaninfo | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;}/Display.*/{flag=0}flag' | awk /./ | awk '!/===/' "%(gpu,gpu+1))
            f2 = pool.submit(run_cmd, r"vulkaninfo | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk /./ | awk '!/===/' | awk '{gsub(/\(.*/, 'True');print}' | uniq "%(gpu,gpu+1))
        
        vulkanVideoProfiles = f1.result()
        vulkanVideoProfilesUniq = f2.result()
        
        vulkanVideoProfilesCount = []
        for i in range(len(vulkanVideoProfilesUniq)):
            count = 0
            for profile in vulkanVideoProfiles:
                if vulkanVideoProfilesUniq[i] in profile:
                    count = count + 1
            vulkanVideoProfilesCount.append(count)

        vulkanVideoProfilesUniq.append("")

        def update_ui():
            vkVideoProfilesTab_Store.remove_all()
            j = 0; k = 0 ; group = None
            toprow = None
            for line in vulkanVideoProfiles:
                if 'Video Profiles' in line:
                    toprow = ExpandDataObject(line.replace('count =',''),"")
                    continue
                if not toprow:
                    continue
                if vulkanVideoProfilesUniq[j] in line and j <= len(vulkanVideoProfilesUniq) - 2:
                    iter1 = ExpandDataObject(vulkanVideoProfilesUniq[j].replace("placeholder =","")+": %d" %vulkanVideoProfilesCount[j],"")
                    toprow.children.append(iter1)
                    iter2 = ExpandDataObject(line.replace("placeholder =",""),"")
                    iter1.children.append(iter2)
                    j = j + 1
                else:
                    iter2 = ExpandDataObject(line.replace("placeholder =",""),"")
                    # Try to append to the last iter1, or toprow if not exists
                    if len(toprow.children) > 0:
                        toprow.children[-1].children.append(iter2)
                    else:
                        toprow.children.append(iter2)
                    continue

            if toprow:
                vkVideoProfilesTab_Store.append(toprow)
            hide_spinner_for_tab("Video Profiles")
            return False
        GLib.idle_add(update_ui)

    def vDefinitions(gpu):
        from concurrent.futures import ThreadPoolExecutor
        def run_cmd(cmd):
            return fetchContentsFromCommand(cmd)

        with ThreadPoolExecutor(max_workers=4) as pool:
            f1 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Definition/{flag=1}/Video Profile Capabilities/{flag=0}flag'| awk /./ | awk '!/---|===/' "%(gpu,gpu+1))
            f2 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Definition/{flag=1}/Video Profile Capabilities/{flag=0}flag'| awk /./ | awk '!/---|===/' | awk '{gsub(/[=,:].*/,'True')}1' "%(gpu,gpu+1))
            f3 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Definition/{flag=1}/Video Profile Capabilities/{flag=0}flag'| awk /./ | awk '!/---|===/' | grep -o [=].* | grep -o ' .*' "%(gpu,gpu+1))
            f4 = pool.submit(run_cmd, "vulkaninfo | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;}flag' | awk /./ | awk '!/===/' | grep placeholder "%(gpu,gpu+1))

        vulkanVideoProfileDefinition = f1.result()
        vulkanVideoProfileDefinitionLHS = f2.result()
        vulkanVideoProfileDefinitionRHS = f3.result()
        vulkanVideoProfiles = f4.result()
        vulkanVideoProfiles.append("")

        def update_ui():
            vkVideoProfileDefinitionTab_Store.remove_all(); print("update_ui running for Profile Definition"); print("LENGTH:", len(vulkanVideoProfileDefinition))
            group = None
            j = 0;i =0 ;k = 0
            iter1 = None
            for line in vulkanVideoProfileDefinition:
                if '=' in line and "Video Profile Definition" not in line:
                    rhs = vulkanVideoProfileDefinitionRHS[k].replace('count =','') if k < len(vulkanVideoProfileDefinitionRHS) else ""
                    k = k + 1
                else:
                    rhs = ""
                if "Video Profile Definition" in line:
                    if group == None:
                        if j < len(vulkanVideoProfiles):
                            iter1 = ExpandDataObject((vulkanVideoProfiles[j]).replace("placeholder =",""),"")
                    else:
                        if iter1:
                            vkVideoProfileDefinitionTab_Store.append(iter1); print("Appended iter1 to Profile Definition Store")
                        if j < len(vulkanVideoProfiles):
                            iter1 = ExpandDataObject((vulkanVideoProfiles[j]).replace("placeholder =",""),"")
                    j = j + 1
                    i = i + 1
                    group = line
                    continue
                
                if not iter1 or i >= len(vulkanVideoProfileDefinitionLHS):
                    continue
                    
                lhs_val = vulkanVideoProfileDefinitionLHS[i].strip("\t")
                if "\t" in line and "\t\t" not in line:
                    iter2 = ExpandDataObject(lhs_val,rhs)
                    iter1.children.append(iter2)
                    i = i + 1
                    continue
                elif "\t\t" in line and "\t\t\t" not in line:
                    iter3 = ExpandDataObject(lhs_val,rhs)
                    iter2.children.append(iter3)
                    i = i + 1
                    continue
                elif "\t\t\t" in line and "\t\t\t\t" not in line:
                    iter4 = ExpandDataObject(lhs_val,rhs)
                    iter3.children.append(iter4)
                    i = i + 1
                    continue            
                elif "\t\t\t\t" in line and "\t\t\t\t\t" not in line:
                    iter5 = ExpandDataObject(lhs_val,rhs)
                    iter4.children.append(iter5)
                    i = i + 1
                    continue    
                else:
                    iter6 = ExpandDataObject(lhs_val,rhs)
                    iter5.children.append(iter6)
                    i = i + 1
                    
            if iter1:
                vkVideoProfileDefinitionTab_Store.append(iter1); print("Appended iter1 to Profile Definition Store")
            hide_spinner_for_tab("Profile Definition")
            return False
        GLib.idle_add(update_ui)
    def vCapabitlies(gpu):
        from concurrent.futures import ThreadPoolExecutor
        def run_cmd(cmd):
            return fetchContentsFromCommand(cmd)

        with ThreadPoolExecutor(max_workers=4) as pool:
            f1 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Capabilities/{flag=1}/Video Formats/{flag=0}flag'| awk /./ | awk '!/---|===/' "%(gpu,gpu+1))
            f2 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Capabilities/{flag=1}/Video Formats/{flag=0}flag'| awk /./ | awk '!/---|===/' | awk '{gsub(/[=,:].*/,'True')}1' "%(gpu,gpu+1))
            f3 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Profile Capabilities/{flag=1}/Video Formats/{flag=0}flag'| awk /./ | awk '!/---|===/' | grep -o [=].* | grep -o ' .*' "%(gpu,gpu+1))
            f4 = pool.submit(run_cmd, "vulkaninfo | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;}flag' | awk /./ | awk '!/===/' | grep placeholder "%(gpu,gpu+1))

        vulkanVideoCapabilities = f1.result()
        vulkanVideoCapabilitiesLHS = f2.result()
        vulkanVideoCapabilitiesRHS = f3.result()
        vulkanVideoProfiles = f4.result()
        vulkanVideoProfiles.append("")

        def update_ui():
            vkVideoCapabilitiesTab_Store.remove_all()
            group = None
            j = 0;i = 0 ; k = 0
            iter1 = None
            for line in vulkanVideoCapabilities:
                if '=' in line:
                    rhs = vulkanVideoCapabilitiesRHS[k].replace('count =','') if k < len(vulkanVideoCapabilitiesRHS) else ""
                    k = k + 1
                else:
                    rhs = ""
                if "Video Profile Capabilities" in line:
                    if group == None:
                        if j < len(vulkanVideoProfiles):
                            iter1 = ExpandDataObject((vulkanVideoProfiles[j]).replace("placeholder =",""),"")
                    else:
                        if iter1:
                            vkVideoCapabilitiesTab_Store.append(iter1)
                        if j < len(vulkanVideoProfiles):
                            iter1 = ExpandDataObject((vulkanVideoProfiles[j]).replace("placeholder =",""),"")
                    j = j + 1
                    i = i + 1
                    group = line
                    continue
                
                if not iter1 or i >= len(vulkanVideoCapabilitiesLHS):
                    continue
                    
                lhs_val = vulkanVideoCapabilitiesLHS[i].strip("\t")
                if "\t" in line and "\t\t" not in line:
                    iter2 = ExpandDataObject(lhs_val,rhs)
                    iter1.children.append(iter2)
                    i = i + 1
                    continue
                elif "\t\t" in line and "\t\t\t" not in line:
                    iter3 = ExpandDataObject(lhs_val,rhs)
                    iter2.children.append(iter3)
                    i = i + 1
                    continue
                elif "\t\t\t" in line and "\t\t\t\t" not in line:
                    iter4 = ExpandDataObject(lhs_val,rhs)
                    iter3.children.append(iter4)
                    i = i + 1
                    continue            
                elif "\t\t\t\t" in line and "\t\t\t\t\t" not in line:
                    iter5 = ExpandDataObject(lhs_val,rhs)
                    iter4.children.append(iter5)
                    i = i + 1
                    continue    
                else:
                    iter6 = ExpandDataObject(lhs_val,rhs)
                    iter5.children.append(iter6)
                    i = i + 1
                    
            if iter1:
                vkVideoCapabilitiesTab_Store.append(iter1)
            hide_spinner_for_tab("Video Capabilities")
            return False
        GLib.idle_add(update_ui)
    def vFormats(gpu):
        from concurrent.futures import ThreadPoolExecutor
        def run_cmd(cmd):
            return fetchContentsFromCommand(cmd)

        with ThreadPoolExecutor(max_workers=4) as pool:
            f1 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Formats:/{flag=1}/Display.*/{flag=0}flag'| awk '/./' | awk '!/---|===/' "%(gpu,gpu+1))
            f2 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Formats:/{flag=1}/Display.*/{flag=0}flag'| awk '/./' | awk '!/---|===/' | awk '{gsub(/[=,:].*/,'True')}1' "%(gpu,gpu+1))
            f3 = pool.submit(run_cmd, "vulkaninfo --show-video-props | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;next}flag' | awk '/Video Formats:/{flag=1}/Display.*/{flag=0}flag'| awk '/./' | awk '!/---|===/' | grep -o [=].* | grep -o ' .*' "%(gpu,gpu+1))
            f4 = pool.submit(run_cmd, "vulkaninfo | awk '/GPU%d/{flag=1;next}/GPU%d/{flag=0}flag' | awk '/Video Profiles/{flag=1;}flag' | awk /./ | awk '!/===/' | grep placeholder "%(gpu,gpu+1))

        vulkanVideoFormats = f1.result()
        vulkanVideoFormatsLHS = f2.result()
        vulkanVideoFormatsRHS = f3.result()
        vulkanVideoProfiles = f4.result()
        vulkanVideoProfiles.append("")

        def update_ui():
            vkVideoFormatsTab_Store.remove_all()
            group = None
            j = 1;i = 0; k = 0;
            toprow = None
            if len(vulkanVideoProfiles) > 0:
                toprow = ExpandDataObject(vulkanVideoProfiles[0].replace("placeholder = ",""),"")
                
            for line in vulkanVideoFormats:
                if '=' in line:
                    rhs = vulkanVideoFormatsRHS[k].replace('count =','') if k < len(vulkanVideoFormatsRHS) else ""
                    k = k + 1
                else:
                    rhs = ""
                    
                if not toprow:
                    continue
                    
                if j < len(vulkanVideoProfiles) and line.strip(":") in vulkanVideoProfiles[j].replace("placeholder = ",""):
                    vkVideoFormatsTab_Store.append(toprow)
                    toprow = ExpandDataObject(vulkanVideoProfiles[j].replace("placeholder = ",""),"")
                    j = j + 1
                    i = i + 1
                    group = line
                    continue
                    
                if i >= len(vulkanVideoFormatsLHS):
                    continue
                    
                lhs_val = vulkanVideoFormatsLHS[i].strip("\t")
                if "Video Formats" in line:
                    iter1 = ExpandDataObject(lhs_val,rhs)
                    toprow.children.append(iter1)
                    i = i + 1
                    continue
                elif "\t" in line and "\t\t" not in line:
                    iter2 = ExpandDataObject(lhs_val,rhs)
                    iter1.children.append(iter2)
                    i = i + 1
                    continue
                elif "\t\t" in line and "\t\t\t" not in line:
                    iter3 = ExpandDataObject(lhs_val,rhs)
                    iter2.children.append(iter3)
                    i = i + 1
                    continue
                elif "\t\t\t" in line and "\t\t\t\t" not in line:
                    iter4 = ExpandDataObject(lhs_val,rhs)
                    iter3.children.append(iter4)
                    i = i + 1
                    continue            
                elif "\t\t\t\t" in line and "\t\t\t\t\t" not in line:
                    iter5 = ExpandDataObject(lhs_val,rhs)
                    iter4.children.append(iter5)
                    i = i + 1
                    continue    
                else:
                    iter6 = ExpandDataObject(lhs_val,rhs)
                    iter5.children.append(iter6)
                    i = i + 1
                    
            if toprow:
                vkVideoFormatsTab_Store.append(toprow)
            hide_spinner_for_tab("Video Formats")
            return False
        GLib.idle_add(update_ui)

    def on_gpu_dropdown_changed(combo,dummy):
        text = combo.props.selected_item
        for gpu in range(len(gpu_list)):
            if gpu_list[gpu] in text.get_string():
                tabs_loading_count["count"] = 4
                for tab in tab_spinners:
                    tab_spinners[tab].start()
                    tab_spinners[tab].set_visible(True)
                    tab_content_containers[tab][1].set_visible(True)
                    tab_content_containers[tab][0].set_visible(False)
                    
                import threading
                def load_all_bg(selected_gpu):
                    try:
                        vProfiles(selected_gpu)
                        vDefinitions(selected_gpu)
                        vCapabitlies(selected_gpu)
                        vFormats(selected_gpu)
                    except Exception as e:
                        import traceback
                        traceback.print_exc()
                threading.Thread(target=load_all_bg, args=(gpu,), daemon=True).start()

                gpu_image = getGpuImage(gpu_list[gpu])
                image_renderer.set_pixbuf(gpu_image)
                break





    h_box = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 10)
    h_box.set_halign(Gtk.Align.CENTER)
    
    # Add a top margin to create space between the header bar and the content
    h_box.set_margin_top(10)
    h_box.set_margin_bottom(10)
    h_box.set_margin_start(10)

    # Create the label for the devices
    label = Gtk.Label.new("Available Device(s) :")
    h_box.append(label)

    # Create a list with some dummy device names
    gpu_list = fetchContentsFromCommand(Filenames.fetch_vulkaninfo_ouput_command+Filenames.fetch_device_name_command)
    
    # Create the gpu_dropdown, populated from the list of strings
    gpu_Dropdown = Gtk.DropDown()
    gpu_Dropdown.add_css_class(css_class="card")
    gpu_Dropdown_list = Gtk.StringList()
    gpu_Dropdown.set_model(gpu_Dropdown_list)
    gpu_Dropdown.set_margin_start(10)
    h_box.append(gpu_Dropdown)
    
    unique_gpus = []
    for i in range(len(gpu_list)):
        # Re-use the cached vulkaninfo file — avoids spawning vulkaninfo once per GPU
        check_cmd = (
            f"cat {Filenames.vulkaninfo_output_file} "
            f"| awk '/GPU{i}/{{flag=1;next}}/GPU{i+1}/{{flag=0}}flag' "
            f"| grep 'Video Profiles'"
        )
        if fetchContentsFromCommand(check_cmd):
            if gpu_list[i] not in unique_gpus:
                unique_gpus.append(gpu_list[i])
                gpu_Dropdown_list.append(gpu_list[i])
    # Add the horizontal box to the main vertical box
    videoTab.append(h_box)
    
    split_view_container = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
    split_view_container.set_vexpand(True)
    split_view_container.set_hexpand(True)
    
    # Create a new NavigationSplitView
    split_view = Adw.NavigationSplitView.new()
    split_view.set_vexpand(True)
    split_view.set_hexpand(True)

    # Create the sidebar content using a Gtk.ListBox for tabs
    sidebar_listbox = Gtk.ListBox.new()
    sidebar_listbox.set_selection_mode(Gtk.SelectionMode.SINGLE)
    sidebar_listbox.set_vexpand(True)
    sidebar_listbox.add_css_class(css_class="boxed-list")
    sidebar_listbox.add_css_class(css_class="sidebar")
    


#    sidebar_listbox.add_css_class(css_class="frame")
    # Set the show-separators property to False
    sidebar_listbox.set_show_separators(True)
    
    # Add the tabs to the sidebar ListBox
    tabs = [
        "Video Profiles", "Profile Definition", "Video Capabilities", "Video Formats"
    ]

    content_stack = Gtk.Stack.new()
    
    for tab_name in tabs:
        row = Gtk.ListBoxRow()
        label = Gtk.Label.new(tab_name)
        # Add padding to the label inside the row
        label.set_margin_top(10)
        label.set_margin_bottom(10)
        row.set_child(label)
        sidebar_listbox.append(row)


        # Create a box for the content of this specific tab
        content_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 10)
        
        spinner_box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 12)
        spinner_box.set_valign(Gtk.Align.CENTER)
        spinner_box.set_halign(Gtk.Align.CENTER)
        spinner_box.set_vexpand(True)
        spinner = Gtk.Spinner()
        spinner.set_size_request(36, 36)
        lbl = Gtk.Label(label=f"Loading {tab_name}…")
        lbl.add_css_class("dim-label")
        spinner_box.append(spinner)
        spinner_box.append(lbl)
        
        tab_spinners[tab_name] = spinner
        tab_content_containers[tab_name] = (content_box, spinner_box)
        
        tab_wrapper = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        content_box.set_visible(False)
        tab_wrapper.append(spinner_box)
        tab_wrapper.append(content_box)
        
        if tab_name == "Video Profiles":
 # --------------------- Vulkan Video Profiles ---------------------------------------------------------------------
            vkVideoProfilesColumnView = Gtk.ColumnView()
            vkVideoProfilesColumnView.props.show_row_separators = True
            vkVideoProfilesColumnView.props.show_column_separators = False

            factory_vkVideoProfiles = Gtk.SignalListItemFactory()
            factory_vkVideoProfiles.connect("setup",setup_expander)
            factory_vkVideoProfiles.connect("bind",bind_expander)

            factory_vkVideoProfiles_value = Gtk.SignalListItemFactory()
            factory_vkVideoProfiles_value.connect("setup",setup)
            factory_vkVideoProfiles_value.connect("bind",bind1)

            vkVideoProfilesSelection = Gtk.SingleSelection()
            vkVideoProfilesTab_Store = Gio.ListStore.new(ExpandDataObject)

            vkVideoModel = Gtk.TreeListModel.new(vkVideoProfilesTab_Store,False,True,add_tree_node)
            vkVideoProfilesSelection.set_model(vkVideoModel)

            vkVideoProfilesColumnView.set_model(vkVideoProfilesSelection)

            vkVideoProfilesColumnLhs = Gtk.ColumnViewColumn.new("Details",factory_vkVideoProfiles)
            vkVideoProfilesColumnLhs.set_resizable(True)
            vkVideoProfilesColumnRhs = Gtk.ColumnViewColumn.new("",factory_vkVideoProfiles_value)
            vkVideoProfilesColumnRhs.set_expand(True)

            vkVideoProfilesColumnView.append_column(vkVideoProfilesColumnLhs)
            vkVideoProfilesColumnView.append_column(vkVideoProfilesColumnRhs)

            vkVideoProfilesScrollbar = create_scrollbar(vkVideoProfilesColumnView)
            content_box.append(vkVideoProfilesScrollbar)
        
        elif tab_name == "Profile Definition":
        # --------------------- Vulkan Video Profile Definition ---------------------------------------------------------------------

            vkVideoProfileDefinitionColumnView = Gtk.ColumnView()
            vkVideoProfileDefinitionColumnView.props.show_row_separators = True
            vkVideoProfileDefinitionColumnView.props.show_column_separators = False

            factory_vkVideoProfileDefinition = Gtk.SignalListItemFactory()
            factory_vkVideoProfileDefinition.connect("setup",setup_expander)
            factory_vkVideoProfileDefinition.connect("bind",bind_expander)

            factory_vkVideoProfileDefinition_value = Gtk.SignalListItemFactory()
            factory_vkVideoProfileDefinition_value.connect("setup",setup)
            factory_vkVideoProfileDefinition_value.connect("bind",bind1)

            vkVideoProfileDefinitionSelection = Gtk.SingleSelection()
            vkVideoProfileDefinitionTab_Store = Gio.ListStore.new(ExpandDataObject)

            vkVideoModel = Gtk.TreeListModel.new(vkVideoProfileDefinitionTab_Store,False,True,add_tree_node)
            vkVideoProfileDefinitionSelection.set_model(vkVideoModel)

            vkVideoProfileDefinitionColumnView.set_model(vkVideoProfileDefinitionSelection)

            vkVideoProfileDefinitionColumnLhs = Gtk.ColumnViewColumn.new("Details",factory_vkVideoProfileDefinition)
            vkVideoProfileDefinitionColumnLhs.set_resizable(True)
            vkVideoProfileDefinitionColumnRhs = Gtk.ColumnViewColumn.new("Value",factory_vkVideoProfileDefinition_value)
            vkVideoProfileDefinitionColumnRhs.set_expand(True)

            vkVideoProfileDefinitionColumnView.append_column(vkVideoProfileDefinitionColumnLhs)
            vkVideoProfileDefinitionColumnView.append_column(vkVideoProfileDefinitionColumnRhs)

            vkVideoProfileDefinitionScrollbar = create_scrollbar(vkVideoProfileDefinitionColumnView)
            content_box.append(vkVideoProfileDefinitionScrollbar)

        elif tab_name == "Video Capabilities":
        # -------------------- Vulkan Video Capabilities -------------------------------------------------------------------------------

            vkVideoCapabilitiesColumnView = Gtk.ColumnView()
            vkVideoCapabilitiesColumnView.props.show_row_separators = True
            vkVideoCapabilitiesColumnView.props.show_column_separators = False

            factory_vkVideoCapabilities = Gtk.SignalListItemFactory()
            factory_vkVideoCapabilities.connect("setup",setup_expander)
            factory_vkVideoCapabilities.connect("bind",bind_expander)

            factory_vkVideoCapabilities_value = Gtk.SignalListItemFactory()
            factory_vkVideoCapabilities_value.connect("setup",setup)
            factory_vkVideoCapabilities_value.connect("bind",bind1)

            vkVideoCapabilitiesSelection = Gtk.SingleSelection()
            vkVideoCapabilitiesTab_Store = Gio.ListStore.new(ExpandDataObject)

            vkVideoModel = Gtk.TreeListModel.new(vkVideoCapabilitiesTab_Store,False,True,add_tree_node)
            vkVideoCapabilitiesSelection.set_model(vkVideoModel)

            vkVideoCapabilitiesColumnView.set_model(vkVideoCapabilitiesSelection)

            vkVideoCapabilitiesColumnLhs = Gtk.ColumnViewColumn.new("Details",factory_vkVideoCapabilities)
            vkVideoCapabilitiesColumnLhs.set_resizable(True)
            vkVideoCapabilitiesColumnRhs = Gtk.ColumnViewColumn.new("Value",factory_vkVideoCapabilities_value)
            vkVideoCapabilitiesColumnRhs.set_expand(True)

            vkVideoCapabilitiesColumnView.append_column(vkVideoCapabilitiesColumnLhs)
            vkVideoCapabilitiesColumnView.append_column(vkVideoCapabilitiesColumnRhs)

            vkVideoCapabilitiesScrollbar = create_scrollbar(vkVideoCapabilitiesColumnView)

            content_box.append(vkVideoCapabilitiesScrollbar)
        elif tab_name == "Video Formats":
        
            # -------------------- Vulkan Video Formats -------------------------------------------------------------------------------

            vkVideoFormatsColumnView = Gtk.ColumnView()
            vkVideoFormatsColumnView.props.show_row_separators = True
            vkVideoFormatsColumnView.props.show_column_separators = False

            factory_vkVideoFormats = Gtk.SignalListItemFactory()
            factory_vkVideoFormats.connect("setup",setup_expander)
            factory_vkVideoFormats.connect("bind",bind_expander)

            factory_vkVideoFormats_value = Gtk.SignalListItemFactory()
            factory_vkVideoFormats_value.connect("setup",setup)
            factory_vkVideoFormats_value.connect("bind",bind1)

            vkVideoFormatsSelection = Gtk.SingleSelection()
            vkVideoFormatsTab_Store = Gio.ListStore.new(ExpandDataObject)

            vkVideoModel = Gtk.TreeListModel.new(vkVideoFormatsTab_Store,False,True,add_tree_node)
            vkVideoFormatsSelection.set_model(vkVideoModel)

            vkVideoFormatsColumnView.set_model(vkVideoFormatsSelection)

            vkVideoFormatsColumnLhs = Gtk.ColumnViewColumn.new("Details",factory_vkVideoFormats)
            vkVideoFormatsColumnLhs.set_resizable(True)
            vkVideoFormatsColumnRhs = Gtk.ColumnViewColumn.new("Value",factory_vkVideoFormats_value)
            vkVideoFormatsColumnRhs.set_expand(True)

            vkVideoFormatsColumnView.append_column(vkVideoFormatsColumnLhs)
            vkVideoFormatsColumnView.append_column(vkVideoFormatsColumnRhs)

            vkVideoFormatsScrollbar = create_scrollbar(vkVideoFormatsColumnView)
            content_box.append(vkVideoFormatsScrollbar)

        content_stack.add_titled(tab_wrapper, tab_name.replace(" ", "-").lower(), tab_name)

    gpu_Dropdown.connect("notify::selected-item", on_gpu_dropdown_changed)

    gpu_image = Gtk.Image()
    gpu_image = GdkPixbuf.Pixbuf.new_from_file_at_size(const.APP_LOGO_PNG, 100, 100)
    image_renderer = Gtk.Picture.new_for_pixbuf(gpu_image)
    gpu_Dropdown.set_margin_end(10)
    h_box.append(image_renderer)

    on_gpu_dropdown_changed(gpu_Dropdown,dummy=0)
    # Create a scrolled window for the sidebar list
    sidebar_scrolled_window = Gtk.ScrolledWindow.new()
    sidebar_scrolled_window.set_child(sidebar_listbox)

    # Connect the listbox signal to change the stack page
    def on_row_activated(listbox, row):
        # Get the label from the activated row to find the tab's name
        tab_label = row.get_child()
        tab_name = tab_label.get_label()
        
        # The name for the stack child is the tab name, with spaces replaced by dashes and lowercase
        child_name = tab_name.replace(" ", "-").lower()

        # Set the visible child of the stack using its name
        content_stack.set_visible_child_name(child_name)
        
    sidebar_listbox.connect("row-activated", on_row_activated)
    sidebar_listbox.select_row(sidebar_listbox.get_row_at_index(0))
#    content_stack.set_visible_child_name("System Information")
    # Set a minimum width for the sidebar


    # Create the Adw.NavigationPage wrappers for the sidebar and content
    sidebar_page = Adw.NavigationPage.new(sidebar_scrolled_window, "Sidebar")
    content_page = Adw.NavigationPage.new(content_stack, "Content")
    
    # Set the sidebar and content for the split view using the new pages
    split_view.set_sidebar(sidebar_page)
    split_view.set_content(content_page)
    
    # Add the split view to its new container
    split_view_container.append(split_view)
    
    # Add the split view container to the main vertical box
    videoTab.append(split_view_container)

    return videoTab