{{ define "labels/fragments/label" }}
  {{ $d := .def }}
  {{ $v := .val }}
  {{ $withPrefix := .withPrefix }}
  {{ $baseFilterQuery := .baseFilterQuery }}
  {{ $basePath := .basePath }}

  {{ $lhs := printf "%s" $d.Name }}
  {{ $rhs := "" }}

  {{ if not $d.ValueType.IsNull }}
    {{ if $d.ValueType.IsDidFormat }}
      {{ $v = resolve $v }}
    {{ end }}

    {{ if not $withPrefix }}
      {{ $lhs = "" }}
    {{ else }}
      {{ $lhs = printf "%s/" $d.Name }}
    {{ end }}

    {{ $rhs = printf "%s" $v }}
  {{ end }}

  {{ $chipClasses := "w-fit flex items-center gap-2 font-normal normal-case rounded py-1 px-2 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800 hover:bg-gray-100 dark:hover:bg-gray-700 text-inherit text-sm hover:no-underline" }}

  {{ if $basePath }}
    {{ $filterToken := printf "label:%s" $d.Name }}
    {{ if not $d.ValueType.IsNull }}
      {{ $filterToken = printf "%s:%s" $d.Name $v }}
    {{ end }}
    {{ $fullQuery := $filterToken }}
    {{ if ne $baseFilterQuery "" }}
      {{ $fullQuery = printf "%s %s" $baseFilterQuery $filterToken }}
    {{ end }}
    <a href="{{ $basePath }}?q={{ urlquery $fullQuery }}" class="{{ $chipClasses }}">
      {{ template "repo/fragments/colorBall" (dict "color" $d.GetColor) }}
      {{ printf "%s%s" $lhs $rhs }}
    </a>
  {{ else }}
    <span class="{{ $chipClasses }}">
      {{ template "repo/fragments/colorBall" (dict "color" $d.GetColor) }}
      {{ printf "%s%s" $lhs $rhs }}
    </span>
  {{ end }}
{{ end }}


{{ define "labelVal" }}
  {{ $d := .def }}
  {{ $v := .val }}

  {{ if $d.ValueType.IsDidFormat }}
      {{ resolve $v }}
  {{ else }}
    {{ $v }}
  {{ end }}
{{ end }}
