import streamlit as st from app_core.config.settings import STORES, STORE_CODE_TO_TENANT_ID def apply_global_style(background_url: str | None = None) -> None: css = """ """ st.markdown(css, unsafe_allow_html=True) # Optional login/background image with 50% transparency if background_url: # Support @prefix and local files by embedding as base64 when needed try: import os, base64 url = background_url.lstrip('@').strip() if url.startswith('http://') or url.startswith('https://'): data_url = url else: # Treat as local file path # Map shorthand names to assets/ if needed if url in {"bg.jpg", "workolik.png"}: url = os.path.join("assets", url) if os.path.exists(url): ext = os.path.splitext(url)[1].lower() mime = 'image/jpeg' if ext in ['.jpg', '.jpeg'] else 'image/png' if ext == '.png' else 'image/webp' if ext == '.webp' else 'image/*' with open(url, 'rb') as f: b64 = base64.b64encode(f.read()).decode() data_url = f'data:{mime};base64,{b64}' else: data_url = url # fallback; let browser try st.markdown( f""" """, unsafe_allow_html=True, ) except Exception: pass def render_header(brand_name: str = "Workolik") -> None: st.markdown( f"""
""", unsafe_allow_html=True, ) def render_topbar(brand_name: str = "") -> None: st.markdown( f"""
\n
\n \n {brand_name}\n
\n
""", unsafe_allow_html=True, ) def render_sidebar_logo(brand_name: str = "Workolik") -> None: import streamlit as st import base64 import os try: # Read the image file and encode it as base64 logo_path = os.path.join("assets", "workolik.png") if os.path.exists(logo_path): with open(logo_path, "rb") as img_file: img_data = base64.b64encode(img_file.read()).decode() st.markdown( f""" """, unsafe_allow_html=True, ) else: raise FileNotFoundError("Logo file not found") except Exception as e: # Fallback to text logo if image fails to load st.markdown( f""" """, unsafe_allow_html=True, ) def render_store_selector() -> tuple[int | None, str | None]: """Render a compact, classy store selector box. Returns (tenant_id, label). Also persists selection in session_state. """ st.markdown( """
🛍️
Choose the store you want to view
👉 Click a card to select
""", unsafe_allow_html=True, ) # Sub caption + clear selection current_label = st.session_state.get("store_label") left_cap, right_clear = st.columns([6, 1]) with left_cap: st.caption("Please choose a store before surfing !") if current_label: st.caption(f"Selected: {current_label}") with right_clear: if st.button("Clear", key="clear_store_sel"): st.session_state["tenant_id"] = None st.session_state["store_label"] = None st.experimental_rerun() if hasattr(st, "experimental_rerun") else st.rerun() # We no longer use query params; selection happens in-session only chosen_from_query: str | None = None # Grid of store boxes (soft gradient cards with per-store colors and emojis) emoji_map = {"PC": "🍷", "IP": "🍻", "ML": "🥂", "CL4": "🍸", "NL": "🥃", "CL6": "🍾", "RC": "🍹", "PL": "🍺"} color_rgb = {"PC": (37,99,235), "IP": (22,163,74), "ML": (245,158,11), "CL4": (220,38,38), "NL": (124,58,237), "CL6": (234,179,8), "RC": (6, 182, 212), "PL": (236, 72, 153)} preselect_label = st.session_state.get("store_label") chosen_label = None # No search box; show all stores filtered_stores = STORES # Always render 3 columns per row (e.g., 3 + 3 for 6 stores) rows = [filtered_stores[i:i+3] for i in range(0, len(filtered_stores), 3)] for row in rows: cols = st.columns(3) for i, store in enumerate(row): with cols[i]: icon = emoji_map.get(store["code"], "🏬") r, g, b = color_rgb.get(store["code"], (14,165,233)) is_selected = (preselect_label == store["label"]) or (chosen_from_query == store["label"]) # highlight current border_alpha = 0.48 if is_selected else 0.28 shadow = "0 18px 42px rgba(2,6,23,0.16)" if is_selected else "0 12px 28px rgba(2,6,23,0.10)" border_width = "2px" if is_selected else "1px" check = " ✅" if is_selected else "" # Render a card-like button that sets selection without changing URL clicked = st.button( f"{icon} {store['label']}{check}", key=f"store_card_{store['code']}", use_container_width=True, type="secondary", ) # Lightweight card styling via inline CSS targeting this button st.markdown( f""" """, unsafe_allow_html=True, ) if clicked: st.session_state["tenant_id"] = store["tenant_id"] st.session_state["store_label"] = store["label"] chosen_label = store["label"] st.rerun() # Resolve tenant_id effective_label = chosen_label or preselect_label selected = next((s for s in STORES if s["label"] == effective_label), None) tenant_id = selected["tenant_id"] if selected else None # Persist st.session_state["tenant_id"] = tenant_id st.session_state["store_label"] = selected["label"] if selected else None st.session_state["division_code"] = None return tenant_id, (selected["label"] if selected else None)