import PropTypes from 'prop-types'
import { connect } from "react-redux"
import { update as updateSettings } from "../../ducks/settings"
import { toggleVisibility } from "../../ducks/eventLog"

MenuToggle.propTypes = {
    value: PropTypes.bool.isRequired,
    onChange: PropTypes.func.isRequired,
    children: PropTypes.node.isRequired,
}

export function MenuToggle({ value, onChange, children }) {
    return (
        <div className="menu-entry">
            <label>
                <input type="checkbox"
                       checked={value}
                       onChange={onChange}/>
                {children}
            </label>
        </div>
    )
}


SettingsToggle.propTypes = {
    setting: PropTypes.string.isRequired,
    children: PropTypes.node.isRequired,
}

export function SettingsToggle({ setting, children, settings, updateSettings }) {
    return (
        <MenuToggle
            value={settings[setting] || false} // we don't have settings initially, so just pass false.
            onChange={() => updateSettings({ [setting]: !settings[setting] })}
        >
            {children}
        </MenuToggle>
    )
}
SettingsToggle = connect(
    state => ({
        settings: state.settings,
    }),
    {
        updateSettings,
    }
)(SettingsToggle)


export function EventlogToggle({ toggleVisibility, eventLogVisible }) {
    return (
        <MenuToggle
            value={eventLogVisible}
            onChange={toggleVisibility}
        >
            Display Event Log
        </MenuToggle>
    )
}
EventlogToggle = connect(
    state => ({
        eventLogVisible: state.eventLog.visible,
    }),
    {
        toggleVisibility,
    }
)(EventlogToggle)

m-br6478acv2/master-187ad058/log/target/linux/Makefile'>log</a><a class='active' href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/tree/target/linux/Makefile?id=20350819d2e024f60c9641fa6728148734bb3375'>tree</a><a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/commit/target/linux/Makefile?id=20350819d2e024f60c9641fa6728148734bb3375'>commit</a><a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/diff/target/linux/Makefile?id=20350819d2e024f60c9641fa6728148734bb3375'>diff</a><a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/stats/target/linux/Makefile'>stats</a></td><td class='form'><form class='right' method='get' action='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/log/target/linux/Makefile'>
<input type='hidden' name='id' value='20350819d2e024f60c9641fa6728148734bb3375'/><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.cgi/openwrt/em-br6478acv2/master-187ad058/tree/?id=20350819d2e024f60c9641fa6728148734bb3375'>root</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/tree/target?id=20350819d2e024f60c9641fa6728148734bb3375'>target</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/tree/target/linux?id=20350819d2e024f60c9641fa6728148734bb3375'>linux</a>/<a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/tree/target/linux/Makefile?id=20350819d2e024f60c9641fa6728148734bb3375'>Makefile</a></div><div class='content'>blob: f7bbdffbf831654ca8617277e5fd7aeb8959f416 (<a href='/cgit.cgi/openwrt/em-br6478acv2/master-187ad058/plain/target/linux/Makefile?id=20350819d2e024f60c9641fa6728148734bb3375'>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>
<a id='n10' href='#n10'>10</a>
<a id='n11' href='#n11'>11</a>
<a id='n12' href='#n12'>12</a>
<a id='n13' href='#n13'>13</a>
</pre></td>
<td class='lines'><pre><code>