import { Divider } from '@mui/material';

import type { HostInfo } from '../types';
import { CmdbEmbed } from './CmdbEmbed';
import { GroupsSection } from './GroupsSection';
import { HostInfoPanels } from './HostInfoPanels';
import { InventorySection } from './InventorySection';
import { MeasurementsSection } from './MeasurementsSection';
import { PolicyExecutionSection } from './PolicyExecutionSection';

interface Props {
  hostkey: string;
  hostname: string;
  info: HostInfo;
}

export const HostInfoTab = ({ hostkey, hostname, info }: Props) => {
  const cfengineRoles = (info.cfengineRoles ?? info['CFEngine roles'] ?? '') as string;
  const isHub = /Reporting hub|policy_server/.test(cfengineRoles);

  return (
    <div>
      <HostInfoPanels hostkey={hostkey} info={info} isHub={isHub} />

      <Divider sx={{ my: '20px' }} />
      <GroupsSection hostkey={hostkey} />

      <Divider sx={{ my: '20px' }} />
      <CmdbEmbed hostkey={hostkey} isHub={isHub} />

      <Divider sx={{ my: '20px' }} />
      <InventorySection hostkey={hostkey} hostname={hostname} />

      <Divider sx={{ my: '20px' }} />
      <h4>Measurements</h4>
      <MeasurementsSection hostkey={hostkey} hostname={hostname} />

      <Divider sx={{ my: '20px' }} />
      <PolicyExecutionSection hostkey={hostkey} />
    </div>
  );
};
