{{!-- Hire a Developer Page --}}
<!DOCTYPE html>
<html lang="en">
<head>
  {{> partials/head title=title}}
</head>
<body class="bg-gray-50">
  {{> partials/header user=user}}

  <main class="max-w-7xl mx-auto px-4 py-8">
    <!-- Page Header -->
    <div class="text-center mb-8">
      <h1 class="text-4xl font-bold text-gray-900 mb-4">Hire a Developer</h1>
      <p class="text-xl text-gray-600 max-w-2xl mx-auto">
        Find skilled developers for your next project. Browse our marketplace of verified professionals.
      </p>
    </div>

    <!-- Filters -->
    <div class="bg-white rounded-lg shadow-sm p-6 mb-8">
      <form action="/hire-developer" method="GET" class="grid grid-cols-1 md:grid-cols-5 gap-4">
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">Category</label>
          <select name="category" class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
            <option value="">All Categories</option>
            {{#each categories}}
            <option value="{{value}}" {{#if (eq value ../filters.category)}}selected{{/if}}>{{label}}</option>
            {{/each}}
          </select>
        </div>
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">Skills</label>
          <input type="text" name="skills" value="{{filters.skills}}" placeholder="e.g., React, Node.js"
            class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
        </div>
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">Min Rate ($/hr)</label>
          <input type="number" name="minRate" value="{{filters.minRate}}" placeholder="0"
            class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
        </div>
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">Max Rate ($/hr)</label>
          <input type="number" name="maxRate" value="{{filters.maxRate}}" placeholder="500"
            class="w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
        </div>
        <div class="flex items-end">
          <button type="submit" class="w-full bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition">
            Search
          </button>
        </div>
      </form>
    </div>

    <!-- Search Bar -->
    <div class="mb-6">
      <form action="/hire-developer" method="GET" class="flex gap-2">
        <input type="text" name="search" value="{{filters.search}}" placeholder="Search developers..."
          class="flex-1 rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
        <button type="submit" class="bg-gray-800 text-white py-2 px-6 rounded-md hover:bg-gray-900 transition">
          Search
        </button>
      </form>
    </div>

    <!-- Developers Grid -->
    {{#if developers.length}}
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
      {{#each developers}}
      <div class="bg-white rounded-lg shadow-sm overflow-hidden hover:shadow-md transition">
        <div class="p-6">
          <div class="flex items-start gap-4">
            <img src="{{#if profileImage}}{{profileImage}}{{else}}/images/default-avatar.png{{/if}}" 
              alt="{{displayName}}" class="w-16 h-16 rounded-full object-cover">
            <div class="flex-1">
              <h3 class="font-semibold text-lg text-gray-900">{{displayName}}</h3>
              <p class="text-sm text-gray-500">{{headline}}</p>
              <div class="flex items-center gap-1 mt-1">
                <span class="text-yellow-400">★</span>
                <span class="text-sm font-medium">{{rating}}</span>
                <span class="text-sm text-gray-400">({{reviewCount}} reviews)</span>
              </div>
            </div>
          </div>
          <div class="mt-4">
            <div class="flex flex-wrap gap-2 mb-3">
              {{#each skills}}
              {{#if (lt @index 4)}}
              <span class="px-2 py-1 bg-blue-100 text-blue-800 text-xs rounded-full">{{this}}</span>
              {{/if}}
              {{/each}}
            </div>
            <div class="flex items-center justify-between text-sm">
              <span class="text-gray-600">{{yearsOfExperience}} years exp.</span>
              <span class="font-semibold text-green-600">${{hourlyRate}}/hr</span>
            </div>
          </div>
          <div class="mt-4 flex gap-2">
            <a href="/developer/{{slug}}" class="flex-1 text-center bg-blue-600 text-white py-2 px-4 rounded-md hover:bg-blue-700 transition">
              View Profile
            </a>
          </div>
        </div>
      </div>
      {{/each}}
    </div>

    <!-- Pagination -->
    {{#if (gt pagination.pages 1)}}
    <div class="flex justify-center gap-2">
      {{#if (gt pagination.page 1)}}
      <a href="?page={{subtract pagination.page 1}}" class="px-4 py-2 bg-white border rounded-md hover:bg-gray-50">Previous</a>
      {{/if}}
      <span class="px-4 py-2 bg-blue-600 text-white rounded-md">{{pagination.page}} / {{pagination.pages}}</span>
      {{#if (lt pagination.page pagination.pages)}}
      <a href="?page={{add pagination.page 1}}" class="px-4 py-2 bg-white border rounded-md hover:bg-gray-50">Next</a>
      {{/if}}
    </div>
    {{/if}}
    {{else}}
    <div class="text-center py-12 bg-white rounded-lg">
      <p class="text-gray-500 text-lg">No developers found matching your criteria.</p>
      <a href="/hire-developer" class="mt-4 inline-block text-blue-600 hover:underline">Clear filters</a>
    </div>
    {{/if}}
  </main>

  {{> partials/footer}}
</body>
</html>

