import 'package:flutter/material.dart';
import 'package:wechat_camera_picker/wechat_camera_picker.dart';
import 'package:flutter/services.dart';

/*
 * 照相机的引擎封装,目前用的 CameraPicker 插件
 */
class CameraEngine {
  /// 拍照
  static Future<AssetEntity?> takePhoto(BuildContext context) async {
    return await CameraPicker.pickFromCamera(
      context,
      pickerConfig: CameraPickerConfig(
        enableRecording: false,
        theme: ThemeData(
          brightness: Brightness.dark,
          appBarTheme: AppBarTheme(
            systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
              statusBarColor: Colors.transparent,
              statusBarBrightness: Brightness.dark,
              statusBarIconBrightness: Brightness.light,
            ),
          ),
        ),
      ),
    );
  }

  /// 录制视频
  static Future<AssetEntity?> takeVideo(
    BuildContext context, {
    int maxRecordInSeconds = 30,
  }) async {
    return await CameraPicker.pickFromCamera(
      context,
      pickerConfig: CameraPickerConfig(
        enableRecording: true,
        onlyEnableRecording: true,
        enableTapRecording: false,
        enableAudio: true,
        shouldAutoPreviewVideo: true,
        maximumRecordingDuration: Duration(seconds: maxRecordInSeconds),
        theme: ThemeData(
          brightness: Brightness.dark,
          appBarTheme: AppBarTheme(
            systemOverlayStyle: SystemUiOverlayStyle.dark.copyWith(
              statusBarColor: Colors.transparent,
              statusBarBrightness: Brightness.dark,
              statusBarIconBrightness: Brightness.light,
            ),
          ),
        ),
      ),
    );
  }
}
