| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  | import { useCallback, useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   RiMenuLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | import { useChatWithHistoryContext } from './context' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  | import Operation from './header/operation' | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | import Sidebar from './sidebar' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  | import MobileOperationDropdown from './header/mobile-operation-dropdown' | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | import AppIcon from '@/app/components/base/app-icon' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  | import ActionButton from '@/app/components/base/action-button' | 
					
						
							|  |  |  | import { Message3Fill } from '@/app/components/base/icons/src/public/other' | 
					
						
							|  |  |  | import InputsFormContent from '@/app/components/base/chat/chat-with-history/inputs-form/content' | 
					
						
							|  |  |  | import Confirm from '@/app/components/base/confirm' | 
					
						
							|  |  |  | import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' | 
					
						
							|  |  |  | import type { ConversationItem } from '@/models/share' | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const HeaderInMobile = () => { | 
					
						
							|  |  |  |   const { | 
					
						
							|  |  |  |     appData, | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |     currentConversationId, | 
					
						
							|  |  |  |     currentConversationItem, | 
					
						
							|  |  |  |     pinnedConversationList, | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |     handleNewConversation, | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |     handlePinConversation, | 
					
						
							|  |  |  |     handleUnpinConversation, | 
					
						
							|  |  |  |     handleDeleteConversation, | 
					
						
							|  |  |  |     handleRenameConversation, | 
					
						
							|  |  |  |     conversationRenaming, | 
					
						
							| 
									
										
										
										
											2025-05-06 13:15:23 +08:00
										 |  |  |     inputsForms, | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   } = useChatWithHistoryContext() | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const isPin = pinnedConversationList.some(item => item.id === currentConversationId) | 
					
						
							|  |  |  |   const [showConfirm, setShowConfirm] = useState<ConversationItem | null>(null) | 
					
						
							|  |  |  |   const [showRename, setShowRename] = useState<ConversationItem | null>(null) | 
					
						
							|  |  |  |   const handleOperate = useCallback((type: string) => { | 
					
						
							|  |  |  |     if (type === 'pin') | 
					
						
							|  |  |  |       handlePinConversation(currentConversationId) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type === 'unpin') | 
					
						
							|  |  |  |       handleUnpinConversation(currentConversationId) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type === 'delete') | 
					
						
							|  |  |  |       setShowConfirm(currentConversationItem as any) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (type === 'rename') | 
					
						
							|  |  |  |       setShowRename(currentConversationItem as any) | 
					
						
							|  |  |  |   }, [currentConversationId, currentConversationItem, handlePinConversation, handleUnpinConversation]) | 
					
						
							|  |  |  |   const handleCancelConfirm = useCallback(() => { | 
					
						
							|  |  |  |     setShowConfirm(null) | 
					
						
							|  |  |  |   }, []) | 
					
						
							|  |  |  |   const handleDelete = useCallback(() => { | 
					
						
							|  |  |  |     if (showConfirm) | 
					
						
							|  |  |  |       handleDeleteConversation(showConfirm.id, { onSuccess: handleCancelConfirm }) | 
					
						
							|  |  |  |   }, [showConfirm, handleDeleteConversation, handleCancelConfirm]) | 
					
						
							|  |  |  |   const handleCancelRename = useCallback(() => { | 
					
						
							|  |  |  |     setShowRename(null) | 
					
						
							|  |  |  |   }, []) | 
					
						
							|  |  |  |   const handleRename = useCallback((newName: string) => { | 
					
						
							|  |  |  |     if (showRename) | 
					
						
							|  |  |  |       handleRenameConversation(showRename.id, newName, { onSuccess: handleCancelRename }) | 
					
						
							|  |  |  |   }, [showRename, handleRenameConversation, handleCancelRename]) | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |   const [showSidebar, setShowSidebar] = useState(false) | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |   const [showChatSettings, setShowChatSettings] = useState(false) | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='flex shrink-0 items-center gap-1 bg-mask-top2bottom-gray-50-to-transparent px-2 py-3'> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |         <ActionButton size='l' className='shrink-0' onClick={() => setShowSidebar(true)}> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiMenuLine className='h-[18px] w-[18px]' /> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |         </ActionButton> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className='flex grow items-center justify-center'> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |           {!currentConversationId && ( | 
					
						
							|  |  |  |             <> | 
					
						
							|  |  |  |               <AppIcon | 
					
						
							|  |  |  |                 className='mr-2' | 
					
						
							|  |  |  |                 size='tiny' | 
					
						
							|  |  |  |                 icon={appData?.site.icon} | 
					
						
							|  |  |  |                 iconType={appData?.site.icon_type} | 
					
						
							|  |  |  |                 imageUrl={appData?.site.icon_url} | 
					
						
							|  |  |  |                 background={appData?.site.icon_background} | 
					
						
							|  |  |  |               /> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <div className='system-md-semibold truncate text-text-secondary'> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |                 {appData?.site.title} | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             </> | 
					
						
							|  |  |  |           )} | 
					
						
							|  |  |  |           {currentConversationId && ( | 
					
						
							|  |  |  |             <Operation | 
					
						
							|  |  |  |               title={currentConversationItem?.name || ''} | 
					
						
							|  |  |  |               isPinned={!!isPin} | 
					
						
							|  |  |  |               togglePin={() => handleOperate(isPin ? 'unpin' : 'pin')} | 
					
						
							|  |  |  |               isShowDelete | 
					
						
							|  |  |  |               isShowRenameConversation | 
					
						
							|  |  |  |               onRenameConversation={() => handleOperate('rename')} | 
					
						
							|  |  |  |               onDelete={() => handleOperate('delete')} | 
					
						
							|  |  |  |             /> | 
					
						
							|  |  |  |           )} | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |         <MobileOperationDropdown | 
					
						
							|  |  |  |           handleResetChat={handleNewConversation} | 
					
						
							|  |  |  |           handleViewChatSettings={() => setShowChatSettings(true)} | 
					
						
							| 
									
										
										
										
											2025-05-06 13:15:23 +08:00
										 |  |  |           hideViewChatSettings={inputsForms.length < 1} | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |         /> | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       {showSidebar && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className='fixed inset-0 z-50 flex bg-background-overlay p-1' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |           onClick={() => setShowSidebar(false)} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <div className='flex h-full w-[calc(100vw_-_40px)] rounded-xl bg-components-panel-bg shadow-lg backdrop-blur-sm' onClick={e => e.stopPropagation()}> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |             <Sidebar /> | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |       )} | 
					
						
							|  |  |  |       {showChatSettings && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         <div className='fixed inset-0 z-50 flex justify-end bg-background-overlay p-1' | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |           onClick={() => setShowChatSettings(false)} | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <div className='flex h-full w-[calc(100vw_-_40px)] flex-col rounded-xl bg-components-panel-bg shadow-lg backdrop-blur-sm' onClick={e => e.stopPropagation()}> | 
					
						
							|  |  |  |             <div className='flex items-center gap-3 rounded-t-2xl border-b border-divider-subtle px-4 py-3'> | 
					
						
							|  |  |  |               <Message3Fill className='h-6 w-6 shrink-0' /> | 
					
						
							|  |  |  |               <div className='system-xl-semibold grow text-text-secondary'>{t('share.chat.chatSettingsTitle')}</div> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |             </div> | 
					
						
							|  |  |  |             <div className='p-4'> | 
					
						
							| 
									
										
										
										
											2025-03-27 11:58:16 +08:00
										 |  |  |               <InputsFormContent /> | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |             </div> | 
					
						
							|  |  |  |           </div> | 
					
						
							| 
									
										
										
										
											2025-03-03 14:44:51 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |       {!!showConfirm && ( | 
					
						
							|  |  |  |         <Confirm | 
					
						
							|  |  |  |           title={t('share.chat.deleteConversation.title')} | 
					
						
							|  |  |  |           content={t('share.chat.deleteConversation.content') || ''} | 
					
						
							|  |  |  |           isShow | 
					
						
							|  |  |  |           onCancel={handleCancelConfirm} | 
					
						
							|  |  |  |           onConfirm={handleDelete} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       )} | 
					
						
							|  |  |  |       {showRename && ( | 
					
						
							|  |  |  |         <RenameModal | 
					
						
							|  |  |  |           isShow | 
					
						
							|  |  |  |           onClose={handleCancelRename} | 
					
						
							|  |  |  |           saveLoading={conversationRenaming} | 
					
						
							|  |  |  |           name={showRename?.name || ''} | 
					
						
							|  |  |  |           onSave={handleRename} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |       )} | 
					
						
							| 
									
										
										
										
											2024-02-04 16:10:46 +08:00
										 |  |  |     </> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default HeaderInMobile |