import React, { Component } from 'react'
import { connect } from 'react-redux'
import _ from 'lodash'

import Nav from './FlowView/Nav'
import { ErrorView as Error, Request, Response } from './FlowView/Messages'
import Details from './FlowView/Details'

import { selectTab } from '../ducks/ui/flow'

export const allTabs = { Request, Response, Error, Details }

function FlowView({ flow, tabName, selectTab }) {

    // only display available tab names
    const tabs = ['request', 'response', 'error'].filter(k => flow[k])
    tabs.push("details")

    if (tabs.indexOf(tabName) < 0) {
        if (tabName === 'response' && flow.error) {
            tabName = 'error'
        } else if (tabName === 'error' && flow.response) {
            tabName = 'response'
        } else {
            tabName = tabs[0]
        }
    }

    const Tab = allTabs[_.capitalize(tabName)]

    return (
        <div className="flow-detail">
            <Nav
                tabs={tabs}
                active={tabName}
                onSelectTab={selectTab}
            />
            <Tab flow={flow}/>
        </div>
    )
}

export default connect(
    state => ({
        flow: state.flows.byId[state.flows.selected[0]],
        tabName: state.ui.flow.tab,
    }),
    {
        selectTab,
    }
)(FlowView)
sys/'>summary</a><a href='/cgit/iCE40/yosys/refs/?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>refs</a><a href='/cgit/iCE40/yosys/log/manual/PRESENTATION_ExAdv/addshift_test.v'>log</a><a class='active' href='/cgit/iCE40/yosys/tree/manual/PRESENTATION_ExAdv/addshift_test.v?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>tree</a><a href='/cgit/iCE40/yosys/commit/manual/PRESENTATION_ExAdv/addshift_test.v?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>commit</a><a href='/cgit/iCE40/yosys/diff/manual/PRESENTATION_ExAdv/addshift_test.v?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>diff</a><a href='/cgit/iCE40/yosys/stats/manual/PRESENTATION_ExAdv/addshift_test.v'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/iCE40/yosys/log/manual/PRESENTATION_ExAdv/addshift_test.v'>
<input type='hidden' name='id' value='6d49145497e48bb063ebbed5164b45569e91b5ca'/><select name='qt'>
<option value='grep'>log msg</option>
<option value='author'>author</option>
<option value='committer'>committer</option>
<option value='range'>range</option>
</select>
<input class='txt' type='search' size='10' name='q' value=''/>
<input type='submit' value='search'/>
</form>
</td></tr></table>
<div class='path'>path: <a href='/cgit/iCE40/yosys/tree/?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>root</a>/<a href='/cgit/iCE40/yosys/tree/manual?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>manual</a>/<a href='/cgit/iCE40/yosys/tree/manual/PRESENTATION_ExAdv?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>PRESENTATION_ExAdv</a>/<a href='/cgit/iCE40/yosys/tree/manual/PRESENTATION_ExAdv/addshift_test.v?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>addshift_test.v</a></div><div class='content'>blob: b53271faac6ebcb20bf984091cc9063fa9c7b243 (<a href='/cgit/iCE40/yosys/plain/manual/PRESENTATION_ExAdv/addshift_test.v?id=6d49145497e48bb063ebbed5164b45569e91b5ca'>plain</a>)
<table summary='blob content' class='blob'>
<tr><td class='linenumbers'><pre><a id='n1' href='#n1'>1</a>
<a id='n2' href='#n2'>2</a>
<a id='n3' href='#n3'>3</a>
<a id='n4' href='#n4'>4</a>
<a id='n5' href='#n5'>5</a>
</pre></td>
<td class='lines'><pre><code>