import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'

import { startEdit, stopEdit } from '../../ducks/ui/flow'

ToggleEdit.propTypes = {
    isEdit: PropTypes.bool.isRequired,
    flow: PropTypes.object.isRequired,
    startEdit: PropTypes.func.isRequired,
    stopEdit: PropTypes.func.isRequired,
}

function ToggleEdit({ isEdit, startEdit, stopEdit, flow, modifiedFlow }) {
    return (
        <div className="edit-flow-container">
            {isEdit ?
                <a className="edit-flow" title="Finish Edit" onClick={() => stopEdit(flow, modifiedFlow)}>
                    <i className="fa fa-check"/>
                </a>
                :
                <a className="edit-flow" title="Edit Flow" onClick={() => startEdit(flow)}>
                    <i className="fa fa-pencil"/>
                </a>
            }
        </div>
    )
}

export default connect(
    state => ({
        isEdit: !!state.ui.flow.modifiedFlow,
        modifiedFlow: state.ui.flow.modifiedFlow || state.flows.byId[state.flows.selected[0]],
        flow: state.flows.byId[state.flows.selected[0]]
    }),
    {
        startEdit,
        stopEdit,
    }
)(ToggleEdit)
table>
<table class='tabs'><tr><td>
<a href='/cgit/cloud-email/mitmproxy/about/'>about</a><a href='/cgit/cloud-email/mitmproxy/'>summary</a><a href='/cgit/cloud-email/mitmproxy/refs/?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>refs</a><a href='/cgit/cloud-email/mitmproxy/log/examples/simple/add_header_class.py'>log</a><a class='active' href='/cgit/cloud-email/mitmproxy/tree/examples/simple/add_header_class.py?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>tree</a><a href='/cgit/cloud-email/mitmproxy/commit/examples/simple/add_header_class.py?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>commit</a><a href='/cgit/cloud-email/mitmproxy/diff/examples/simple/add_header_class.py?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>diff</a><a href='/cgit/cloud-email/mitmproxy/stats/examples/simple/add_header_class.py'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit/cloud-email/mitmproxy/log/examples/simple/add_header_class.py'>
<input type='hidden' name='id' value='b6d943cfa3a226651e705ff45aa7154010ea29ba'/><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/cloud-email/mitmproxy/tree/?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>root</a>/<a href='/cgit/cloud-email/mitmproxy/tree/examples?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>examples</a>/<a href='/cgit/cloud-email/mitmproxy/tree/examples/simple?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>simple</a>/<a href='/cgit/cloud-email/mitmproxy/tree/examples/simple/add_header_class.py?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>add_header_class.py</a></div><div class='content'>blob: 419c99ac21aa8a8643a9b070d29b732a6c9bfed2 (<a href='/cgit/cloud-email/mitmproxy/plain/examples/simple/add_header_class.py?id=b6d943cfa3a226651e705ff45aa7154010ea29ba'>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>
<a id='n6' href='#n6'>6</a>
<a id='n7' href='#n7'>7</a>
<a id='n8' href='#n8'>8</a>
<a id='n9' href='#n9'>9</a>
</pre></td>
<td class='lines'><pre><code>