/**
 * File History Button — injected into the file editor toolbar
 * Ball Studios <https://git.balls.studio>
 */

import React, { useState } from 'react';
import { useParams } from 'react-router-dom';
import RevisionSidebar from './RevisionSidebar';

interface Props { filePath: string; }

export default function FileHistoryButton({ filePath }: Props) {
    const { id: serverUuid } = useParams<{ id: string }>();
    const [open, setOpen] = useState(false);

    return (
        <>
            <button
                className='addon-btn addon-btn-sm addon-btn-history'
                onClick={() => setOpen(true)}
                title='View file revision history'
                aria-label='View file revision history'
            >
                🕐 History
            </button>
            {open && serverUuid && (
                <RevisionSidebar
                    serverUuid={serverUuid}
                    filePath={filePath}
                    onClose={() => setOpen(false)}
                />
            )}
        </>
    );
}
