const preact = require('preact');
const { Provider } = require('preact-redux');
const { createStore, combineReducers } = require('redux');

const reducers = require('./reducers');
const actions = require('./actions');
const createSocket = require('./animations.socket');

// const TrippyTriangle = require('./components/svgs/trippy.triangle');
// const Amplify = require('./components/svgs/amplify');
// const Hex = require('./components/svgs/hex');
const Game = require('./components/game');
const testGameBuilder = require('./test.game');

const testGame = testGameBuilder('8552e0bf-340d-4fc8-b6fc-cccccccccccc');
const testAccount = {
    id: '8552e0bf-340d-4fc8-b6fc-cccccccccccc',
    name: 'ntr',
};

// Redux Store
const store = createStore(
    combineReducers(reducers)
);

store.subscribe(() => console.log(store.getState()));
store.dispatch(actions.setAccount(testAccount));
store.dispatch(actions.setGame(testGame));

function animationsNav(ws) {
    function useSkill(skill) {
        const ateam = Math.round(Math.random());
        const bteam = Math.round(Math.random());
        const acon = Math.floor(Math.random() * 3);
        const bcon = Math.floor(Math.random() * 3);

        const a = testGame.players[ateam].constructs[acon].id;
        const b = testGame.players[bteam].constructs[bcon].id;

        return ws.sendDevResolve(a, b, skill);
    }

    return SKILLS.map((s, i) => (
        <button
            key={i}
            onClick={() => useSkill(s)}>
            {s}
        </button>
    ));
}

document.fonts.load('16pt "Jura"').then(() => {
    const ws = createSocket(store);
    ws.connect();

    const Animations = () => (
        <Provider store={store}>
            <div id="mnml">
                <nav>
                    {animationsNav(ws)}
                </nav>
                <Game />
            </div>
        </Provider>
    );

    // eslint-disable-next-line
    preact.render(<Animations />, document.body);
});

const SKILLS = [
    'AbsorbI',
    'AbsorptionI',
    'AmplifyI',
    'Attack',
    'BanishI',
    'BashI',
    'BlastI',
    'Block',
    'BreakI',
    'Buff',
    'ChaosI',
    'CounterAttackI',
    'CounterI',
    'CurseI',
    'Debuff',
    'DecayI',
    'DecayTickI',
    'ElectrifyI',
    'ElectrocuteI',
    'ElectrocuteTickI',
    'HasteI',
    'HasteStrike',
    'HealI',
    'HybridBlast',
    'HybridI',
    'InterceptI',
    'InvertI',
    'LinkI',
    'PurgeI',
    'PurifyI',
    'RechargeI',
    'ReflectI',
    'RestrictI',
    'RuinI',
    'SilenceI',
    'SiphonI',
    'SiphonTickI',
    'SlayI',
    'SleepI',
    'StrikeI',
    'Stun',
    'SustainI',
    'TriageI',
    'TriageTickI',
];
