{{$action := .Action}}
{{$result := .Result}}
{{$context := .Context}}
{{$resource := .Resource}}
{{$bulkEdit := .BulkEdit}}

{{define "url" -}}
  {{ if .Action.URL }}
    {{- call .Action.URL .Result .Context -}}
  {{else if (and (not .Multiple) (not .BulkEdit))}}
    {{- join_url (url_for .Result .Resource) .Action.ToParam -}}
  {{else}}
    {{- join_url (url_for .Resource) "!action" .Action.ToParam -}}
  {{ end }}
{{- end}}

{{if (and $action.URL (eq $action.Method "GET"))}}
  {{if (or (eq $action.URLOpenType "bottomsheet") (eq $action.URLOpenType "slideout"))}}
    <a class="{{if ne (print .Mode) "menu_item"}}mdl-button mdl-button--colored mdl-button--raised qor-action-button{{end}} qor-action-button--link" data-url="{{template "url" .}}" data-open-type="{{$action.URLOpenType}}">
      {{t (printf "%v.actions.%v" $resource.ToParam $action.Label) $action.Label}}
    </a>
  {{else}}
    <a class="{{if ne (print .Mode) "menu_item"}}mdl-button mdl-button--colored mdl-button--raised qor-action-button{{end}} qor-action-button--link" href="{{template "url" .}}" {{if $action.URLOpenType}}data-open-type="{{$action.URLOpenType}}"{{end}}>
      {{t (printf "%v.actions.%v" $resource.ToParam $action.Label) $action.Label}}
    </a>
  {{end}}
{{else}}
  <a class="{{if ne (print .Mode) "menu_item"}}mdl-button mdl-button--colored mdl-button--raised {{end -}} qor-action-button" type="button"
    data-url="{{template "url" .}}"
    data-error-no-item="{{t "qor_admin.actions.please_select_an_item" "Please select at least one item"}}"
    {{if $action.URLOpenType}}
      data-open-type="{{$action.URLOpenType}}"
    {{end}}
    {{if not $action.Resource}}
      data-dataType="json"
      data-ajax-form="true"
      data-from-index="{{$bulkEdit}}"
      data-confirm="{{t "qor_admin.form.are_you_sure" "Are you sure?"}}"
      data-confirm-ok="{{t "qor_admin.form.confirm.button.ok" "ok"}}" data-confirm-cancel="{{t "qor_admin.form.confirm.button.cancel" "cancel"}}"
      data-method="{{$action.Method}}"
    {{end}}>
    {{t (printf "%v.actions.%v" $resource.ToParam $action.Label) $action.Label}}
  </a>
{{end}}
