/**
 * Development-only file manager for testing forms.
 *
 * Creates an in-memory file manager backed by hazo_files upload API.
 * NOT for production use — files are stored in memory and lost on page refresh.
 *
 * @param upload_endpoint - Upload API endpoint (default: '/api/files/upload')
 * @param download_endpoint - Download API endpoint (default: '/api/files/download')
 */
export function create_dev_file_manager(upload_endpoint = '/api/files/upload', download_endpoint = '/api/files/download') {
    const file_paths = new Map();
    const blob_urls = new Map();
    return {
        callbacks: {
            upload: async (file, options) => {
                const file_id = `file_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
                const remote_path = `/dev-uploads/${file_id}_${file.name}`;
                const form_data = new FormData();
                form_data.append('file', file);
                form_data.append('remote_path', remote_path);
                const res = await fetch(upload_endpoint, { method: 'POST', body: form_data });
                const result = await res.json();
                if (!result.success) {
                    throw new Error(result.error || 'Upload failed');
                }
                file_paths.set(file_id, remote_path);
                blob_urls.set(file_id, URL.createObjectURL(file));
                return {
                    file_id,
                    ref_id: `ref_${file_id}`,
                    file_name: file.name,
                    file_size: file.size,
                    mime_type: file.type || 'application/octet-stream',
                    visibility: options?.visibility ?? 'public',
                    attached_at: new Date().toISOString(),
                };
            },
            remove: async (file_id) => {
                const blob_url = blob_urls.get(file_id);
                if (blob_url)
                    URL.revokeObjectURL(blob_url);
                blob_urls.delete(file_id);
                file_paths.delete(file_id);
            },
            get_download_url: (file_id) => {
                const path = file_paths.get(file_id);
                if (path)
                    return `${download_endpoint}?path=${encodeURIComponent(path)}`;
                return blob_urls.get(file_id) ?? '#';
            },
        },
    };
}
//# sourceMappingURL=dev_file_manager.js.map