/**
 * Created by baoyinghai on 10/21/16.
 */
import React from 'react';
import { Spin } from '../../components/mxa';
import Compose from '../utils/Compose';
import AsyncDecorator from './AsyncDecorator';
import InitDecorator from './InitDecorator';
import { getMenu } from '../service/CacheService';
import { getMenuItemAndPathByFunc } from '../utils/MenuHelper';


export const composePage = () => {
  return Compose(AsyncDecorator, InitDecorator)();
};

class PageContainer extends React.PureComponent {
  render() {
    if (this.props.query === undefined) {
      return (
        <div className="loading-mask">
          <Spin size="large" />
        </div>
      );
    }

    const domainLink = this.props.params.splat;
    const { linkInfo } = getMenuItemAndPathByFunc(item =>
      (item.actionLink === domainLink || item.actionLink === '/' + domainLink),
      getMenu());
    const domainType = linkInfo ? linkInfo.templateType : this.props.query.domainType;
    const FinalPage = composePage();
    return (
      <FinalPage
        key="key_page_container"
        {...this.props}
        menuValue={linkInfo && linkInfo.menuValue}
        domainType={domainType}
        domainLink={domainLink}
      />
    );
  }
}

export default PageContainer;
