// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';

var ListH$OptolithClient = require("../../Data/ListH.bs.js");
var Maybe$OptolithClient = require("../../Data/Maybe.bs.js");

function flattenSkill(getValueForTargetId, id, dependencies) {
  return Maybe$OptolithClient.mapMaybe((function (dep) {
                var targets = dep.target;
                if (!targets.TAG) {
                  return /* Just */{
                          _0: dep.value
                        };
                }
                var isMatchedByOtherEntry = ListH$OptolithClient.Foldable.any((function (value) {
                        return value >= dep.value;
                      }), ListH$OptolithClient.map(getValueForTargetId, ListH$OptolithClient.$$delete(id, targets._0)));
                if (isMatchedByOtherEntry) {
                  return /* Nothing */0;
                } else {
                  return /* Just */{
                          _0: dep.value
                        };
                }
              }), dependencies);
}

function flattenActivatableSkill(getValueForTargetId, id, dependencies) {
  return Maybe$OptolithClient.mapMaybe((function (dep) {
                var targets = dep.target;
                if (!targets.TAG) {
                  return /* Just */{
                          _0: dep.value
                        };
                }
                var isMatchedByOtherEntry = ListH$OptolithClient.Foldable.any((function (value) {
                        var match = dep.value;
                        if (value) {
                          if (match) {
                            return value._0 >= match._0;
                          } else {
                            return false;
                          }
                        } else if (match) {
                          return false;
                        } else {
                          return true;
                        }
                      }), ListH$OptolithClient.map(getValueForTargetId, ListH$OptolithClient.$$delete(id, targets._0)));
                if (isMatchedByOtherEntry) {
                  return /* Nothing */0;
                } else {
                  return /* Just */{
                          _0: dep.value
                        };
                }
              }), dependencies);
}

exports.flattenSkill = flattenSkill;
exports.flattenActivatableSkill = flattenActivatableSkill;
/* No side effect */
