import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:location/sdk/wechat/wechat_helper.dart';
import 'package:wechat_kit/wechat_kit.dart';
import '../../data/consts/web_url.dart';
import '../../resource/assets.gen.dart';
import '../../resource/string.gen.dart';

class WechatShareUtil {
  WechatShareUtil._();

  static Future<void> shareWebPage() async {
    if (!await WechatHelper.isInstalled()) {
      throw Exception(StringName.wechatNoInstall);
    }
    return WechatHelper.shareUrlToWechat(
        scene: WechatScene.kSession,
        webpageUrl: WebUrl.shareUrl,
        title: StringName.shareFriendTitle,
        description: StringName.shareFriendDesc,
        thumbData: await assetImageToBytes(Assets.images.iconLogoMax.path));
  }

  static Future<Uint8List> assetImageToBytes(String assetPath) async {
    final ByteData byteData = await rootBundle.load(assetPath);
    return byteData.buffer.asUint8List();
  }
}
