{{define "scene_templates"}}
<div class="card">
  <div class="section-title">
    <div>
      <h2 class="title-with-icon">{{icon "profile"}}<span>场景列表</span></h2>
    </div>
    <div class="actions compact">
      <a class="btn secondary" href="/ui/scene-templates?new=1">{{icon "apply"}}<span>新建场景</span></a>
      {{if .SelectedProfile}}
      <a class="btn secondary" href="/ui/scene-templates?name={{.SelectedProfile}}&edit=1">编辑</a>
      <form method="post" action="/ui/scene-templates/{{.SelectedProfile}}/delete" onsubmit="return confirm('确认删除这个场景吗？');">
        <button class="btn secondary" type="submit">删除</button>
      </form>
      {{end}}
    </div>
  </div>
  <div class="table-wrap">
    <table>
      <thead>
        <tr>
          <th>场景</th>
          <th>识别模板</th>
          <th>调试参数</th>
          <th>视频通道</th>
        </tr>
      </thead>
      <tbody>
        {{range .AssetProfiles}}
        <tr data-nav-row data-nav-href="/ui/scene-templates?name={{.Name}}" {{if eq $.SelectedProfile .Name}}class="selected"{{end}}>
          <td><a class="mono" href="/ui/scene-templates?name={{.Name}}">{{.Name}}</a></td>
          <td>{{if index .Raw "primary_template_name"}}{{index .Raw "primary_template_name"}}{{else if .Instances}}{{(index .Instances 0).Template}}{{else}}-{{end}}</td>
          <td>{{if $.AssetProfileEditor}}{{if and (eq $.AssetProfileEditor.Name .Name) $.AssetProfileEditor.OverlayName}}{{$.AssetProfileEditor.OverlayName}}{{else}}-{{end}}{{else}}-{{end}}</td>
          <td>{{len .Instances}}</td>
        </tr>
        {{else}}
        <tr><td colspan="4"><div class="empty-state compact"><div class="empty-title">还没有场景</div></div></td></tr>
        {{end}}
      </tbody>
    </table>
  </div>
</div>

{{if .AssetProfileEditor}}
{{if .AssetProfileEditing}}<form method="post" action="{{.AssetProfileFormAction}}">{{end}}
<div class="card editor-state {{if .AssetProfileEditing}}editing{{else}}readonly{{end}}">
  <div class="section-title">
    <div>
      <h2 class="title-with-icon">{{icon "profile"}}<span>场景{{if .AssetProfileEditor.Name}} · {{.AssetProfileEditor.Name}}{{end}}</span></h2>
      <div class="form-hint form-state-hint">
        {{if .AssetProfileEditing}}
        <span class="pill run">编辑模式</span>
        <span>当前内容只包含场景级信息，视频通道请到“视频通道”页面维护。</span>
        {{else}}
        <span class="pill">查看模式</span>
        <span>当前内容为只读，点击“编辑”后进入表单模式。</span>
        {{end}}
      </div>
    </div>
    <div class="actions compact">
      {{if .AssetProfileEditing}}
      <button type="submit">{{icon "apply"}}<span>保存场景</span></button>
      <a class="btn secondary" href="/ui/scene-templates{{if .SelectedProfile}}?name={{.SelectedProfile}}{{end}}">{{icon "close"}}<span>取消</span></a>
      {{end}}
      <button type="button" class="btn secondary js-export-json" data-export-url="/ui/scene-templates/{{.AssetProfileEditor.Name}}/export" data-default-filename="{{.AssetProfileEditor.Name}}.json">{{icon "apply"}}<span>导出为 JSON</span></button>
    </div>
  </div>

  {{if .AssetProfileEditing}}
    <div class="field-grid">
      <label><span>场景名称<span class="required-mark">*</span></span><input name="profile_name" value="{{.AssetProfileEditor.Name}}" {{if not .SelectedProfile}}autofocus{{end}} /></label>
      <label><span>识别模板<span class="required-mark">*</span></span>
        <select name="primary_template_name">
          {{range .AssetTemplates}}
          <option value="{{.Name}}" {{if eq $.AssetProfileEditor.PrimaryTemplateName .Name}}selected{{end}}>{{.Name}}</option>
          {{end}}
        </select>
      </label>
      <label><span>业务名称</span><input name="business_name" value="{{.AssetProfileEditor.BusinessName}}" /></label>
    <label>
      <span>调试参数</span>
      <select name="overlay_name">
        <option value="">不使用</option>
        {{range .AssetOverlays}}
        <option value="{{.Name}}" {{if eq $.AssetProfileEditor.OverlayName .Name}}selected{{end}}>{{.Name}}{{if .Description}} - {{.Description}}{{end}}</option>
        {{end}}
      </select>
    </label>
    <label><span>站点名</span><input name="site_name" value="{{.AssetProfileEditor.SiteName}}" /></label>
    <label><span>描述</span><input name="description" value="{{.AssetProfileEditor.Description}}" /></label>
  </div>
  {{else}}
  <div class="detail-sheet">
      <div class="detail-item"><span>场景名称</span><strong class="mono">{{if .AssetProfileEditor.Name}}{{.AssetProfileEditor.Name}}{{else}}-{{end}}</strong></div>
      <div class="detail-item"><span>识别模板</span><strong class="mono">{{if .AssetProfileEditor.PrimaryTemplateName}}{{.AssetProfileEditor.PrimaryTemplateName}}{{else}}-{{end}}</strong></div>
      <div class="detail-item"><span>业务名称</span><strong>{{if .AssetProfileEditor.BusinessName}}{{.AssetProfileEditor.BusinessName}}{{else}}-{{end}}</strong></div>
    <div class="detail-item"><span>调试参数</span><strong>{{if .AssetProfileEditor.OverlayName}}{{.AssetProfileEditor.OverlayName}}{{else}}不使用{{end}}</strong></div>
    <div class="detail-item"><span>站点名</span><strong>{{if .AssetProfileEditor.SiteName}}{{.AssetProfileEditor.SiteName}}{{else}}-{{end}}</strong></div>
    <div class="detail-item"><span>视频通道</span><strong>{{len .AssetProfileEditor.Instances}} 路</strong></div>
    <div class="detail-item full"><span>描述</span><strong>{{if .AssetProfileEditor.Description}}{{.AssetProfileEditor.Description}}{{else}}-{{end}}</strong></div>
  </div>
  {{end}}
</div>
{{if .AssetProfileEditing}}</form>{{end}}
{{end}}
{{end}}
