import re

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

def get_block(start_str, end_strs):
    start_idx = -1
    for i, l in enumerate(lines):
        if start_str in l:
            start_idx = i
            break
    if start_idx == -1: return [], -1, -1
    
    end_idx = -1
    for i in range(start_idx+1, len(lines)):
        for e in end_strs:
            if e in lines[i]:
                end_idx = i
                return lines[start_idx:end_idx], start_idx, end_idx
    return [], -1, -1

# DomainTab is from "function DomainTab" to "function MyPlanTab"
d_block, d_s, d_e = get_block("function DomainTab({", ["function MyPlanTab({"])

if d_block:
    d_content = "import React, { useState, useEffect } from 'react';\n"
    d_content += "import { Globe, Plus, CheckCircle, RefreshCw, XCircle, AlertCircle, LogIn } from 'lucide-react';\n\n"
    d_content += "".join(d_block)
    
    with open("resources/js/components/admin/DomainTab.tsx", "w", encoding="utf-8") as f:
        f.write(d_content)
    print("DomainTab.tsx created successfully!")

# MyPlanTab is from "function MyPlanTab" to the end of file
p_block, p_s, p_e = get_block("function MyPlanTab({", [])
# Wait, get_block fails if no end string is found. Let's do it manually.
p_s = -1
for i, l in enumerate(lines):
    if "function MyPlanTab({" in l:
        p_s = i
        break

if p_s != -1:
    p_block = lines[p_s:]
    p_content = "import React, { useState, useEffect } from 'react';\n"
    p_content += "import { CheckCircle, AlertCircle, RefreshCw, LogIn, CreditCard, Clock, Check, X, Shield, Star, Zap } from 'lucide-react';\n\n"
    p_content += "".join(p_block)
    
    with open("resources/js/components/admin/MyPlanTab.tsx", "w", encoding="utf-8") as f:
        f.write(p_content)
    print("MyPlanTab.tsx created successfully!")

# Remove both from AdminDashboard.tsx
if d_s != -1 and p_s != -1:
    lines = lines[:d_s]
    
    # Insert imports at top
    import_idx = -1
    for i, l in enumerate(lines):
        if "import AppearanceManager" in l:
            import_idx = i
            break
    if import_idx != -1:
        lines.insert(import_idx+1, "import DomainTab from './admin/DomainTab';\nimport MyPlanTab from './admin/MyPlanTab';\n")
        
    with open("resources/js/components/AdminDashboard.tsx", "w", encoding="utf-8") as f:
        f.writelines(lines)
    print("AdminDashboard.tsx updated successfully!")
