"""import os
import re
a= int(alma'")
source_file = "/mnt/code_ssd/prog1/html_generalo_program/program/web/js/global-settings.js"

# Define the output filenames
files = {
    "core": "/mnt/code_ssd/prog1/html_generalo_program/program/web/js/settings-core.js",
    "projects": "/mnt/code_ssd/prog1/html_generalo_program/program/web/js/settings-projects.js",
    "styles": "/mnt/code_ssd/prog1/html_generalo_program/program/web/js/settings-styles.js",
    "presets": "/mnt/code_ssd/prog1/html_generalo_program/program/web/js/settings-presets.js"
}

# We will store the lines for each file here
content_map = {
    "core": [],
    "projects": [],
    "styles": [],
    "presets": []
}

def split_file():
    if not os.path.exists(source_file):
        print(f"Error: {source_file} not found.")
        return

    with open(source_file, "r", encoding="utf-8") as f:
        lines = f.readlines()

    # State machine to determine which file we are writing to
    # Default start state is 'core' (top of the file)
    current_target = "core"

    print(f"Processing {len(lines)} lines...")

    for line in lines:
        stripped = line.strip()

        # --- MARKER DETECTION LOGIC ---
        
        # 1. Switch to Project List logic
        if "function renderGlobalProjectsList() {" in line:
            current_target = "projects"
            print(f"Line {lines.index(line)}: Switching to {files['projects']} (Project List)")

        # 2. Switch back to Core (Favicon & Save Global Settings come after project list)
        elif "window.pickFavicon = async function()" in line:
            current_target = "core"
            print(f"Line {lines.index(line)}: Switching to {files['core']} (Favicon/Save Logic)")

        # 3. Switch to Styles (CSS Editor)
        elif "// --- CUSTOM CSS EDITOR FUNCTIONS ---" in line:
            current_target = "styles"
            print(f"Line {lines.index(line)}: Switching to {files['styles']} (CSS Editor)")

        # 4. Switch to Presets (Gallery & Import/Export)
        elif "// Cache + helpers for style application and presets" in line:
            current_target = "presets"
            print(f"Line {lines.index(line)}: Switching to {files['presets']} (Presets)")

        # 5. Switch back to Projects (The Project Content Editor is at the very end)
        elif "// ---------------- Project content editor ----------------" in line:
            current_target = "projects"
            print(f"Line {lines.index(line)}: Appending to {files['projects']} (Content Editor)")

        # --- END MARKER DETECTION ---

        # Append line to the currently active target
        content_map[current_target].append(line)

    # Write the files
    for key, filename in files.items():
        with open(filename, "w", encoding="utf-8") as out:
            out.writelines(content_map[key])
        print(f"✔ Created {filename} ({len(content_map[key])} lines)")

if __name__ == "__main__":
    split_file()"""