import React, { PureComponent } from 'react';
import { NativeNavigatorTransitions, NativeNavigatorHeaderModes, NativeNavigatorModes } from './types';
import NativeSceneView from './NativeSceneView';
import NativeStackScene from './NativeStackScene';
import NativeHeader from './NativeHeader';
import NativeStackSceneContainer from './NativeStackSceneContainer';
export default class NativeScenes extends PureComponent {
    constructor() {
        super(...arguments);
        this.handleDidFocus = (route) => {
            this.props.onOpenRoute(route);
        };
        this.handleDidBlur = (route, dismissed) => {
            // If the scene has been removed from native side.
            if (dismissed) {
                if (this.props.closingRouteKey === route.key) {
                    // Handle close transition complete.
                    this.props.onCloseRoute(route);
                }
                else {
                    // Handle dismiss from native side.
                    this.props.onDismissRoute(route);
                }
            }
        };
    }
    render() {
        const { routes, descriptors, screenProps, mode, closingRouteKey } = this.props;
        return (<>
        {routes.map(route => {
            var _a, _b;
            const { key } = route;
            const descriptor = descriptors[key];
            if (!descriptor) {
                return null;
            }
            const { options, navigation } = descriptor;
            let headerMode = options.headerHidden
                ? NativeNavigatorHeaderModes.None
                : this.props.headerMode;
            if (mode === NativeNavigatorModes.Stack) {
                headerMode = headerMode || NativeNavigatorHeaderModes.Auto;
            }
            else {
                headerMode = headerMode || NativeNavigatorHeaderModes.None;
            }
            const SceneComponent = descriptor.getComponent();
            return (<NativeStackScene key={key} transition={((_b = (_a = navigation.dangerouslyGetParent()) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.isTransitioning) ?
                (options.transition || NativeNavigatorTransitions.Default) : NativeNavigatorTransitions.None} closing={closingRouteKey === route.key} gestureEnabled={options.gestureEnabled !== false} translucent={options.translucent === true} transparent={options.transparent === true} popover={options.popover} onDidFocus={this.handleDidFocus} onDidBlur={this.handleDidBlur} route={route} style={options.cardStyle} statusBarStyle={options.statusBarStyle} statusBarHidden={options.statusBarHidden}>
              <NativeStackSceneContainer>
                <NativeSceneView screenProps={screenProps} navigation={navigation} component={SceneComponent}/>
                {headerMode === NativeNavigatorHeaderModes.Auto ? (<NativeHeader descriptor={descriptor} route={route}/>) : null}
              </NativeStackSceneContainer>
            </NativeStackScene>);
        })}
      </>);
    }
}
//# sourceMappingURL=NativeScenes.js.map