#!/usr/bin/env nu

# Script to fix common clippy warnings in tools-tui-shared crate

let files = [
    "shared/rust-tui/src/config/mod.rs",
    "shared/rust-tui/src/widgets/form.rs",
    "shared/rust-tui/src/widgets/table.rs",
    "shared/rust-tui/src/widgets/menu.rs",
    "shared/rust-tui/src/widgets/help.rs",
    "shared/rust-tui/src/widgets/status.rs",
    "shared/rust-tui/src/app/mod.rs",
    "shared/rust-tui/src/plugin.rs",
    "shared/rust-tui/src/utils.rs",
    "shared/rust-tui/src/lib.rs"
]

# Function to add const to simple getter methods
def add_const_to_getters [] {
    each { |file|
        print $"Processing: ($file)"
        let content = (open $file)

        # Add const to simple return methods
        let updated = ($content
            | str replace --all --regex 'pub fn (\w+)\(&self\) -> (\w+) \{\s+self\.(\w+)\s+\}' 'pub const fn $1(&self) -> $2 {
        self.$3
    }'
        )

        $updated | save -f $file
    }
}

# Main execution
print "Fixing clippy warnings in tools-tui-shared..."
$files | add_const_to_getters
print "Done!"
