<?php
/**
 * Find Opacity Issue
 * This script finds where the opacity: 0 is coming from
 */

// Set up environment
$_GET['_route'] = 'banks/list';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['HTTP_HOST'] = 'newdesign1.netreachsolutions.co.ke';
$_SERVER['REQUEST_URI'] = '/index.php?_route=banks/list';
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443';

try {
    // Include necessary files
    require_once 'system/vendor/autoload.php';
    require_once 'init.php';
    
    // Set up global variables
    $routes = explode('/', 'banks/list');
    global $ui;
    
    // Initialize UI
    $ui = new Smarty();
    $ui->setTemplateDir([
        'custom' => File::pathFixer($UI_PATH . '/ui_custom/'),
        'default' => File::pathFixer($UI_PATH . '/ui/')
    ]);
    $ui->assign('_url', APP_URL . '/index.php?_route=');
    $ui->setCompileDir(File::pathFixer($UI_PATH . '/compiled/'));
    $ui->setConfigDir(File::pathFixer($UI_PATH . '/conf/'));
    $ui->setCacheDir(File::pathFixer($UI_PATH . '/cache/'));
    $ui->assign('app_url', APP_URL);
    $ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST)));
    $ui->assign('_path', __DIR__);
    $ui->assign('_c', $config);
    $ui->assign('_system_menu', 'dashboard');
    
    // Mock admin authentication
    $_SESSION['aid'] = 1;
    $_SESSION['username'] = 'admin';
    $_SESSION['user_type'] = 'SuperAdmin';
    
    // Mock admin data
    $admin = [
        'id' => 1,
        'username' => 'admin',
        'user_type' => 'SuperAdmin'
    ];
    
    $ui->assign('_title', 'Bank Management');
    $ui->assign('_system_menu', 'services');
    $ui->assign('_admin', $admin);
    
    // Get banks data
    $query = ORM::for_table('tbl_banks');
    $query->order_by_desc('is_default')->order_by_asc('name');
    $banks = Paginator::findMany($query, []);
    
    $ui->assign('banks', $banks);
    $ui->assign('search', '');
    $ui->assign('filter_stk', '');
    $ui->assign('filter_active', '');
    
    // Render template
    ob_start();
    $ui->display('banks.tpl');
    $output = ob_get_contents();
    ob_end_clean();
    
    // Find all occurrences of opacity: 0
    $lines = explode("\n", $output);
    echo "=== Searching for opacity: 0 ===\n";
    
    for ($i = 0; $i < count($lines); $i++) {
        if (strpos($lines[$i], 'opacity: 0') !== false) {
            echo "Found opacity: 0 at line " . ($i + 1) . ":\n";
            echo "  " . trim($lines[$i]) . "\n";
            echo "Context (3 lines before and after):\n";
            for ($j = max(0, $i - 3); $j <= min(count($lines) - 1, $i + 3); $j++) {
                $marker = ($j == $i) ? ">>> " : "    ";
                echo $marker . ($j + 1) . ": " . trim($lines[$j]) . "\n";
            }
            echo "\n";
        }
    }
    
    // Also search for other hiding CSS
    echo "=== Searching for other hiding CSS ===\n";
    $hiding_patterns = ['display: none', 'visibility: hidden', 'opacity: 0', 'height: 0', 'overflow: hidden'];
    
    foreach ($hiding_patterns as $pattern) {
        for ($i = 0; $i < count($lines); $i++) {
            if (strpos($lines[$i], $pattern) !== false) {
                echo "Found '$pattern' at line " . ($i + 1) . ":\n";
                echo "  " . trim($lines[$i]) . "\n";
            }
        }
    }
    
} catch (Exception $e) {
    echo "Exception: " . $e->getMessage() . "\n";
} catch (Error $e) {
    echo "Fatal Error: " . $e->getMessage() . "\n";
}
?>
