import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import { useCallback, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from 'antd';
import { AimOutlined } from '@ant-design/icons';
import { Transform, Actor } from 'dacha';
import { getActorIdByPath } from '../../../../../../../utils/get-actor-id-by-path';
import { EngineContext } from '../../../../../../providers';
import { ButtonCSS } from '../../../../explorer.style';
export const FocusActionButton = ({ path, }) => {
    const { t } = useTranslation();
    const { world } = useContext(EngineContext);
    const handleClick = useCallback(() => {
        const selectedActorId = getActorIdByPath(path);
        if (!selectedActorId) {
            return;
        }
        const mainActor = world.data.mainActor;
        const selectedActor = world.findChildById(selectedActorId);
        if (selectedActor instanceof Actor && selectedActor.getComponent(Transform)) {
            const mainActorTransform = mainActor.getComponent(Transform);
            const transform = selectedActor.getComponent(Transform);
            mainActorTransform.world.position.x = transform.world.position.x;
            mainActorTransform.world.position.y = transform.world.position.y;
        }
    }, [world, path]);
    return (_jsx(Button, { css: ButtonCSS, icon: _jsx(AimOutlined, {}), size: "small", onClick: handleClick, title: t('explorer.scenes.actionBar.focusActor.button.title'), disabled: path === undefined }));
};
