{"size": 1283, "ext": "js", "max_stars_repo_path": "src/components/PlayerAction.js", "max_stars_repo_name": "marmelab/labyrinth-react", "max_stars_repo_stars_event_min_datetime": "2018-11-03T01:13:48.000Z", "max_stars_repo_stars_event_max_datetime": "2020-12-01T13:36:52.000Z", "max_issues_repo_path": "src/components/PlayerAction.js", "max_issues_repo_name": "marmelab/labyrinth-react", "max_issues_repo_issues_event_min_datetime": "2018-10-15T08:30:30.000Z", "max_issues_repo_issues_event_max_datetime": "2018-10-25T07:48:45.000Z", "max_forks_repo_path": "src/components/PlayerAction.js", "max_forks_repo_name": "marmelab/labyrinth-react", "max_forks_repo_forks_event_min_datetime": "2020-11-16T09:59:26.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-16T09:59:26.000Z"}
{"max_stars_count": 2, "max_issues_count": 3, "max_forks_count": 1, "avg_line_length": 36.6571428571, "max_line_length": 117, "alphanum_fraction": 0.6017147311}
import * as React from 'react';
import { isGameInInsertState, isGameInMoveState, positionIsIn } from '../common/game';

const insert_positions = [
    { x: 0, y: 1 },
    { x: 0, y: 3 },
    { x: 0, y: 5 },
    { x: 6, y: 1 },
    { x: 6, y: 3 },
    { x: 6, y: 5 },
    { x: 1, y: 0 },
    { x: 3, y: 0 },
    { x: 5, y: 0 },
    { x: 1, y: 6 },
    { x: 3, y: 6 },
    { x: 5, y: 6 },
];

const isInsertPosition = (x, y) => insert_positions.findIndex(position => position.x === x && position.y === y) > -1;

export const PlayerAction = ({ game, x, y, onInsertRemainingPathCardAt, onMoveCurrentPlayerTo }) => {
    const renderInsertPosition = isGameInInsertState(game) && isInsertPosition(x, y);
    const renderMovePosition =
        isGameInMoveState(game) && positionIsIn({ x, y }, game.reachablePositions[game.currentPlayerIndex]);
    const subClassName = renderInsertPosition ? 'insert-position' : renderMovePosition ? 'move-player' : '';
    const onClickFunction = renderInsertPosition
        ? () => onInsertRemainingPathCardAt(game, x, y)
        : renderMovePosition
            ? () => onMoveCurrentPlayerTo(game, x, y)
            : x => x;
    return <div className={`centered-content ${subClassName}`} onClick={onClickFunction} />;
};

export default PlayerAction;
