import React, { useEffect } from 'react';
import { createPortal } from 'react-dom';
import { HomeOutlined, CameraOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import portalLogo from '@/assets/logo.png';
import './index.less';

/** 人社门户首页地址 */
const PORTAL_HOME_URL = 'http://218.31.252.15:9081/hrss-web-vue/home';

const EnterpriseHeader: React.FC = () => {
  useEffect(() => {
    document.body.classList.add('has-enterprise-header');
    return () => {
      document.body.classList.remove('has-enterprise-header');
    };
  }, []);

  const handleGoHome = () => {
    window.open(PORTAL_HOME_URL, '_blank');
  };

  const handleGoShowcase = () => {
    history.push('/management/enterprise-showcase');
  };

  const header = (
    <div className="enterprise-header">
      <div className="header-left">
        <img className="header-logo" src={portalLogo} alt="石城智慧就业" />
        <div className="header-divider" />
        <span className="header-system-name">石河子智慧就业 · 企业管理端</span>
      </div>

      <div className="header-right">
        <div className="home-link-btn" onClick={handleGoShowcase}>
          <CameraOutlined />
          <span>企业风采</span>
        </div>
        <div className="home-link-btn" onClick={handleGoHome}>
          <HomeOutlined />
          <span>返回首页</span>
        </div>
      </div>
    </div>
  );

  return createPortal(header, document.body);
};

export default EnterpriseHeader;
