{% extends "base.html" %}
{% block content %}
<h1>{{ printer.name }}</h1>
<article>
  <h2>Configuration</h2>
  <dl>
    <dt>IP Address</dt><dd>{{ printer.ip_address }}</dd>
    <dt>Port Name</dt><dd>{{ printer.port_name }}</dd>
    <dt>Duplex Mode</dt><dd>{{ printer.duplex_mode }}</dd>
    <dt>Color Mode</dt><dd>{{ "Color" if printer.color_mode else "Grayscale" }}</dd>
    <dt>Paper Size</dt><dd>{{ printer.paper_size }}</dd>
    <dt>Collate</dt><dd>{{ "Yes" if printer.collate else "No" }}</dd>
    <dt>Client</dt><dd>{{ printer.client.name if printer.client_id else "Unassigned" }}</dd>
  </dl>

  <h2>Driver</h2>
  {% if printer.driver_id %}
  <dl>
    <dt>Package</dt><dd>{{ printer.driver.original_filename }}</dd>
    <dt>Driver Name(s)</dt><dd>{{ driver_names | join(", ") }}</dd>
    <dt>Architecture</dt><dd>{{ printer.driver.architecture or "Unknown" }}</dd>
  </dl>
  {% else %}
  <p>No driver assigned</p>
  {% endif %}

  {% if has_driver %}
  <h2>Intune Commands</h2>
  <div x-data="{ copiedInstall: false }">
    <label>Install command</label>
    <code id="install-cmd">{{ install_cmd }}</code>
    <button @click="
      const text = document.getElementById('install-cmd').innerText;
      navigator.clipboard.writeText(text).then(() => { copiedInstall = true; setTimeout(() => copiedInstall = false, 2000) })
      .catch(() => { /* fallback: text is visible for manual copy */ })
    " x-text="copiedInstall ? 'Copied!' : 'Copy'" class="secondary outline"></button>
  </div>
  <div x-data="{ copiedUninstall: false }">
    <label>Uninstall command</label>
    <code id="uninstall-cmd">{{ uninstall_cmd }}</code>
    <button @click="
      const text = document.getElementById('uninstall-cmd').innerText;
      navigator.clipboard.writeText(text).then(() => { copiedUninstall = true; setTimeout(() => copiedUninstall = false, 2000) })
      .catch(() => { /* fallback: text is visible for manual copy */ })
    " x-text="copiedUninstall ? 'Copied!' : 'Copy'" class="secondary outline"></button>
  </div>

  <h2>Scripts</h2>
  <a href="/printers/{{ printer.id }}/scripts/install.ps1" role="button" class="secondary">
    Download Install Script
  </a>
  <a href="/printers/{{ printer.id }}/scripts/uninstall.ps1" role="button" class="secondary">
    Download Uninstall Script
  </a>
  <a href="/printers/{{ printer.id }}/scripts/detect.ps1" role="button" class="secondary">
    Download Detect Script
  </a>

  <h2>Export</h2>
  <a href="/printers/{{ printer.id }}/packages/ninja" role="button">Download NinjaRMM ZIP</a>
  <a href="/printers/{{ printer.id }}/packages/intunewin" role="button">Download .intunewin</a>
  {% endif %}

  <h2>Icon</h2>
  {% if has_icon %}
  <p>Icon uploaded</p>
  {% endif %}
  <form hx-post="/printers/{{ printer.id }}/icon"
        hx-target="#icon-status" hx-swap="innerHTML"
        enctype="multipart/form-data">
    <input type="file" name="file" accept="image/png" required>
    <button type="submit">Upload Icon</button>
  </form>
  <div id="icon-status"></div>

  <a href="/printers" role="button" class="secondary">Back to Printers</a>
</article>
{% endblock %}
