import re

with open("resources/js/components/AdminDashboard.tsx", "r", encoding="utf-8") as f:
    lines = f.readlines()

start_idx = -1
for i, l in enumerate(lines):
    if "const AdminBannerCarousel: React.FC" in l:
        start_idx = i
        break

end_idx = -1
for i in range(start_idx+1, len(lines)):
    if "};" in lines[i]:
        end_idx = i
        break

if start_idx != -1 and end_idx != -1:
    content = lines[start_idx:end_idx+1]
    
    # write to AdminBannerCarousel.tsx
    out = "import React, { useState, useEffect } from 'react';\n"
    out += "import { Plus, X, Upload } from 'lucide-react';\n\n"
    out += "".join(content).replace("const AdminBannerCarousel: React.FC<{ banners: any[] }> = ({ banners }) => {", "export default function AdminBannerCarousel({ banners }: { banners: any[] }) {")
    
    # Wait, the end is `};`, we should replace it with `}` if we use `export default function`. 
    out = out.replace("};", "}")
    
    with open("resources/js/components/AdminBannerCarousel.tsx", "w", encoding="utf-8") as f:
        f.write(out)
        
    new_lines = lines[:start_idx] + lines[end_idx+1:]
    with open("resources/js/components/AdminDashboard.tsx", "w", encoding="utf-8") as f:
        f.writelines(new_lines)
    print("AdminBannerCarousel extracted!")
else:
    print("Not found")
