import numpy as np
import pandas as pd
import streamlit as st

reserved_columns = ['Nachname', 'Vorname', 'Punkte', 'Note']

def update_columns(new_columns, table):
    if len(table) > 0:
        # Drop table columns that are not in the list of columns
        for column in table.columns:
            if column not in new_columns and column not in reserved_columns+list(st.session_state.session.students_df.columns):
                table.drop(column, axis=1, inplace=True)
        # Add columns that are in the list of columns but not in the table
        for column in new_columns:
            if column not in table.columns:
                table[column] = pd.Series(np.nan, index=table.index, dtype='float64')
        # Reorder columns
        before_reorder = table.columns
        original_columns = [col for col in before_reorder if col not in new_columns]
        table = table[original_columns + new_columns]
    return table