'use client';
import { useState, useEffect, useCallback } from 'react';
export function useContentLock(documentId, userId) {
    const [lock, setLock] = useState({
        lockedBy: null,
        lockedAt: null,
        isLocked: false,
        isLockedByMe: false,
    });
    const acquireLock = useCallback(async () => {
        if (!documentId)
            return false;
        setLock({
            lockedBy: userId,
            lockedAt: new Date(),
            isLocked: true,
            isLockedByMe: true,
        });
        return true;
    }, [documentId, userId]);
    const releaseLock = useCallback(async () => {
        setLock({
            lockedBy: null,
            lockedAt: null,
            isLocked: false,
            isLockedByMe: false,
        });
    }, []);
    useEffect(() => {
        return () => {
            if (lock.isLockedByMe) {
                releaseLock();
            }
        };
    }, [lock.isLockedByMe, releaseLock]);
    return { ...lock, acquireLock, releaseLock };
}
//# sourceMappingURL=useContentLock.js.map