import { Breadcrumb } from 'antd';
import Chat from '../Chat';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useEffect } from 'react';
import { useStore } from '@/stores/utils';
import './index.scss';
import { isApp, isMobile } from '@/utils/tools';
const Content = () => {
  const [searchParams] = useSearchParams();
  const title = searchParams.get('title');
  const url = searchParams.get('url');
  const botId = searchParams.get('botId');
  const navigate = useNavigate();
  const { ChatStore } = useStore();

  useEffect(() => {
    // 如果有botId参数，初始化聊天页面的智能体信息
    if (botId) {
      ChatStore.setBotId(botId);
    }
  }, [botId]);
  return (
    <div className='flex_column'>
      {!isApp && !isMobile() && (
        <Breadcrumb
          className='breadcrumb'
          separator='>'
          items={[
            {
              title: '瑞小美 Ai 学苑',
              className: 'nav_home',
              onClick: () => navigate('/'),
            },
            {
              title,
            },
          ]}
        />
      )}
      <div className='flex_1'>
        {url ? (
          <iframe
            style={{
              display: 'block',
              width: '100%',
              height: isApp || isMobile() ? '100vh' : 'calc(100vh - 42px)',
              border: 'none',
            }}
            src={url}
          ></iframe>
        ) : (
          <Chat />
        )}
      </div>
    </div>
  );
};

export default Content;
