File size: 3,214 Bytes
aa04092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337ec9f
aa04092
 
af01c91
337ec9f
aa04092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c4292b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import streamlit as st
from datetime import datetime
import pytz
from config import Config

def render_message(role: str, content: str, timezone: str = Config.DEFAULT_TIMEZONE):
    """タイムゾーンを考慮してメッセージを表示"""
    if role == "assistant":
        with st.chat_message(role, avatar="🤖"):
            st.write(content)
    elif role == "user":
        with st.chat_message(role, avatar="👤"):
            st.write(content)
    else:
        with st.chat_message(role):
            st.write(content)

def show_notification(message: str, type: str = "info", duration: int = 3):
    """Show an elegant notification toast."""
    if type == "error":
        st.error(message, icon="🚨")
    elif type == "success":
        st.success(message, icon="✅")
    elif type == "warning":
        st.warning(message, icon="⚠️")
    else:
        st.info(message, icon="ℹ️")

def render_sidebar(i18n, chat_manager):
    # Create a persistent sidebar container
    sidebar = st.sidebar

    # Ensure sidebar is visible
    if "sidebar_visibility" not in st.session_state:
        st.session_state.sidebar_visibility = True

    # Initialize timezone in session state if not exists
    if "timezone" not in st.session_state:
        st.session_state.timezone = Config.DEFAULT_TIMEZONE

    with sidebar:
        st.title(i18n.get_text("settings"))

        # Language selection - デフォルトを日本語に設定
        language = st.selectbox(
            i18n.get_text("language"),
            ["English", "日本語"],
            index=1,
            key="language_selector"
        )

        # Model selection - デフォルトをOpenRouter-Autoに設定
        model = st.selectbox(
            i18n.get_text("model_selection"),
            ["OpenRouter-Auto", "OpenAI", "Claude-3.5", "Gemini-2.0", "deepseek-chat"],
            index=0,
            key="model_selection"
        )

        # Timezone selection
        timezone = st.selectbox(
            i18n.get_text("timezone"),
            Config.SUPPORTED_TIMEZONES,
            index=Config.SUPPORTED_TIMEZONES.index(Config.DEFAULT_TIMEZONE),
            key="timezone_selector"
        )
        st.session_state.timezone = timezone

        st.markdown("---")

        # Export section
        export_format = st.selectbox(
            i18n.get_text("export_format"),
            ["Markdown", "PDF"],
            key="export_format"
        )

        if st.button(i18n.get_text("export_chat"), key="export_button"):
            try:
                timezone = st.session_state.get("timezone", Config.DEFAULT_TIMEZONE)
                if export_format == "Markdown":
                    filename = chat_manager.save_markdown_file(timezone=timezone)
                    show_notification(f"{i18n.get_text('export_success')} ({filename})", "success")
                else:
                    filename = chat_manager.export_chat_pdf(timezone=timezone)
                    show_notification(f"{i18n.get_text('export_success')} ({filename})", "success")
            except Exception as e:
                show_notification(f"{i18n.get_text('export_error')}: {str(e)}", "error")

        return language, model