import 'dart:async';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart';
import 'package:wallpaperx/common/components/easy_loading.dart';
import 'package:wallpaperx/common/utils/shared_util.dart';

class AiManagerController extends GetxController with WidgetsBindingObserver {
  RxList labelSettingList = <String>[].obs;

  RxList aiLabelOptions = <String>[
    "Realistic Photography",
    "Portrait Photography",
    "Animal Photography",
    "Landscape",
    "Product Photography",
    "Architectural Photography",
    "Fashion Photography",
    "Other Photography",
    "Products",
    "Crafts",
    "Toys and Figures",
    "Automotive and Transportation",
    "Other Functional Models",
    "Plants",
    "Animals",
    "Food",
    "World Landscapes",
    "Landscape Design",
    "Nature Photography",
    "Other Niches",
    "Themes",
    "Styles",
    "Style Filters",
    "Abstract Flat",
    "Realistic",
    "Handcrafted Style",
    "Subject",
    "Enhanced Subject",
    "Flat Illustration",
    "Enhanced Characters",
    "Fashion and Makeup",
    "Fashion",
    "Male",
    "Female",
    "Anime and Games",
    "Anime Characters",
    "Anime Scenes",
    "2D",
    "Character Design",
    "IP Characters",
    "IP Character Design",
    "Game Design",
    "Other Game Designs",
    "Mecha",
    "Fantasy",
    "Anime Art Style",
    "Other Anime and Games",
    "Brand and Visual Design",
    "Other Brand and Visual Design",
    "Poster Design",
    "Icon and Prop Design",
    "Logo Icons",
    "Logo and Icon Design",
    "Illustration",
    "Flat Illustration",
    "Abstract Flat",
    "3D Illustration",
    "3D Stereoscopic",
    "Illustration",
    "Children's Illustration",
    "Artistic Illustration",
    "Style Filters",
    "Classic Painting Style",
    "Enhanced Painting Style",
    "Hand-Drawn Style",
    "Other Illustrations",
    "Other Styles",
    "Other Visual Designs",
    "Architectural Design",
    "Buildings",
    "Space Design",
    "Space Scenes",
    "Landscape Design",
    "Scene Design",
    "Other Architecture and Space Design",
    "Other Space Designs",
    "Other Architecture and Space Designs",
    "Photography",
  ].obs;

  Timer? _timer;

  @override
  void onInit() {
    super.onInit();
    labelSettingList.addAll(
      UPCache.getInstance().getStringList("labelSettingList"),
    );
  }

  @override
  void onClose() {
    super.onClose();
    _stopTimer();
  }

  putAiLabel(label, {String? type, String? addValue}) {
    if (labelSettingList.contains(label)) {
      return;
    } else {
      labelSettingList.add(label);
    }
  }

  deleteAiLabel(label, {String? type, String? removeValue}) {
    labelSettingList.remove(label);
  }

  resetAiConfig({String? setType, String? setValue}) {
    loading(show: true);
    _timer = Timer.periodic(const Duration(seconds: 1), (Timer t) {
      dismiss(dismiss: true);
      UPCache.getInstance().setData("labelSettingList", labelSettingList);
      _stopTimer();
    });
  }

  /// 停止定时器
  void _stopTimer() {
    _timer?.cancel();
    _timer = null;
  }
}
