{{ define "title" }}New repository &middot; Tangled{{ end }}

{{ define "content" }}
<div class="grid grid-cols-12">
  <div class="col-span-full md:col-start-3 md:col-span-8 px-6 py-2 mb-4">
    <h1 class="text-xl font-bold dark:text-white mb-1">Create a new repository</h1>
    <p class="text-gray-600 dark:text-gray-400 mb-1">
    Repositories contain a project's files and version history. All
    repositories are publicly accessible.
    </p>
  </div>
  {{ template "newRepoPanel" . }}
</div>
{{ end }}

{{ define "newRepoPanel" }}
  <div class="col-span-full md:col-start-3 md:col-span-8 bg-white dark:bg-gray-800 drop-shadow-sm rounded p-6 md:px-10">
    {{ template "newRepoForm" . }}
  </div>
{{ end }}

{{ define "newRepoForm" }}
  <form hx-post="/repo/new" hx-swap="none" hx-indicator="#spinner">
    {{ template "step-1" . }}
    {{ template "step-2" . }}
    {{ template "step-3" . }}

    <div class="mt-8 flex justify-end">
      <button type="submit" class="btn-create flex items-center gap-2">
        {{ i "book-plus" "w-4 h-4" }}
        Create repository
        <span id="spinner" class="group">
          {{ i "loader-circle" "w-4 h-4 animate-spin hidden group-[.htmx-request]:inline" }}
        </span>
      </button>
    </div>
    <div id="repo" class="error mt-2"></div>

  </form>
{{ end }}

{{ define "step-1" }}
  <div class="flex gap-4 relative border-l border-gray-200 dark:border-gray-700 pl-6">
    <div class="absolute -left-3 -top-0">
      {{ template "numberCircle" 1 }}
    </div>

    <!-- Content column -->
    <div class="flex-1 pb-12">
      <h2 class="text-lg font-medium dark:text-white">General</h2>
      <div class="text-sm text-gray-500 dark:text-gray-400 mb-4">Basic repository information.</div>

      <div class="space-y-2">
        {{ template "name" . }}
        {{ template "description" . }}
      </div>
    </div>
  </div>
{{ end }}

{{ define "step-2" }}
  <div class="flex gap-4 relative border-l border-gray-200 dark:border-gray-700 pl-6">
    <div class="absolute -left-3 -top-0">
      {{ template "numberCircle" 2 }}
    </div>

    <div class="flex-1 pb-12">
      <h2 class="text-lg font-medium dark:text-white">Configuration</h2>
      <div class="text-sm text-gray-500 dark:text-gray-400 mb-4">Repository settings and hosting.</div>

      <div class="space-y-2">
        {{ template "defaultBranch" . }}
        {{ template "knot" . }}
      </div>
    </div>
  </div>
{{ end }}

{{ define "step-3" }}
  <details class="group/advanced">
    <summary class="flex gap-4 items-center relative border-l border-gray-200 dark:border-gray-700 pl-6 cursor-pointer list-none">
      <div class="absolute -left-3 top-1/2 -translate-y-1/2">
        <div class="w-6 h-6 bg-gray-200 dark:bg-gray-600 dark:text-white rounded-full flex items-center justify-center">
          {{ i "plus" "w-4 h-4" }}
        </div>
      </div>

      <div class="flex-1">
        <h2 class="text-lg font-medium dark:text-white">Advanced</h2>
      </div>
    </summary>

    <div class="flex gap-4 relative border-l border-gray-200 dark:border-gray-700 pl-6">
      <div class="flex-1 pt-4">
        <div class="space-y-2">
          {{ template "spindle" . }}
        </div>
      </div>
    </div>
  </details>
{{ end }}

{{ define "name" }}
  <!-- Repository Name with Owner -->
  <div>
    <label class="block text-sm font-bold dark:text-white mb-1">
      Repository name
    </label>
    <div class="flex flex-col md:flex-row md:items-center gap-2 md:gap-0 w-full">
      <div class="shrink-0 hidden md:flex items-center px-2 py-2 gap-1 text-sm text-gray-700 dark:text-gray-300 md:border md:border-r-0 md:border-gray-300 md:dark:border-gray-600 md:rounded-l md:bg-gray-50 md:dark:bg-gray-700">
        {{ template "user/fragments/picHandle" .LoggedInUser.Did }}
      </div>
      <input
        type="text"
        id="name"
        name="name"
        required
        class="flex-1 md:rounded-r md:rounded-l-none py-2"
        placeholder="repository-name"
      />
    </div>
    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
      Choose a unique, descriptive name for your repository. Use letters, numbers, and hyphens.
    </p>
  </div>
{{ end }}

{{ define "description" }}
  <!-- Description -->
  <div>
    <label for="description" class="block text-sm font-bold dark:text-white mb-1">
      Description
    </label>
    <input
      type="text"
      id="description"
      name="description"
      maxlength="140"
      class="w-full py-2"
      placeholder="A brief description of your project..."
    />
    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
      Optional. A short description to help others understand what your project does (max 140 characters).
    </p>
  </div>
{{ end }}

{{ define "defaultBranch" }}
  <!-- Default Branch -->
  <div>
    <label for="branch" class="block text-sm font-bold dark:text-white mb-1">
      Default branch
    </label>
    <input
      type="text"
      id="branch"
      name="branch"
      value="main"
      required
      class="w-full py-2"
    />
    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
      The primary branch where development happens. Common choices are "main" or "master".
    </p>
  </div>
{{ end }}

{{ define "knot" }}
  <!-- Knot Selection -->
  <div>
    <label class="block text-sm font-bold dark:text-white mb-1">
      Select a knot
    </label>
    <div class="w-full space-y-2">
      {{ range .Knots }}
        <div class="flex items-center">
          <input
            type="radio"
            name="domain"
            value="{{ . }}"
            class="mr-2"
            id="domain-{{ . }}"
            required
            {{if eq (len $.Knots) 1}}checked{{end}}
          />
          <label for="domain-{{ . }}" class="dark:text-white lowercase">{{ . }}</label>
        </div>
      {{ else }}
      <p class="dark:text-white">No knots available.</p>
      {{ end }}
    </div>
    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
      A knot hosts repository data and handles Git operations.
      You can also <a href="/settings/knots" class="underline">register your own knot</a>.
    </p>
  </div>
{{ end }}

{{ define "spindle" }}
  <!-- Spindle Selection -->
  <div>
    <label class="block text-sm font-bold dark:text-white mb-1">
      Select a spindle
    </label>
    <div class="w-full space-y-2">
      <div class="flex items-center">
        <input
          type="radio"
          name="spindle"
          value=""
          class="mr-2"
          id="spindle-none"
          checked
        />
        <label for="spindle-none" class="dark:text-white">No spindle</label>
      </div>
      {{ range .Spindles }}
        <div class="flex items-center">
          <input
            type="radio"
            name="spindle"
            value="{{ . }}"
            class="mr-2"
            id="spindle-{{ . }}"
          />
          <label for="spindle-{{ . }}" class="dark:text-white lowercase">{{ . }}</label>
        </div>
      {{ end }}
    </div>
    <p class="text-sm text-gray-500 dark:text-gray-400 mt-1">
      A spindle runs your CI workflows.
      You can also <a href="/settings/spindles" class="underline">register your own spindle</a>.
    </p>
  </div>
{{ end }}

{{ define "numberCircle" }}
  <div class="w-6 h-6 bg-gray-200 dark:bg-gray-600 rounded-full flex items-center justify-center text-sm font-medium">
    {{.}}
  </div>
{{ end }}
