# frozen_string_literal: true

module RedmineUxToolkit
  module Patches
    module MenuVisibilityPatch
      def menu_items_for(*args)
        unless block_given?
          items = super
          return items unless items.respond_to?(:select)

          return items.select do |node|
            RedmineUxToolkit::Services::NavigationLinks.visible?(node.name)
          end
        end

        super(*args) do |node|
          yield node if RedmineUxToolkit::Services::NavigationLinks.visible?(node.name)
        end
      end
    end
  end
end
