defmodule RefugeWeb.JobsLive.Show do
  use RefugeWeb, :live_view

  @impl true
  def mount(%{"id" => id}, _session, socket) do
    # In a real application, you would fetch the job from a database
    # For now, we'll use hardcoded data
    job = get_job_by_id(String.to_integer(id))
    
    {:ok, assign(socket, :job, job)}
  end

  @impl true
  def render(assigns) do
    ~H"""
    <div class="mx-auto max-w-4xl px-4 py-8">
      <div class="mb-8">
        <a href="/jobs" class="text-indigo-600 hover:text-indigo-900">← Back to jobs</a>
      </div>
      
      <%= if @job do %>
        <div class="bg-white shadow overflow-hidden sm:rounded-lg">
          <div class="px-4 py-5 sm:px-6">
            <h1 class="text-3xl font-bold text-gray-900"><%= @job.title %></h1>
            <h2 class="text-xl text-gray-600 mt-1"><%= @job.name %></h2>
          </div>
          <div class="border-t border-gray-200 px-4 py-5 sm:p-6">
            <h3 class="text-lg font-medium text-gray-900">Job Description</h3>
            <p class="mt-3 text-gray-600"><%= @job.description %></p>
          </div>
          <div class="border-t border-gray-200 px-4 py-5 sm:p-6">
            <h3 class="text-lg font-medium text-gray-900">Application Details</h3>
            <p class="mt-3 text-gray-600">
              To apply for this position, please send your resume and cover letter to 
              <a href="mailto:jobs@example.com" class="text-indigo-600 hover:text-indigo-900">jobs@example.com</a>
              with the subject line "Application for <%= @job.title %> at <%= @job.name %>".
            </p>
          </div>
        </div>
      <% else %>
        <div class="bg-red-50 border-l-4 border-red-400 p-4">
          <div class="flex">
            <div class="ml-3">
              <p class="text-sm text-red-700">
                Job not found. Please go back and select another job.
              </p>
            </div>
          </div>
        </div>
      <% end %>
    </div>
    """
  end

  # Helper function to get job by ID
  # In a real application, this would be a database query
  defp get_job_by_id(id) do
    jobs = [
      %{id: 1, name: "Acme Corp", title: "Software Engineer", description: "Build amazing software with cutting-edge technologies. In this role, you'll work with a team of talented engineers to develop new features and maintain existing systems. Experience with Elixir and Phoenix is a plus."},
      %{id: 2, name: "Globex", title: "Frontend Developer", description: "Create beautiful and responsive user interfaces using modern frontend frameworks. You'll work closely with designers and backend developers to implement pixel-perfect designs with smooth interactions."},
      %{id: 3, name: "Initech", title: "Backend Engineer", description: "Design and build scalable backend systems that power our applications. You'll work on API development, database optimization, and ensuring system reliability under high load."},
      %{id: 4, name: "Umbrella Corp", title: "DevOps Engineer", description: "Manage our cloud infrastructure and deployment pipelines. You'll help maintain our Kubernetes clusters, automate deployments, and ensure high availability of our services."},
      %{id: 5, name: "Stark Industries", title: "AI Researcher", description: "Develop cutting-edge AI solutions for complex problems. You'll work on machine learning models, natural language processing, and computer vision systems that power our innovative products."}
    ]
    
    Enum.find(jobs, fn job -> job.id == id end)
  end
end
