/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { useCallback, useState } from 'react';
import { useModalState } from '../hooks/useModalState.js';
/* eslint-disable @typescript-eslint/unbound-method */ export function useDeleteConfirm(onDelete) {
    const { isOpen , show , hide , toggle  } = useModalState(undefined, undefined);
    const [deleteIndex, setDeleteIndex] = useState();
    const onDeleteClicked = useCallback((index)=>{
        setDeleteIndex(index);
        show();
    }, [
        show,
        setDeleteIndex
    ]);
    const onConfirmDelete = useCallback(()=>{
        deleteIndex !== undefined && onDelete?.(deleteIndex);
        hide();
    }, [
        hide,
        deleteIndex,
        onDelete
    ]);
    return {
        isOpen,
        toggle,
        onConfirm: onConfirmDelete,
        onClick: onDeleteClicked
    };
}
