import streamlit as st from utils.time_utils import compute_end_time, format_time def render_card(index: int, on_save, on_delete, rank_tone: str) -> None: card = st.session_state.cards[index] title_key = f"title_{index}" hour_key = f"hour_{index}" minute_key = f"minute_{index}" current_hour = f"{int(st.session_state.get(hour_key, card['startHour'])):02d}" current_minute = f"{int(st.session_state.get(minute_key, card['startMinute'])):02d}" end_hour, end_minute = compute_end_time(current_hour, current_minute) card["endHour"] = end_hour card["endMinute"] = end_minute with st.container(border=True): st.markdown(f'
', unsafe_allow_html=True) title_col, status_col = st.columns([1.8, 0.42]) with title_col: card["title"] = st.text_input( "Title", value=card["title"], key=title_key, placeholder="Morning Shift", label_visibility="collapsed", ) with status_col: badge = "Saved" if card.get("id") else "Draft" st.markdown(f'
{badge}
', unsafe_allow_html=True) hour_col, minute_col, end_col, save_col, delete_col = st.columns([0.46, 0.46, 0.8, 0.62, 0.62]) with hour_col: hour_value = st.number_input( "Hour", min_value=0, max_value=23, value=int(current_hour), step=1, key=hour_key, label_visibility="collapsed", ) card["startHour"] = f"{hour_value:02d}" with minute_col: minute_value = st.number_input( "Minute", min_value=0, max_value=59, value=int(current_minute), step=1, key=minute_key, label_visibility="collapsed", ) card["startMinute"] = f"{minute_value:02d}" end_hour, end_minute = compute_end_time(card["startHour"], card["startMinute"]) card["endHour"] = end_hour card["endMinute"] = end_minute with end_col: st.markdown( f"""
End
{format_time(end_hour, end_minute)}
""", unsafe_allow_html=True, ) with save_col: st.markdown('
', unsafe_allow_html=True) st.button( "Update" if card.get("id") else "Save", key=f"save_{index}", use_container_width=True, on_click=on_save, args=(index,), ) st.markdown("
", unsafe_allow_html=True) with delete_col: st.markdown('
', unsafe_allow_html=True) st.button( "Delete", key=f"delete_{index}", use_container_width=True, on_click=on_delete, args=(index,), ) st.markdown("
", unsafe_allow_html=True)