import 'package:chat/chat/my_special_text_span_builder.dart';
import 'package:extended_text/extended_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:ui' as ui show window;

class Screen {
  static double uiFactor = 1.0;
  static initFactor() {
    uiFactor = width / 640;
  }

  static double get width {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.width;
  }

  static double get height {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.size.height;
  }

  static double get scale {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.devicePixelRatio;
  }

  static double get textScaleFactor {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.textScaleFactor;
  }

  static double get navigationBarHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top + kToolbarHeight;
  }

  static double get topSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.top;
  }

  static double get bottomSafeHeight {
    MediaQueryData mediaQuery = MediaQueryData.fromWindow(ui.window);
    return mediaQuery.padding.bottom;
  }

  static updateStatusBarStyle(SystemUiOverlayStyle style) {
    SystemChrome.setSystemUIOverlayStyle(style);
  }
}

fixedFontSize(double fontSize) {
  return fontSize / Screen.textScaleFactor;
}

fixedText(data, {Color color, double fontSize, FontWeight fontWeight}) {
  return Text(data,
      textScaleFactor: 1.0,
      style: TextStyle(
          fontSize: fontSize ?? 14.0, color: color, fontWeight: fontWeight));
}

extendedText(String text,
    {Color color = Colors.blue,
      double fontSize = 14,
      selectionEnabled = false,
      double emojisize = 20.0,
      Function hideKeyboard,
      fontWeight,int maxLines,
      Function onSpecialTextTap,
    }) {
  return ExtendedText(
    text,
    onSpecialTextTap: onSpecialTextTap,
    textAlign: TextAlign.left,
    maxLines: maxLines,
    specialTextSpanBuilder: MySpecialTextSpanBuilder(emojiSize: emojisize),
    textScaleFactor: 1.0,
    style: TextStyle(fontSize: fontSize, color: color, fontWeight: fontWeight),
    selectionEnabled: selectionEnabled,
  );
}


setStatusBar(){
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.transparent,
      statusBarBrightness: Brightness.light,
      statusBarIconBrightness: Brightness.dark,
      systemNavigationBarColor: Colors.white,
      systemNavigationBarIconBrightness: Brightness.dark));
}


debugPrint(dynamic msg){
  print('###${DateTime.now()}####### '+msg);
}
