# A dialog to get string to be replaced
$startValue = Read-Host "
Enter a alias string, for example 'rep', then press Enter; If empty, use 'rep' as the default value"

# Replace `[rep=xxx]`
$start = '[';
$end = '=';
# Replace `--ALIAS:rep;`
$start2 = ':';
$end2 = ';';

# Input null is allowed
if ($startValue -eq "") {
    $startValue = 'rep';
}

$searchString = $start + $startValue + $end;
$searchString2 = $start2 + $startValue + $end2;

# A dialog to get string to replace
$inputValue = Read-Host "
Enter a string to replace '$startValue', for example 'role', then press Enter"

# Confirm replacement
$response = Read-Host "
Are you sure you want to replace '$startValue' with '$inputValue'?
If you are sure, please enter 'Y/y' and press Enter; otherwise, enter 'N/n' and press Enter"

if ($response -eq "Y") {
    # Result: "rep='person'" => "role='person'"

    $replaceString = $start + $inputValue + $end;
    $replaceString2 = $start2 + $inputValue + $end2;

    # Get all CSS and LESS files
    $files = Get-ChildItem -Path '.\styles' -File -Recurse

    # Perform replacement operation on each file individually
    foreach ($file in $files) {
        # Get
        $content = Get-Content -Path $file.FullName -Raw
        
        # Replace
        $newContent = $content -replace [Regex]::Escape($searchString), $replaceString -replace [Regex]::Escape($searchString2), $replaceString2;
        
        # Fill
        Set-Content -Path $file.FullName -Value $newContent
    }
    
    # Success
    Read-Host -Prompt 'Operation successful! Press Enter to exit.'
}