import re

files = [
    r"c:\Users\User\Desktop\IMRAN VAI\AdminDashboardFM\AdminDashboardFM\resources\views\frontend\app.blade.php",
    r"c:\Users\User\Desktop\IMRAN VAI\AdminDashboardFM\AdminDashboardFM\resources\views\frontend\verification.blade.php",
    r"c:\Users\User\Desktop\IMRAN VAI\AdminDashboardFM\AdminDashboardFM\resources\views\frontend\transaction.blade.php"
]

all_css = []

for filepath in files:
    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # Extract CSS
    style_blocks = re.findall(r'<style>(.*?)</style>', content, re.DOTALL)
    for block in style_blocks:
        all_css.append(block.strip())
        
    # Remove CSS
    content = re.sub(r'<style>.*?</style>', '', content, flags=re.DOTALL)
    
    # If app.blade.php, add link tag where style tag was
    if 'app.blade.php' in filepath:
        content = content.replace("@stack('styles')", '<link href="{{ asset(\'css/frontend.css\') }}" rel="stylesheet">\n    @stack(\'styles\')')
        
    with open(filepath, 'w', encoding='utf-8') as f:
        f.write(content)

with open(r"c:\Users\User\Desktop\IMRAN VAI\AdminDashboardFM\AdminDashboardFM\public\css\frontend.css", 'w', encoding='utf-8') as f:
    f.write('\n\n'.join(all_css))
