<commit_before>part of couclient;

class UseWindow extends Modal {
	static Map<String, UseWindow> instances = {};
	String id = 'useWindow' + WindowManager.randomId.toString();
	String itemType, itemName;
	String listUrl;
	List<Map> recipeList;
	Element well;
	bool makingCancelled;

	factory UseWindow(String itemType, String itemName) {
		if (instances[itemType] == null) {
			instances[itemType] = new UseWindow._(itemType, itemName);
		} else {
			instances[itemType].open();
		}
		return instances[itemType];
	}

	UseWindow._(this.itemType, this.itemName) {
		load().then((Element el) {
			querySelector("#windowHolder").append(el);
			prepare();
			open(refresh: false);
		});
	}

	Future<Element> load() async {
		await updateRecipes();

		// Header

		Element closeButton = new Element.tag("i")
			..classes.add("fa-li")
			..classes.add("fa")
			..classes.add("fa-times")
			..classes.add("close");

		Element icon = new Element.tag("i")
			..classes.add("fa-li")
			..classes.add("fa")
			..classes.add("fa-bars");

		SpanElement titleSpan = new SpanElement()
			..text = "Using a $itemName";

		Element header = new Element.header()
			..append(icon)..append(titleSpan);

		// Container

		well = new Element.tag("ur-well")
			..classes.add("useitem-well");

		DivElement window = new DivElement()
			..id = id
			..classes.add("window")
			..classes.add("useWindow")
			..append(closeButton)..append(header)..append(well);

		return (window);
	}

	Future<Element> listRecipes([bool clearWell = true]) async {
		if (clearWell) {
			well
				..children.clear()
				..classes.remove("col3");
		}

		DivElement recipeContainer = new DivElement()
			..classes.add("useitem-recipes")
			..hidden = false;

		if (recipeList.length > 0) {
			recipeList.forEach((Map recipe) {
				List<int> itemMax = [];

				//decide if we can make this recipe
				recipe['input'].forEach((Map itemMap) {
					int userHas = util.getNumItems(itemMap['itemType']);
					itemMap['userHas'] = userHas;

					int qty = itemMap['qtyReq'];
					if (userHas >= qty) {
						itemMax.add((userHas / qty).floor());
					} else {
						itemMax.add(0);
					}

					itemMax.sort();

					if (itemMax.length > 0) {
						recipe["canMake"] = itemMax.first;
					} else {
						recipe["canMake"] = 0;
					}
				});

				DivElement image = new DivElement()
					..classes.add("useitem-recipe-image")
					..style.backgroundImage = "url(${recipe["output_map"]["iconUrl"]})";

				DivElement info = new DivElement()
					..classes.add("useitem-recipe-text")
					..text = recipe["output_map"]["recipeName"] ?? recipe['output_map']['name'];

				DivElement recipeBtn = new DivElement()
					..classes.addAll(["useitem-recipe", "white-btn"])
					..append(image)..append(info)
					..onClick.listen((_) => openRecipe(recipe["id"]));

				if (recipe["canMake"] == 0) {<commit_msg>mark repair recipes in tinkertool (fixes https://github.com/ChildrenOfUr/cou-issues/issues/1492)<commit_after>part of couclient;

class UseWindow extends Modal {
	static Map<String, UseWindow> instances = {};
	String id = 'useWindow' + WindowManager.randomId.toString();
	String itemType, itemName;
	String listUrl;
	List<Map> recipeList;
	Element well;
	bool makingCancelled;

	factory UseWindow(String itemType, String itemName) {
		if (instances[itemType] == null) {
			instances[itemType] = new UseWindow._(itemType, itemName);
		} else {
			instances[itemType].open();
		}
		return instances[itemType];
	}

	UseWindow._(this.itemType, this.itemName) {
		load().then((Element el) {
			querySelector("#windowHolder").append(el);
			prepare();
			open(refresh: false);
		});
	}

	Future<Element> load() async {
		await updateRecipes();

		// Header

		Element closeButton = new Element.tag("i")
			..classes.add("fa-li")
			..classes.add("fa")
			..classes.add("fa-times")
			..classes.add("close");

		Element icon = new Element.tag("i")
			..classes.add("fa-li")
			..classes.add("fa")
			..classes.add("fa-bars");

		SpanElement titleSpan = new SpanElement()
			..text = "Using a $itemName";

		Element header = new Element.header()
			..append(icon)..append(titleSpan);

		// Container

		well = new Element.tag("ur-well")
			..classes.add("useitem-well");

		DivElement window = new DivElement()
			..id = id
			..classes.add("window")
			..classes.add("useWindow")
			..append(closeButton)..append(header)..append(well);

		return (window);
	}

	Future<Element> listRecipes([bool clearWell = true]) async {
		if (clearWell) {
			well
				..children.clear()
				..classes.remove("col3");
		}

		DivElement recipeContainer = new DivElement()
			..classes.add("useitem-recipes")
			..hidden = false;

		if (recipeList.length > 0) {
			recipeList.forEach((Map recipe) {
				List<int> itemMax = [];

				List<String> inputTypes = [];

				//decide if we can make this recipe
				recipe['input'].forEach((Map itemMap) {
					inputTypes.add(itemMap['itemType']);

					int userHas = util.getNumItems(itemMap['itemType']);
					itemMap['userHas'] = userHas;

					int qty = itemMap['qtyReq'];
					if (userHas >= qty) {
						itemMax.add((userHas / qty).floor());
					} else {
						itemMax.add(0);
					}

					itemMax.sort();

					if (itemMax.length > 0) {
						recipe["canMake"] = itemMax.first;
					} else {
						recipe["canMake"] = 0;
					}
				});

				DivElement image = new DivElement()
					..classes.add("useitem-recipe-image")
					..style.backgroundImage = "url(${recipe["output_map"]["iconUrl"]})";

				String displayName = recipe["output_map"]["recipeName"] ?? recipe['output_map']['name'];
				if (inputTypes.contains(recipe['output_map']['itemType'])) {
					// Consumes itself
					displayName += ' (Repair)';
				}

				DivElement info = new DivElement()
					..classes.add("useitem-recipe-text")
					..text = displayName;

				DivElement recipeBtn = new DivElement()
					..classes.addAll(["useitem-recipe", "white-btn"])
					..append(image)..append(info)
					..onClick.listen((_) => openRecipe(recipe["id"]));

				if (recipe["canMake"] == 0) {
{'fraction_non_alphanumeric': 0.17591362126245846, 'fraction_numerical': 0.0026578073089701, 'mean_word_length': 3.29151817533856, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636028', 'n_tokens_mistral': 2422, 'n_tokens_neox': 1982, 'n_words': 386}