import 'package:app/request/api/room_api.dart';
import 'package:app/request/dto/room/room_list_item_dto.dart';
import 'package:app/utils/time.dart';
import 'package:flutter/cupertino.dart';

class SHomeVm extends ChangeNotifier {
  RoomListItemDto ? roomInfo;
  bool loading = true;

  SHomeVm() {
    loadData();
  }

  //加载数据
  Future<void> loadData() async {
    final list = await getRoomListApi();
    loading = false;

    if (list.isNotEmpty) {
      roomInfo = list.first;
    }

    notifyListeners();
  }

  ///计算会议时间
  int get roomMinutes {
    if (roomInfo == null) return 0;
    final start = parseTime(roomInfo!.startTime);
    final end = parseTime(roomInfo!.endTime);

    return end.difference(start).inMinutes;
  }
}
