{{define "config_preview"}}
{{template "device_nav" .}}

<div class="card">
  <div class="section-title">
    <div>
      <h2 class="title-with-icon">{{icon "preview"}}<span>设备分配预览</span></h2>
    </div>
  </div>

  <form method="post" action="/ui/devices/{{.Device.DeviceID}}/config-preview">
    <div class="info-list">
      <div><span>设备</span><strong class="mono">{{.Device.DeviceID}}</strong></div>
      <div><span>场景模板</span><strong class="mono">{{if .DeviceAssignment}}{{.DeviceAssignment.ProfileName}}{{else}}-{{end}}</strong></div>
      <div><span>识别单元</span><strong>{{if .DeviceAssignment}}{{.DeviceAssignment.RecognitionCount}} 路{{else}}0 路{{end}}</strong></div>
    </div>

    <div class="actions">
      <button type="submit">生成预览</button>
      <a class="btn ghost" href="/ui/devices/{{.Device.DeviceID}}#device-config">返回设备详情</a>
    </div>
  </form>
</div>

{{if .ConfigPreview}}
<div class="card">
  <div class="section-title">
    <div>
      <h2 class="title-with-icon">{{icon "config"}}<span>预览摘要</span></h2>
    </div>
  </div>
  <div class="info-list">
    <div><span>配置 ID</span><strong class="mono">{{index .ConfigPreview.Metadata "config_id"}}</strong></div>
    <div><span>版本</span><strong class="mono">{{index .ConfigPreview.Metadata "config_version"}}</strong></div>
    <div><span>业务名称</span><strong>{{if index .ConfigPreview.Metadata "business_name"}}{{index .ConfigPreview.Metadata "business_name"}}{{else}}-{{end}}</strong></div>
    <div><span>模板</span><strong>{{index .ConfigPreview.Metadata "template"}}</strong></div>
    <div><span>场景模板</span><strong>{{index .ConfigPreview.Metadata "profile"}}</strong></div>
    <div><span>调试参数</span><strong class="mono">{{if index .ConfigPreview.Metadata "overlays"}}{{range $i, $name := index .ConfigPreview.Metadata "overlays"}}{{if $i}}, {{end}}{{$name}}{{end}}{{else}}-{{end}}</strong></div>
    <div><span>大小</span><strong class="mono">{{.ConfigPreview.Size}} bytes</strong></div>
    <div class="full"><span>SHA256</span><strong class="mono">{{.ConfigPreview.Sha256}}</strong></div>
  </div>
</div>

<details class="card collapsible" {{if not .RawText}}open{{end}}>
  <summary class="title-with-icon">{{icon "tech"}}<span>完整 JSON</span></summary>
  <pre>{{.ConfigPreview.JSON}}</pre>
</details>
{{end}}

{{if .RawText}}
<div class="card">
  <h2>{{if .ResultTitle}}{{.ResultTitle}}{{else}}执行结果{{end}}</h2>
  <pre>{{.RawText}}</pre>
</div>
{{end}}
{{end}}
