import tkinter as tk
from tkinter import ttk, messagebox
from PIL import Image, ImageTk
import requests
from io import BytesIO

class N4AMuseumApp:
    def __init__(self, root):
        self.root = root
        self.root.title("盐城新四军纪念馆 - 沉浸式导览")
        self.root.geometry("1200x800")
        self.root.configure(bg='#f0f0f0')
        
        # 当前展厅索引
        self.current_hall = 0
        
        # 展厅数据（含图片URL）
        self.halls = [
            {
                "id": 1,
                "name": "序厅：铁军忠魂",
                "color": "#b71c1c",
                "icon": "🎖️",
                "image_url": "https://img.zcool.cn/community/01d5ea5f8c8a4d11013e3184d6f8f8.jpg@1280w_1l_2o_100sh.jpg",  # 示例图，可替换
                "content": [
                    "• 巨幅《铁军忠魂》主题雕塑",
                    "• 毛泽东手书《中国共产党中央革命军事委员会命令》",
                    "• 新四军重建军部核心领导人群像",
                    "• 八年抗战、十年征程历史轴线"
                ],
                "guide": "欢迎来到序厅！这里矗立着震撼人心的《铁军忠魂》雕塑，由著名雕塑家吴为山设计。它展现了新四军将士听党指挥、报国为民的英勇形象。"
            },
            {
                "id": 2,
                "name": "第一展厅：民族危急 铁军诞生",
                "color": "#d32f2f",
                "icon": "⚔️",
                "image_url": "https://t7.baidu.com/it/u=2626215425,3843406660&fm=193&f=GIF",
                "content": [
                    "• 七七事变与全面抗战爆发背景",
                    "• 南方八省红军游击队改编为新四军",
                    "• 叶挺任军长、项英任副军长",
                    "• 汉口军部成立历史照片墙"
                ],
                "guide": "1937年‘七七事变’后，民族危亡！南方八省的红军游击队奉命改编为‘国民革命军陆军新编第四军’，这就是我们‘新四军’的诞生！"
            },
            {
                "id": 3,
                "name": "第二展厅：重建军部 浴火重生",
                "color": "#f44336",
                "icon": "🔥",
                "image_url": "https://img.zcool.cn/community/01d5ea5f8c8a4d11013e3184d6f8f8.jpg@1280w_1l_2o_100sh.jpg",
                "content": [
                    "• 皖南事变历史真相展",
                    "• 1941年盐城重建军部大会场景复原",
                    "• 刘少奇、陈毅在盐城办公场景",
                    "• 《中央军委命令》珍贵文献"
                ],
                "guide": "1941年1月，国民党顽固派制造了震惊中外的‘皖南事变’。但我们新四军没有被打垮！党中央决定在盐城重建军部，陈毅为代军长，刘少奇为政委，浴火重生！"
            },
            {
                "id": 4,
                "name": "第三展厅：兵民鏖战 坚持敌后",
                "color": "#e64a19",
                "icon": "🛡️",
                "image_url": "https://t7.baidu.com/it/u=2626215425,3843406660&fm=193&f=GIF",
                "content": [
                    "• 华中敌后抗日根据地地图沙盘",
                    "• 大胡庄战斗、刘老庄战斗场景画",
                    "• 盐阜区反‘扫荡’斗争实物",
                    "• 老百姓支前用的独轮车、纺车"
                ],
                "guide": "在盐阜区，新四军和老百姓是一家人！我们看到了‘刘老庄八十二烈士’的英勇事迹，也看到了老百姓用独轮车推着粮食支援前线的感人场景。"
            },
            {
                "id": 5,
                "name": "新四军人物馆",
                "color": "#ff8f00",
                "icon": "⭐",
                "image_url": "https://img.zcool.cn/community/01d5ea5f8c8a4d11013e3184d6f8f8.jpg@1280w_1l_2o_100sh.jpg",
                "content": [
                    "• 盐城籍48位开国将军生平展",
                    "• 叶挺、陈毅、粟裕等领导人专柜",
                    "• 女战士李珉、卫生员张茜等事迹",
                    "• 国际友人汉斯·希伯的故事"
                ],
                "guide": "这里星光闪耀！我们有1位元帅、2位大将、7位上将，还有48位是我们盐城籍的开国将军！他们是我们的骄傲！"
            }
        ]
        
        # 创建界面
        self.create_widgets()
        self.show_hall(0)
        
    def create_widgets(self):
        """创建界面组件"""
        # 标题栏
        title_frame = tk.Frame(self.root, bg='#b71c1c', height=120)
        title_frame.pack(fill='x')
        title_frame.pack_propagate(False)
        
        tk.Label(title_frame, text="🏛️ 盐城新四军纪念馆", 
                font=("Arial", 28, "bold"), fg='white', bg='#b71c1c').pack(pady=15)
        tk.Label(title_frame, text="全国爱国主义教育示范基地 | 国家一级博物馆", 
                font=("Arial", 12), fg='#ffccbc', bg='#b71c1c').pack()
        
        # 主内容区
        main_frame = tk.Frame(self.root, bg='white')
        main_frame.pack(fill='both', expand=True, padx=20, pady=15)
        
        # 左侧 - 展厅导航
        left_frame = tk.Frame(main_frame, bg='#f5f5f5', width=220)
        left_frame.pack(side='left', fill='y')
        left_frame.pack_propagate(False)
        
        tk.Label(left_frame, text="📂 展厅导航", font=("Arial", 16, "bold"), 
                bg='#e0e0e0', fg='#333', width=22).pack(pady=15)
        
        # 展厅按钮
        self.hall_buttons = []
        for i, hall in enumerate(self.halls):
            btn = tk.Button(left_frame, text=f"{hall['icon']} {hall['name']}", 
                          font=("Arial", 11), bg=hall['color'], fg='white',
                          command=lambda idx=i: self.show_hall(idx),
                          width=22, height=2, relief='flat')
            btn.pack(pady=6, padx=10)
            self.hall_buttons.append(btn)
        
        # 右侧 - 内容展示区
        right_frame = tk.Frame(main_frame, bg='white')
        right_frame.pack(side='right', fill='both', expand=True, padx=(20, 0))
        
        # 展厅标题
        self.hall_title = tk.Label(right_frame, text="", 
                                  font=("Arial", 22, "bold"), fg='#b71c1c', bg='white')
        self.hall_title.pack(pady=(0, 15))
        
        # 图片展示区域
        self.image_label = tk.Label(right_frame, text="[图片加载中...]", 
                                   font=("Arial", 12), bg='#fafafa', 
                                   relief='sunken', width=80, height=20)
        self.image_label.pack(fill='both', expand=True, pady=(0, 15))
        
        # 小导游与内容介绍（分左右两栏）
        bottom_frame = tk.Frame(right_frame, bg='white')
        bottom_frame.pack(fill='x')
        
        # 小导游（左）
        guide_frame = tk.Frame(bottom_frame, bg='#fff3e0', relief='ridge', borderwidth=2, width=300)
        guide_frame.pack(side='left', fill='both', expand=False, padx=(0, 15))
        
        tk.Label(guide_frame, text="👧🏻 小导游讲解", font=("Arial", 14, "bold"), 
                bg='#fff3e0', fg='#e65100').pack(pady=10)
        
        self.guide_text = tk.Text(guide_frame, font=("Arial", 13), width=35, height=8,
                                 bg='#fff9c4', fg='#37474f', wrap='word',
                                 relief='flat', padx=12, pady=12)
        self.guide_text.pack(padx=10, pady=(0, 10), fill='both', expand=True)
        
        # 展厅内容列表（右）
        content_frame = tk.Frame(bottom_frame, bg='white')
        content_frame.pack(side='right', fill='both', expand=True)
        
        tk.Label(content_frame, text="📋 展厅亮点", font=("Arial", 14, "bold"),
                bg='white', fg='#333').pack(anchor='w', pady=(0, 10))
        
        self.content_listbox = tk.Listbox(content_frame, font=("Arial", 12), 
                                         bg='#f8f9fa', fg='#455a64',
                                         height=8, relief='flat',
                                         selectbackground='#e3f2fd')
        self.content_listbox.pack(fill='both', expand=True)
        
        # 控制按钮
        control_frame = tk.Frame(right_frame, bg='white')
        control_frame.pack(fill='x', pady=15)
        
        tk.Button(control_frame, text="◀ 上一展厅", font=("Arial", 12),
                 command=self.prev_hall, bg='#5d4037', fg='white',
                 width=12, height=2).pack(side='left', padx=5)
        
        tk.Button(control_frame, text="下一展厅 ▶", font=("Arial", 12),
                 command=self.next_hall, bg='#d32f2f', fg='white',
                 width=12, height=2).pack(side='right', padx=5)
        
        # 底部信息
        bottom_info = tk.Frame(self.root, bg='#37474f', height=50)
        bottom_info.pack(fill='x', side='bottom')
        bottom_info.pack_propagate(False)
        
        info_text = "📍 地址：江苏省盐城市亭湖区建军东路159号  📞 0515-88335708  🕐 9:00-17:00（周一闭馆）"
        tk.Label(bottom_info, text=info_text, font=("Arial", 10), 
                fg='white', bg='#37474f').pack(pady=15)
        
        # 键盘事件
        self.root.bind('<Left>', lambda e: self.prev_hall())
        self.root.bind('<Right>', lambda e: self.next_hall())
    
    def load_image(self, url):
        """从网络URL加载并显示图片"""
        try:
            response = requests.get(url)
            image_data = Image.open(BytesIO(response.content))
            # 调整图片大小以适应界面
            image_data = image_data.resize((600, 400), Image.Resampling.LANCZOS)
            photo = ImageTk.PhotoImage(image_data)
            self.image_label.config(image=photo, text="")
            self.image_label.image = photo  # 保持引用
        except Exception as e:
            self.image_label.config(text=f"[图片加载失败]\n{str(e)}", image="")
    
    def show_hall(self, index):
        """显示指定展厅内容"""
        self.current_hall = index
        hall = self.halls[index]
        
        # 更新标题
        self.hall_title.config(text=f"{hall['icon']} {hall['name']}")
        
        # 加载并显示图片
        self.load_image(hall["image_url"])
        
        # 更新小导游讲解
        self.guide_text.config(state='normal')
        self.guide_text.delete(1.0, tk.END)
        self.guide_text.insert(1.0, hall['guide'])
        self.guide_text.config(state='disabled')
        
        # 更新展厅内容列表
        self.content_listbox.delete(0, tk.END)
        for item in hall['content']:
            self.content_listbox.insert(tk.END, item)
        
        # 更新导航按钮状态
        for i, btn in enumerate(self.hall_buttons):
            if i == index:
                btn.config(bg='#333', fg='white', relief='sunken')
            else:
                btn.config(bg=self.halls[i]['color'], fg='white', relief='flat')
    
    def next_hall(self):
        """下一展厅"""
        if self.current_hall < len(self.halls) - 1:
            self.show_hall(self.current_hall + 1)
        else:
            messagebox.showinfo("参观完成", "🎉 你已参观完所有展厅！\n\n铁军精神，永放光芒！")
    
    def prev_hall(self):
        """上一展厅"""
        if self.current_hall > 0:
            self.show_hall(self.current_hall - 1)

def main():
    root = tk.Tk()
    app = N4AMuseumApp(root)
    root.mainloop()

if __name__ == "__main__":
    main()