const preact = require('preact');
const { Component } = require('preact');
const { connect } = require('preact-redux');

const Amplify = require('./anims/amplify');
const Attack = require('./anims/attack');
const Absorb = require('./anims/absorb');
const Bash = require('./anims/bash');
const Blast = require('./anims/blast');
const Block = require('./anims/block');
const Buff = require('./anims/buff');
const Break = require('./anims/break');
const Chaos = require('./anims/chaos');
const Sustain = require('./anims/sustain');
const Counter = require('./anims/counter');
const Curse = require('./anims/curse');
const Debuff = require('./anims/debuff');
const Decay = require('./anims/decay');
const Electrify = require('./anims/electrify');
const Electrocute = require('./anims/electrocute');
const Haste = require('./anims/haste');
const Heal = require('./anims/heal');
const Hybrid = require('./anims/hybrid');
const Intercept = require('./anims/intercept');
const Link = require('./anims/link');
const Purify = require('./anims/purify');
const Purge = require('./anims/purge');
const Recharge = require('./anims/recharge');
const Refl = require('./anims/reflect');
const Restrict = require('./anims/restrict');
const Ruin = require('./anims/ruin');
const Silence = require('./anims/silence');
const Siphon = require('./anims/siphon');
const SiphonTick = require('./anims/siphon.tick');
const Slay = require('./anims/slay');
const Sleep = require('./anims/sleep');
const Strike = require('./anims/strike');
const Stun = require('./anims/stun');
const Triage = require('./anims/triage');
const TriageTick = require('./anims/triage.tick');

const actions = require('../actions');
const { removeTier } = require('../utils');


const addState = connect(
    function receiveState(state) {
        const { animTarget } = state;
        return { animTarget };
    },
);

class ConstructAnimation extends Component {
    render(props) {
        const {
            animTarget,
            construct,
        } = props;

        if (!animTarget) return false;

        const {
            skill,
            player,
            direction,
            constructId,
        } = animTarget;
        const animSkill = removeTier(skill);
        if (!constructId.includes(construct.id)) return false;


        // find target animation
        const chooseAnim = (animSkill) => {
            switch (animSkill) {
            // Attack base
            case 'Attack': return <Attack direction={direction}/>;
            case 'Blast': return <Blast direction={direction}/>;
            case 'Siphon': return <Siphon />;
            case 'SiphonTick': return <SiphonTick />;
            case 'Strike': return <Strike colour={'#a52a2a'} direction={direction}/>;
            case 'Chaos': return <Chaos direction={direction}/>;
            case 'Slay': return <Slay direction={direction}/>;
            case 'Heal': return <Heal />;

            // Buff Base
            case 'Buff': return <Buff />;
            case 'Amplify': return <Amplify />;
            case 'Haste': return <Haste />;
            case 'Triage': return <Triage />;
            case 'TriageTick': return <TriageTick />;
            case 'Link': return <Link player={player} />;
            case 'Hybrid': return <Hybrid />;
            case 'Intercept': return <Intercept player={player} />;

            // Debuff base
            case 'Debuff': return <Debuff />;
            case 'Curse': return <Curse />;
            case 'Decay': return <Decay />;
            case 'DecayTick': return <Decay />;
            // case 'Invert': return setAvatarAnimation(true, true, resolution.id, construct.id, 'invert', null);
            case 'Purge': return <Purge />;
            case 'Silence': return <Silence />;
            case 'Restrict': return <Restrict />;

            // Stun Base
            case 'Stun': return <Stun />;
            // case 'Banish': return setAvatarAnimation(true, true, resolution.id, construct.id, 'banish', null);
            case 'Bash': return <Bash />;
            case 'Absorb': return <Absorb />;
            case 'Sleep': return <Sleep />;
            case 'Break': return <Break />;
            case 'Ruin': return <Ruin />;

            // Block Base
            case 'Block': return <Block />;
            case 'Sustain': return <Sustain player={player} />;
            case 'Electrify': return <Electrify />;
            case 'Electrocute': return <Electrocute />;
            case 'ElectrocuteTick': return <Electrocute />;
            case 'Counter': return <Counter player={player} />;
            case 'CounterAttack': return <Attack direction={direction} />;
            case 'Purify': return <Purify player={player} />;
            case 'Recharge': return <Recharge player={player} />;
            case 'Reflect': return <Refl player={player} />;

            default: return false;
            };
        };

        const anim = chooseAnim(animSkill);
        if (!anim) return false;

        return (
            <div class={'combat-anim'}>
                {anim}
            </div>
        );
    }
}


module.exports = {
    ConstructAnimation: addState(ConstructAnimation),
};
