import { ExperimentStatus } from '@/enums';
import { AutoMLInstanceData } from '@/pages/AutoML/types';
import LogList from '@/pages/Experiment/components/LogList';
import { NodeStatus } from '@/types';
import EmptyLog from './empty';
import styles from './index.less';

const NodePrefix = 'auto-ml';

type ExperimentLogProps = {
  instanceInfo: AutoMLInstanceData;
  nodes: Record<string, NodeStatus>;
};

function ExperimentLog({ instanceInfo, nodes }: ExperimentLogProps) {
  const nodeStatus: NodeStatus | undefined = Object.values(nodes).find((node: any) =>
    node.displayName.startsWith(NodePrefix),
  ) as NodeStatus;

  return (
    <div className={styles['experiment-log']}>
      <div className={styles['experiment-log__log']}>
        {nodeStatus ? (
          <LogList
            instanceName={instanceInfo.argo_ins_name}
            instanceNamespace={instanceInfo.argo_ins_ns}
            pipelineNodeId={nodeStatus.displayName}
            workflowId={nodeStatus.id}
            instanceNodeStartTime={nodeStatus.startedAt}
            instanceNodeStatus={nodeStatus.phase as ExperimentStatus}
          ></LogList>
        ) : (
          <EmptyLog />
        )}
      </div>
    </div>
  );
}

export default ExperimentLog;
