// ignore: avoid_web_libraries_in_flutter
import 'package:web/web.dart' as web;

import 'package:flutter/material.dart';

import 'package:share_plus/share_plus.dart';

import 'package:pweb/utils/clipboard.dart';


enum DeviceType { desktop, mobile, unknown }

DeviceType getDeviceType() {
  final userAgent = web.window.navigator.userAgent;
  if (userAgent.contains('Mobile') || userAgent.contains('Android') || userAgent.contains('iPhone')) {
    return DeviceType.mobile;
  }
  
  if (userAgent.contains('Windows') || userAgent.contains('Macintosh') || userAgent.contains('Linux')) {
    return DeviceType.desktop;
  }

  return DeviceType.unknown;
}



Future<void> share(BuildContext context, String content, String hint, String clipboardHint, {int delaySeconds = 1}) {

  if (getDeviceType() != DeviceType.desktop) {
    final RenderBox box = context.findRenderObject() as RenderBox;
    return SharePlus.instance.share(ShareParams(
      text: content,
      subject: hint,
      sharePositionOrigin: box.localToGlobal(Offset.zero) & box.size,
    ));
  } 
  
  return copyToClipboard(context, content, clipboardHint, delaySeconds: delaySeconds);
}