# frozen_string_literal: true

module RedmineUxToolkit
  module Patches
    module IssuesHelperPatch
      def issue_heading(issue)
        heading = super
        return heading unless ux_toolkit_show_badges_in_issue_heading?(issue)

        badges = ux_toolkit_issue_badges(issue)
        return heading if badges.blank?

        safe_join([heading, content_tag(:span, badges, class: 'ux-toolkit-issue-heading-badges')], ' ')
      end

      private

      def ux_toolkit_show_badges_in_issue_heading?(issue)
        issue.present? && defined?(@issue) && @issue == issue && respond_to?(:ux_toolkit_issue_badges)
      end
    end
  end
end
