import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:frontend_splatournament_manager/main.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; class ApiClient { static const String baseUrl = SplatournamentApp.baseUrl; static const _storage = FlutterSecureStorage(); static Future> _getHeaders() async { final token = await _storage.read(key: 'jwt_token'); return { 'Content-Type': 'application/json', if (token != null) 'Authorization': 'Bearer $token', }; } static Future get(String endpoint) async { final headers = await _getHeaders(); return await http.get(Uri.parse('$baseUrl$endpoint'), headers: headers); } static Future post(String endpoint, Map body) async { final headers = await _getHeaders(); return await http.post( Uri.parse('$baseUrl$endpoint'), headers: headers, body: jsonEncode(body), ); } static Future put(String endpoint, Map body) async { final headers = await _getHeaders(); return await http.put( Uri.parse('$baseUrl$endpoint'), headers: headers, body: jsonEncode(body), ); } static Future delete(String endpoint) async { final headers = await _getHeaders(); return await http.delete(Uri.parse('$baseUrl$endpoint'), headers: headers); } }