import { router } from '@inertiajs/react';

export function useClienteEdition() {
    const request = (method: 'post' | 'put', url: string, payload: any, options: Record<string, any> = {}) =>
        new Promise<void>((resolve, reject) => {
            const action = method === 'post' ? router.post : router.put;
            action(url, payload, {
                preserveScroll: true,
                ...options,
                onSuccess: () => resolve(),
                onError: (errors: any) => reject(errors),
            });
        });

    return {
        post: (url: string, payload: any, options?: Record<string, any>) => request('post', url, payload, options),
        put: (url: string, payload: any, options?: Record<string, any>) => request('put', url, payload, options),
    };
}
