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 "function StockTab({" in l:
        start_idx = i
        break

end_idx = -1
# It's followed by `const SectionHeader = `
for i in range(start_idx+1, len(lines)):
    if "const SectionHeader =" in lines[i] or "function AdminDashboard" in lines[i]:
        end_idx = i
        break

if start_idx != -1 and end_idx != -1:
    content = lines[start_idx:end_idx]
    
    # create StockTab.tsx
    out = "import React, { useState, useEffect } from 'react';\n"
    out += "import { AlertCircle, Package, Search, Save, CheckCircle, Target, TrendingDown } from 'lucide-react';\n\n"
    out += "".join(content)
    out += "\nexport default StockTab;\n"
    
    with open("resources/js/components/admin/StockTab.tsx", "w", encoding="utf-8") as f:
        f.write(out)
    
    # remove from AdminDashboard.tsx
    new_lines = lines[:start_idx-1] + lines[end_idx:]
    with open("resources/js/components/AdminDashboard.tsx", "w", encoding="utf-8") as f:
        f.writelines(new_lines)
    print("StockTab extracted successfully!")
else:
    print("Could not find StockTab boundaries")
