<div class="max-w-7xl mx-auto p-6 space-y-10">

  <!-- Title -->
  <div class="flex justify-between items-center">
    <h2 class="text-2xl font-bold text-gray-800">📁 Your Portfolios</h2>
  </div>

  <!-- Portfolios list -->
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
    @for (p of portfolios; track p.id) {
      <div class="border border-gray-200 rounded-2xl p-4 shadow-sm hover:shadow-md transition">

        <div class="flex items-center justify-between mb-2">
          <h3 class="text-lg font-semibold text-gray-700 truncate">{{ p.name }}</h3>
          <span class="text-xs px-2 py-1 rounded-full"
                [ngClass]="!p.active ? 'bg-red-100 text-red-600' :
                               p.path ? 'bg-green-100 text-green-600' :
                               'bg-yellow-100 text-yellow-600'">
                {{ !p.active ? 'Pending Payment' : (p.path ? 'Uploaded' : 'Pending Upload') }}
          </span>
        </div>

        <a href="https://{{ p.domain }}" class=" text-sm text-gray-500 break-words mb-4">{{ p.domain }}</a>

        <div class="flex flex-col md:flex-row items-center justify-between gap-4 mt-4">

          <!-- File Input -->
          <input
            type="file"
            (change)="uploadZip($event, p.id)"
            class="text-sm text-gray-500 file:mr-4 file:py-2 file:px-4
                  file:rounded-full file:border-0
                  file:text-sm file:font-semibold
                  file:bg-blue-50 file:text-blue-700
                  hover:file:bg-blue-100"
          />

          <!-- Deploy Button (conditional) -->
          @if (p.path) {
            <button
              (click)="deploy(p.id)"
              class="inline-flex items-center justify-center rounded-2xl px-3 py-2 text-sm font-medium
                    text-white bg-gradient-to-r from-blue-600 to-blue-500 shadow hover:shadow-md
                    transition-all duration-200 hover:from-blue-700 hover:to-blue-600"
            >
              🚀 Deploy
            </button>
          }
        </div>

        <!-- Uploading Status -->
        @if (uploading[p.id]) {
          <p class="text-blue-500 text-sm mt-2 text-center w-full">Uploading...</p>
        }
      </div>
    }
  </div>

  <!-- Divider -->
  <hr class="border-gray-200"/>

  <!-- Create Portfolio -->
  <div class="space-y-4">
    <h3 class="text-xl font-semibold text-gray-800">➕ Create New Portfolio</h3>

    <form (submit)="create(); $event.preventDefault()" class="space-y-4">
      <div>
        <label class="block text-sm font-medium text-gray-700">Name</label>
        <input
          [(ngModel)]="newPortfolio.name"
          class="mt-3 p-2 block w-full rounded-xl border-gray-300 shadow-sm focus:ring-blue-500 focus:border-blue-500"
          name="name"
          required
          type="text"
        />
      </div>

      <div>
        <label class="block text-sm font-medium text-gray-700">Subdomain</label>
        <input
          [(ngModel)]="newPortfolio.domain"
          class="mt-3 p-3 block w-full rounded-xl border-gray-300 shadow-sm focus:ring-blue-500 focus:border-blue-500"
          name="domain"
          placeholder="e.g. mysite.portfolio-host.com"
          required
          type="text"
        />
      </div>

      <button
        class="bg-blue-600 hover:bg-blue-700 text-white font-semibold px-6 py-2 rounded-xl transition"
        type="submit"
      >
        Create Portfolio
      </button>
    </form>
  </div>
</div>
