# frozen_string_literal: true

module SuccessCriteriaHelper
  def success_criterion_result_icon_classes(sc)
    if sc.passed?
      "bi bi-check text-success"
    elsif sc.failed?
      "bi bi-exclamation-lg text-danger"
    elsif sc.not_applicable?
      "bi bi-dash text-muted"
    else
      "bi bi-question text-warning"
    end
  end

  def success_criterion_result_color_classes(sc)
    if sc.passed?
      "success"
    elsif sc.failed?
      "danger"
    elsif sc.not_applicable?
      "muted"
    else
      "warning"
    end
  end

  def success_criterion_menu(success_criterion, show_mode = true)
     dropdown_menu([
       { text: "Bearbeiten",
         icon: "pencil",
         href: edit_success_criterion_path(success_criterion),
         turbo_frame: "modal",
         color: "body" },
       { text: "Löschen",
         icon: "trash",
         href: success_criterion_path(success_criterion),
         color: :danger,
         method: :delete,
         confirm: "Bist du sicher?" } ],
       klass: "mt-3 ms-auto")
  end

  def success_criterion_edit_button(success_criterion,  edit_mode)
    path = if success_criterion.persisted?
             if edit_mode
               success_criterion
             else
               [ :edit,
                success_criterion ]
             end
    else
             success_criterion.element
    end
    link_to tag.i(class: "bi bi-pencil") + " Bearbeiten".html_safe,
            path,
            class: "text-decoration-none xbtn xbtn-#{edit_mode ? 'link text-warning' : 'link text-body'}"
  end

  def success_criterion_badge(content, extra_classes: "")
    tag.span(content, class: "badge #{extra_classes}")
  end
end
