{{ define "title" }}{{ .String.Filename }} · by {{ resolve .Owner.DID.String }}{{ end }}

{{ define "extrameta" }}
  {{ $ownerId := resolve .Owner.DID.String }}
  <meta property="og:title" content="{{ .String.Filename }} · by {{ $ownerId }}" />
  <meta property="og:type" content="object" />
  <meta property="og:url" content="https://tangled.org/strings/{{ $ownerId }}/{{ .String.Rkey }}" />
  <meta property="og:description" content="{{ .String.Description }}" />
{{ end }}

{{ define "content" }}
{{ $ownerId := resolve .Owner.DID.String }}
  <section id="string-header" class="mb-2 py-2 px-4 dark:text-white">
    <div class="text-lg flex flex-col sm:flex-row items-start gap-4 justify-between">
      <!-- left items -->
      <div class="flex flex-col gap-2">
        <!-- string owner / string name -->
        <div class="flex items-center gap-2 flex-wrap">
          {{ template "user/fragments/picHandleLink" .Owner.DID.String }}
          <span class="select-none">/</span>
          <a href="/strings/{{ $ownerId }}/{{ .String.Rkey }}" class="font-bold">{{ .String.Filename }}</a>
        </div>

        <span class="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm text-gray-600 dark:text-gray-300">
          {{ if .String.Description }}
            {{ .String.Description }}
          {{ else }}
            <span class="italic">this string has no description</span>
          {{ end }}
        </span>
      </div>

      <div class="w-full sm:w-fit grid grid-cols-3 gap-2 z-auto">
        {{ if and .LoggedInUser (eq .LoggedInUser.Did .String.Did) }}
          <a class="btn text-sm no-underline hover:no-underline flex items-center gap-2 group"
             hx-boost="true"
             href="/strings/{{ .String.Did }}/{{ .String.Rkey }}/edit">
            {{ i "pencil" "w-4 h-4" }}
            <span class="hidden md:inline">edit</span>
            {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
          </a>
          <button
            class="btn text-sm text-red-500 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300 flex items-center gap-2 group"
            title="Delete string"
            hx-delete="/strings/{{ .String.Did }}/{{ .String.Rkey }}/"
            hx-swap="none"
            hx-confirm="Are you sure you want to delete the string `{{ .String.Filename }}`?"
          >
            {{ i "trash-2" "w-4 h-4" }}
            <span class="hidden md:inline">delete</span>
            {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
          </button>
        {{ end }}
        {{ template "fragments/starBtn"
          (dict "SubjectAt" .String.AtUri
                "IsStarred" .IsStarred
                "StarCount" .StarCount) }}
      </div>
    </div>
  </section>
  <section class="bg-white dark:bg-gray-800 px-6 py-4 rounded relative w-full dark:text-white">
    <div class="flex flex-col md:flex-row md:justify-between md:items-center text-gray-500 dark:text-gray-400 text-sm md:text-base pb-2 mb-3 text-base border-b border-gray-200 dark:border-gray-700">
      <span>
        {{ .String.Filename }}
        <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
        <span>
          {{ with .String.Edited }}
            edited {{ template "repo/fragments/shortTimeAgo" . }}
          {{ else }}
            {{ template "repo/fragments/shortTimeAgo" .String.Created }}
          {{ end }}
        </span>
      </span>
      <div>
        <span>{{ .Stats.LineCount }} lines</span>
        <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
        <span>{{ byteFmt .Stats.ByteCount }}</span>
        <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
        <a href="/strings/{{ $ownerId }}/{{ .String.Rkey }}/raw">view raw</a>
        {{ if .RenderToggle }}
        <span class="select-none px-1 md:px-2 [&:before]:content-['·']"></span>
        <a href="?code={{ .ShowRendered }}" hx-boost="true">
          view {{ if .ShowRendered }}code{{ else }}rendered{{ end }}
        </a>
        {{ end }}
      </div>
    </div>
    <div class="overflow-x-auto overflow-y-hidden relative">
      {{ if .ShowRendered }}
        <div id="blob-contents" class="prose dark:prose-invert">{{ .String.Contents | readme }}</div>
      {{ else }}
        <div id="blob-contents" class="whitespace-pre peer-target:bg-yellow-200 dark:peer-target:bg-yellow-900">{{ code .String.Contents .String.Filename | escapeHtml }}</div>
      {{ end }}
    </div>
    {{ template "fragments/multiline-select" }}
  </section>
{{ end }}
