{{define "notifications/fragments/item"}}
  <a href="{{ template "notificationUrl" . }}" class="block no-underline hover:no-underline">
    <div
      class="
        w-full mx-auto rounded drop-shadow-sm dark:text-white bg-white dark:bg-gray-800 px-2 md:px-6 py-4 transition-colors
        {{if not .Read}}bg-blue-50 dark:bg-blue-800/20 border border-blue-500 dark:border-sky-800{{end}}
        flex gap-2 items-center
        ">
      {{ template "notificationIcon" . }}
      <div class="flex-1 w-full flex flex-col gap-1">
        <div>
          <span>{{ template "notificationHeader" . }}</span>
          <span class="text-sm text-gray-500 dark:text-gray-400 before:content-['·'] before:select-none">{{ template "repo/fragments/shortTime" .Created }}</span>
        </div>
        <span class="text-sm text-gray-500 dark:text-gray-400">{{ template "notificationSummary" . }}</span>
      </div>

    </div>
  </a>
{{end}}

{{ define "notificationIcon" }}
  <div class="flex-shrink-0 max-h-full relative">
    <img class="object-cover size-16 rounded-full p-2" src="{{ fullAvatar .ActorDid }}" />
    <div class="absolute border-2 border-white dark:border-gray-800 bg-gray-200 dark:bg-gray-700 bottom-1 right-1 rounded-full p-1 flex items-center justify-center z-10">
      {{ i .Icon "size-3 text-black dark:text-white" }}
    </div>
  </div>
{{ end }}

{{ define "notificationHeader" }}
  {{ $actor := resolve .ActorDid }}

  <span class="text-black dark:text-white w-fit">{{ $actor }}</span>
  {{ if eq .Type "repo_starred" }}
    starred <span class="text-black dark:text-white">{{ resolve .Repo.Did }}/{{ .Repo.Name }}</span>
  {{ else if eq .Type "issue_created" }}
    opened an issue
  {{ else if eq .Type "issue_commented" }}
    commented on an issue
  {{ else if eq .Type "issue_closed" }}
    closed an issue
  {{ else if eq .Type "issue_reopen" }}
    reopened an issue
  {{ else if eq .Type "pull_created" }}
    created a pull request
  {{ else if eq .Type "pull_commented" }}
    commented on a pull request
  {{ else if eq .Type "pull_merged" }}
    merged a pull request
  {{ else if eq .Type "pull_closed" }}
    closed a pull request
  {{ else if eq .Type "pull_reopen" }}
    reopened a pull request
  {{ else if eq .Type "followed" }}
    followed you
  {{ else if eq .Type "user_mentioned" }}
    mentioned you
  {{ else }}
  {{ end }}
{{ end }}

{{ define "notificationSummary" }}
  {{ if eq .Type "repo_starred" }}
    <!-- no summary -->
  {{ else if .Issue }}
    #{{.Issue.IssueId}} {{.Issue.Title}} on {{resolve .Repo.Did}}/{{.Repo.Name}}
  {{ else if .Pull }}
    #{{.Pull.PullId}} {{.Pull.Title}} on {{resolve .Repo.Did}}/{{.Repo.Name}}
  {{ else if eq .Type "followed" }}
    <!-- no summary -->
  {{ else }}
  {{ end }}
{{ end }}

{{ define "notificationUrl" }}
  {{ $url := "" }}
  {{ if eq .Type "repo_starred" }}
    {{$url = printf "/%s/%s" (resolve .Repo.Did) .Repo.Name}}
  {{ else if .Issue }}
    {{$url = printf "/%s/%s/issues/%d" (resolve .Repo.Did) .Repo.Name .Issue.IssueId}}
  {{ else if .Pull }}
    {{$url = printf "/%s/%s/pulls/%d" (resolve .Repo.Did) .Repo.Name .Pull.PullId}}
  {{ else if eq .Type "followed" }}
    {{$url = printf "/%s" (resolve .ActorDid)}}
  {{ else }}
  {{ end }}

  {{ $url }}
{{ end }}
