import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:qadirneyriz/services/meetings/meetings.dart';
import 'package:qadirneyriz/utils/enums/status.dart';

class MeetingSummaryState extends ChangeNotifier {
  // send add meeting minute
  MeetingsApi meetingsApi = MeetingsApi();
  Status statusMinuteMeeting = Status.empty;
  String? messageMinuteMeeting;
  Map? errorsMinuteMeeting;

  Future<Status> addMinuteMeeting(
      {required int id,
      required String description,
      required List<PlatformFile> meetingFiles}) async {
    statusMinuteMeeting = Status.loading;
    notifyListeners();
    try {
      final result = await meetingsApi.addMeetingMinuteApi(
          id: id, description: description, meetingFiles: meetingFiles);
      if (result.isOk) {
        statusMinuteMeeting = Status.ready;
        messageMinuteMeeting = result.message;
      } else if (result.isOk == false) {
        print(result.isOk);
        errorsMinuteMeeting = result.errors;
        messageMinuteMeeting = result.message;
        statusMinuteMeeting = Status.error;
      } else {
        statusMinuteMeeting = Status.error;
      }
      notifyListeners();
    } catch (e) {
      statusMinuteMeeting = Status.error;
      print(e);
    }
    notifyListeners();
    print(statusMinuteMeeting);
    return statusMinuteMeeting;
  }

  List<PlatformFile>? selectedFiles;

  Future<void> pickFiles() async {
    final result = await FilePicker.platform.pickFiles(
      allowMultiple: true,
    );

    if (result != null) {
      selectedFiles = result.files;

      notifyListeners();
    }
  }

  void removeFile(int index) {
    selectedFiles!.removeAt(index);
    notifyListeners();
  }
}
