"""
显示设置控件
"""
import streamlit as st
from typing import Dict, Tuple


def create_display_settings_section(display_config: Dict) -> Tuple[int, str, float, bool]:
    """
    显示设置（由配置驱动）
    
    Args:
        display_config: 显示配置字典
    
    Returns:
        tuple: (line_width, display_mode, zoom_level, show_line_numbers)
    """
    st.sidebar.divider()
    st.sidebar.subheader("🖼️ 显示设置")

    line_width = st.sidebar.slider(
        "线条宽度",
        int(display_config.get("line_width_min", 1)),
        int(display_config.get("line_width_max", 5)),
        int(display_config.get("default_line_width", 2)),
    )
    
    display_mode = st.sidebar.radio(
        "显示模式",
        ["对比显示", "仅显示划线图", "仅显示原图"],
        index=1,
    )
    
    zoom_level = st.sidebar.slider(
        "图片缩放",
        float(display_config.get("zoom_min", 0.25)),
        float(display_config.get("zoom_max", 2.0)),
        float(display_config.get("default_zoom", 1.0)),
        float(display_config.get("zoom_step", 0.25)),
    )
    
    show_line_numbers = st.sidebar.checkbox(
        "显示线条编号",
        value=bool(display_config.get("show_line_numbers", True)),
    )

    return line_width, display_mode, zoom_level, show_line_numbers


def create_undo_redo_section():
    """创建撤销/重做区域"""
    from .state_manager import undo_last_action, redo_last_action
    from .drawing import clear_table_image_cache
    
    st.sidebar.divider()
    st.sidebar.subheader("↩️ 撤销/重做")
    
    col1, col2 = st.sidebar.columns(2)
    
    with col1:
        if st.button("↩️ 撤销", disabled=len(st.session_state.undo_stack) == 0):
            if undo_last_action():
                clear_table_image_cache()
                st.success("✅ 已撤销")
                st.rerun()
    
    with col2:
        if st.button("↪️ 重做", disabled=len(st.session_state.redo_stack) == 0):
            if redo_last_action():
                clear_table_image_cache()
                st.success("✅ 已重做")
                st.rerun()
    
    st.sidebar.info(f"📚 历史记录: {len(st.session_state.undo_stack)} 条")