content: import 'dart:convert';
  
  import 'package:dio/dio.dart';
  import 'package:hive_ce/hive.dart';
  import 'package:html/dom.dart';
  import 'package:html/parser.dart' as html_parser;
  import 'package:raven/model/trend.dart';
  import 'package:raven/repository/country.dart';
  import 'package:raven/repository/preferences/content.dart';
  import 'package:raven/repository/preferences/internal.dart';
  import 'package:raven/service/http_client.dart';
  import 'package:raven/utils/network.dart';
  
  class GoogleTrend extends Trend {
    @override
    String get name => "Google";
  
    @override
    String get url => "https://trends.google.com/trends/api/dailytrends?geo=";
  
    @override
    String get locator => "";
  
    @override
    Future<List<String>> get topics async {
      var country = "US";
      List<String> queries = [];
      if (Hive.isBoxOpen("settings")) {
        country = "${countryCodes[ContentPref.country]}";
      }
      var response = await dio().get(
        url + country,
        options: Options(
          responseType: ResponseType.plain,
        ),
      );
  
      if (response.successful) {
        Document document = html_parser.parse(response.data);
        var jsonText = document.outerHtml
            .replaceFirst(")]}',", "")
            .replaceFirst("<html><head></head><body>", "")
            .replaceFirst("</body></html>", "");
        var somethings = json.decode(jsonText)["default"]["trendingSearchesDays"];
        for (var something in somethings) {
          var searches = something["trendingSearches"];
          for (var search in searches) {
            queries.add(search["title"]["query"].toString());
          }
        }
        queries = queries.take(10).toList();
      }
      return queries;
    }
  
    @override
    List<String> locations = [
      'Afghanistan',
      'Albania',
      'Algeria',
      'American Samoa',
      'Andorra',
      'Angola',
      'Anguilla',
      'Antigua & Barbuda',
      'Argentina',
      'Armenia',
      'Aruba',
      'Australia',
      'Austria',
      'Azerbaijan',
      'Bahamas',
      'Bahrain',
      'Bangladesh',
      'Barbados',
      'Belarus',
      'Belgium',
      'Belize',
      'Benin',
      'Bermuda',
      'Bhutan',
      'Bolivia',
      'Bosnia & Herzegovina',
      'Botswana',
      'Brazil',
      'British Indian Ocean Territory',
      'British Virgin Islands',
      'Brunei',
      'Bulgaria',
      'Burkina Faso',
      'Burundi',
      'Cambodia',
      'Cameroon',
      'Canada',
      'Cape Verde',
      'Caribbean Netherlands',
      'Cayman Islands',
      'Central African Republic',
      'Chad',
      'Chile',
      'China',
      'Colombia',
      'Comoros',
      'Congo - Brazzaville',
      'Congo - Kinshasa',
      'Cook Islands',
      'Costa Rica',
      'Côte d’Ivoire',
      'Croatia',
      'Cuba',
      'Curaçao',
      'Cyprus',
      'Czechia',
      'Denmark',
      'Djibouti',
      'Dominica',
      'Dominican Republic',
      'Ecuador',
      'Egypt',
      'El Salvador',
      'Equatorial Guinea',
      'Eritrea',
      'Estonia',
      'Eswatini',
      'Ethiopia',
      'Falkland Islands (Islas Malvinas)',
      'Faroe Islands',
      'Fiji',
      'Finland',
      'France',
      'French Guiana',
      'French Polynesia',
      'Gabon',
      'Gambia',
      'Georgia',
      'Germany',
      'Ghana',
      'Gibraltar',
      'Greece',
      'Greenland',
      'Grenada',
      'Guadeloupe',
      'Guam',
      'Guatemala',
      'Guinea',
      'Guinea-Bissau',
      'Guyana',
      'Haiti',
      'Honduras',
      'Hong Kong',
      'Hungary',
      'Iceland',
      'India',
      'Indonesia',
      'Iran',
      'Iraq',
      'Ireland',
      'Israel',
      'Italy',
      'Jamaica',
      'Japan',
      'Jordan',
      'Kazakhstan',
      'Kenya',
      'Kiribati',
      'Kosovo',
      'Kuwait',
      'Kyrgyzstan',
      'Laos',
      'Latvia',
      'Lebanon',
      'Lesotho',
      'Liberia',
      'Libya',
      'Liechtenstein',
      'Lithuania',
      'Luxembourg',
      'Macao',
      'Madagascar',
      'Malawi',
      'Malaysia',
      'Maldives',
      'Mali',
      'Malta',
      'Marshall Islands',
      'Martinique',
      'Mauritania',
      'Mauritius',
      'Mexico',
      'Micronesia',
      'Moldova',
      'Monaco',
      'Mongolia',
      'Montenegro',
      'Montserrat',
      'Morocco',
      'Mozambique',
      'Myanmar (Burma)',
      'Namibia',
      'Nauru',
      'Nepal',
      'Netherlands',
      'New Caledonia',
      'New Zealand',
      'Nicaragua',
      'Niger',
      'Nigeria',
      'Niue',
      'Norfolk Island',
      'North Korea',
      'North Macedonia',
      'Northern Mariana Islands',
      'Norway',
      'Oman',
      'Pakistan',
      'Palau',
      'Palestine',
      'Panama',
      'Papua New Guinea',
      'Paraguay',
      'Peru',
      'Philippines',
      'Poland',
      'Portugal',
      'Puerto Rico',
      'Qatar',
      'Réunion',
      'Romania',
      'Russia',
      'Rwanda',
      'Samoa',
      'San Marino',
      'São Tomé & Príncipe',
      'Saudi Arabia',
      'Senegal',
      'Serbia',
      'Seychelles',
      'Sierra Leone',
      'Singapore',
      'Sint Maarten',
      'Slovakia',
      'Slovenia',
      'Solomon Islands',
      'Somalia',
      'South Africa',
      'South Korea',
      'South Sudan',
      'Spain',
      'Sri Lanka',
      'St. Barthélemy',
      'St. Helena',
      'St. Kitts & Nevis',
      'St. Lucia',
      'St. Martin',
      'St. Pierre & Miquelon',
      'St. Vincent & Grenadines',
      'Sudan',
      'Suriname',
      'Sweden',
      'Switzerland',
      'Syria',
      'Taiwan',
      'Tajikistan',
      'Tanzania',
      'Thailand',
      'Timor-Leste',
      'Togo',
      'Tokelau',
      'Tonga',
      'Trinidad & Tobago',
      'Tunisia',
      'Türkiye',
      'Turkmenistan',
      'Turks & Caicos Islands',
      'Tuvalu',
      'U.S. Virgin Islands',
      'Uganda',
      'Ukraine',
      'United Arab Emirates',
      'United Kingdom',
      'United States',
      'Uruguay',
      'Uzbekistan',
      'Vanuatu',
      'Vatican City',
      'Venezuela',
      'Vietnam',
      'Wallis & Futuna',
      'Yemen',
      'Zambia',
      'Zimbabwe'
    ];
  }
  