// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
// with the License. A copy of the License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
// OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
// limitations under the License.
import {CloudFormationResourceStatus, Region} from '../../types/base'
import {ClusterName, ClusterStatus} from '../../types/clusters'
import {StackEvent, StackEvents} from '../../types/stackevents'
import React from 'react'
import {Link, useSearchParams} from 'react-router-dom'
// Model
import {DescribeCluster, GetClusterStackEvents} from '../../model'
import {
consoleDomain,
getState,
setState,
clearState,
useState,
} from '../../store'
import {useCollection} from '@cloudscape-design/collection-hooks'
import {findFirst} from '../../util'
// UI Elements
import {
Button,
CollectionPreferences,
Header,
Pagination,
SpaceBetween,
Table,
TextFilter,
} from '@cloudscape-design/components'
// Components
import {StackEventStatusIndicator} from '../../components/Status'
import DateView from '../../components/date/DateView'
import Loading from '../../components/Loading'
import EmptyState from '../../components/EmptyState'
function EventStatus(stackEvent: StackEvent) {
const {logicalResourceId, resourceStatus} = stackEvent
const clusterName: ClusterName = useState(['app', 'clusters', 'selected'])
const clusterPath = ['clusters', 'index', clusterName]
let headNode = useState([...clusterPath, 'headNode'])
const events: StackEvents = useState([
'clusters',
'index',
clusterName,
'stackevents',
'events',
])
let getHeadNode = (events: StackEvent[]) => {
let event = findFirst(
events,
(e: StackEvent) => e.logicalResourceId === 'HeadNode',
)
if (event) return {instanceId: event.physicalResourceId}
}
if (
logicalResourceId.startsWith('HeadNodeWaitCondition') &&
resourceStatus === CloudFormationResourceStatus.CreateFailed &&
!headNode
) {
headNode = getHeadNode(events)
}
return (
{headNode &&
logicalResourceId.startsWith('HeadNodeWaitCondition') &&
resourceStatus === CloudFormationResourceStatus.CreateFailed && (