import 'package:flutter/cupertino.dart';
import 'package:yumi/shared/tools/sc_room_utils.dart';
import 'package:yumi/shared/tools/sc_string_utils.dart';
import 'package:yumi/shared/business_logic/models/res/sc_index_banner_res.dart';
import 'package:yumi/modules/index/main_route.dart';
import 'package:yumi/app/routes/sc_fluro_navigator.dart';

import '../../shared/data_sources/models/enum/sc_banner_open_type.dart';

class SCBannerUtils {
  static void openBanner(SCIndexBannerRes item, BuildContext context) {
    if (item.content == SCBannerOpenType.ENTER_ROOM.name) {
      var params = item.params;
      if (params != null && params.isNotEmpty) {
        SCRoomUtils.goRoom(params, context);
      }
    } else {
      var params = item.params;
      if (SCStringUtils.checkIfUrl(params ?? "")) {
        SCNavigatorUtils.push(
          context,
          "${SCMainRoute.webViewPage}?url=${Uri.encodeComponent(params ?? "")}&showTitle=false",
          replace: false,
        );
      }
    }
  }
}
