variable "wait_on" {
  type        = any
  description = "Resources to wait on"
  default     = true
}

variable "server_ip" {
  type = string
}

variable "ssh_private_key_path" {
  type = string
}

variable "server_domain" {
  type = string
}

module "web" {
  source = "../../quadlet-app"
  wait_on = var.wait_on

  server_ip            = var.server_ip
  ssh_private_key_path = var.ssh_private_key_path

  restart_policy = "never"

  app_name = "plane-web"
  image    = "docker.io/makeplane/plane-frontend:v1.0.0"
  ports    = ["3014:3000"]
  environment = {
    # API settings
    NEXT_PUBLIC_API_BASE_URL = "https://plane.${var.server_domain}/api"
    
    # Web settings
    NEXT_PUBLIC_WEB_BASE_URL = "https://plane.${var.server_domain}"

    NEXT_PUBLIC_ADMIN_BASE_URL = "https://plane.${var.server_domain}/god-mode"
    NEXT_PUBLIC_SPACE_BASE_URL = "https://plane.${var.server_domain}/spaces"
    NEXT_PUBLIC_LIVE_BASE_URL = "https://plane.${var.server_domain}/live"
    
    # Environment
    NODE_ENV = "production"
  }

  haproxy_services = [
    {
      name   = "plane-web"
      domain = "plane.${var.server_domain}"
      port   = "3014"
      host   = "127.0.0.1"
      tls    = false
    }
  ]
}

output "app_urls" {
  value = module.web.app_urls
}

output "installed" {
  value = true
  depends_on = [module.web.installed]
}