<navigation-bar background="{{themeMode === 'dark' ? '#111827' : '#FFF'}}"></navigation-bar>
<view wx:if="{{toastText}}" class="page-toast page-toast--{{toastType}} {{themeClass}}">
  {{toastText}}
</view>
<view wx:if="{{activeParamView}}" class="subpage-fixed-header {{activeParamView == 'genericModbus' || activeParamView == 'genericModbusGroup' ? 'subpage-fixed-header--generic' : ''}} {{themeClass}}">
  <view class="subpage-page-header">
    <view wx:if="{{!(isGenericProtocol && activeParamView == 'genericModbus')}}" class="subpage-back" bindtap="backToParamsHome">
      <view class="subpage-back-icon"></view>
    </view>
    <view class="subpage-page-title">
      {{activeParamView == 'driver' ? '驱动器参数' : activeParamView == 'protection' ? '保护' : activeParamView == 'estimator' ? '估算器参数' : activeParamView == 'dq' ? 'DQ轴电流环参数' : activeParamView == 'startup' ? '启动位置管理' : activeParamView == 'speed' ? '速度管理' : activeParamView == 'genericModbus' ? '' : activeParamView == 'genericModbusGroup' ? (activeGenericGroup.name || '寄存器组') : activeParamView == 'status' ? '状态' : ''}}
    </view>
    <view wx:if="{{activeParamView == 'driver'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="readDriverPageParameters">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="writeMotorParameters">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'protection'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="protection" bindtap="onGroupRead">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="protection" bindtap="onGroupWrite">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'estimator'}}" class="panel-actions panel-actions--three subpage-actions">
      <view class="panel-action-button" bindtap="onEstimatorUpdate">更新</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="estimator" bindtap="onGroupRead">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="estimator" bindtap="onGroupWrite">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'dq'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="dq" bindtap="onGroupRead">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" data-group="dq" bindtap="onGroupWrite">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'startup'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="readStartupManagement">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="writeStartupManagement">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'speed'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="readSpeedManagement">读取</view>
      <view class="panel-action-button {{connectedDevice ? '' : 'is-disabled'}}" bindtap="writeSpeedManagement">写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'genericModbus'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button" bindtap="saveGenericModbusJson">保存</view>
      <view class="panel-action-button" bindtap="importGenericModbusJson">加载</view>
      <view class="panel-action-button panel-action-button--icon" bindtap="openGenericModbusDraft">+</view>
    </view>
    <view wx:elif="{{activeParamView == 'genericModbusGroup'}}" class="panel-actions subpage-actions">
      <view
        class="panel-action-button {{connectedDevice && !activeGenericGroup.addressOverflow ? '' : 'is-disabled'}}"
        data-group-id="{{activeGenericGroup.id}}"
        bindtap="readGenericModbusGroup"
      >读取</view>
      <view
        wx:if="{{activeGenericGroup.writable}}"
        class="panel-action-button {{connectedDevice && !activeGenericGroup.addressOverflow ? '' : 'is-disabled'}}"
        data-group-id="{{activeGenericGroup.id}}"
        bindtap="writeGenericModbusGroup"
      >写入</view>
    </view>
    <view wx:elif="{{activeParamView == 'status'}}" class="panel-actions subpage-actions">
      <view class="panel-action-button {{canReadStatus ? '' : 'is-disabled'}}" bindtap="readStatus">读取</view>
    </view>
  </view>
</view>
<scroll-view class="scrollarea {{themeClass}} {{activeParamView ? 'scrollarea--subpage' : ''}} {{activeParamView == 'genericModbus' || activeParamView == 'genericModbusGroup' ? 'scrollarea--generic' : ''}}" scroll-y type="list">
  <view class="page-shell">
    <block wx:if="{{activeParamView == 'driver'}}">
      <view class="panel driver-summary-panel">
        <view class="driver-summary-row driver-summary-row--top">
          <text class="driver-summary-chip">{{chipModel || '--'}}</text>
          <text class="driver-summary-checksum">{{flashChecksum || '--'}}</text>
        </view>
        <view class="driver-summary-row driver-summary-row--model">
          <text class="driver-summary-model">{{motorModel || '--'}}</text>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">硬件参数</view>
        <view wx:for="{{readonlyParamRegisters}}" wx:key="name" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view wx:if="{{!item.hideMeta}}" class="param-meta">{{item.addressDisplay}}</view>
          </view>
          <view class="param-value">{{item.displayValue || '--'}}{{item.unit ? ' ' + item.unit : ''}}</view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">电机参数</view>
        <view wx:for="{{motorParameterInputRegisters}}" wx:key="name" class="param-row input-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input value-input--with-unit"
              type="{{item.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{item.inputValue}}"
              data-index="{{index}}"
              bindinput="onMotorParameterInput"
              bindblur="onMotorParameterBlur"
            />
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'protection'}}">
      <view
        wx:for="{{protectionSections}}"
        wx:for-item="section"
        wx:key="key"
        class="panel protection-section-panel"
      >
        <view class="params-section-title">{{section.title}}</view>
        <view
          wx:for="{{section.rows}}"
          wx:for-item="row"
          wx:key="key"
          class="protection-field-row"
        >
          <view
            wx:for="{{row.fields}}"
            wx:for-item="field"
            wx:key="name"
            class="protection-field protection-field--{{field.kind}}"
          >
            <view class="protection-field-main">
              <view class="param-name">{{field.label}}</view>
              <view class="param-meta {{field.isDirty ? 'param-meta--dirty' : ''}}">{{field.addressDisplay}} {{field.metaValue}}</view>
            </view>
            <switch
              wx:if="{{field.kind == 'switch'}}"
              checked="{{field.value}}"
              color="#0f766e"
              disabled="{{!connectedDevice}}"
              data-index="{{field.sourceIndex}}"
              bindchange="onProtectionSwitchChange"
            />
            <view wx:else class="input-wrap">
              <input
                class="value-input {{field.unit ? 'value-input--with-unit' : ''}}"
                type="{{field.unit ? 'text' : 'digit'}}"
                placeholder="--"
                value="{{field.inputValue}}"
                data-index="{{field.sourceIndex}}"
                data-input-group="protection"
                bindinput="onProtectionInputChange"
                bindblur="onInputBlur"
              />
            </view>
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'estimator'}}">
      <view class="panel params-section-panel">
        <view wx:for="{{estimatorCalculatedDisplayRegisters}}" wx:key="name" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
          </view>
          <view class="param-value">{{item.writeValue || '--'}}{{item.unit ? ' ' + item.unit : ''}}</view>
        </view>
        <view
          wx:for="{{atoBandwidthDisplayRegisters}}"
          wx:for-item="atoItem"
          wx:key="name"
          class="param-row input-row"
        >
          <view class="param-main">
            <view class="param-name">{{atoItem.name}}</view>
            <view class="param-meta {{atoItem.isDirty ? 'param-meta--dirty' : ''}}">KP 0x{{atoItem.kpAddress}} {{atoItem.kpWriteValue || '--'}}  KI 0x{{atoItem.kiAddress}} {{atoItem.kiWriteValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input {{atoItem.unit ? 'value-input--with-unit' : ''}}"
              type="{{atoItem.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{atoItem.inputValue}}"
              data-index="{{atoItem.sourceIndex}}"
              data-input-group="ato"
              bindinput="onAtoBandwidthInput"
              bindblur="onInputBlur"
            />
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'dq'}}">
      <view class="panel params-section-panel">
        <view
          wx:for="{{dqGainDisplayRegisters}}"
          wx:for-item="dqItem"
          wx:key="name"
          class="param-row input-row"
        >
          <view class="param-main">
            <view class="param-name">{{dqItem.name}}</view>
            <view class="param-meta {{dqItem.isDirty ? 'param-meta--dirty' : ''}}">{{dqItem.addressDisplay}} {{dqItem.writeValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input {{dqItem.unit ? 'value-input--with-unit' : ''}}"
              type="{{dqItem.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{dqItem.inputValue}}"
              data-index="{{dqItem.sourceIndex}}"
              data-input-group="dq"
              bindinput="onDqGainInput"
              bindblur="onInputBlur"
            />
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'startup'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title">顺逆风配置</view>
        <view wx:for="{{tailwindControlRegisters}}" wx:key="address" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue}}</view>
          </view>
          <switch
            checked="{{item.value}}"
            color="#0f766e"
            disabled="{{!connectedDevice}}"
            data-index="{{item.sourceIndex}}"
            bindchange="onTailwindSwitchChange"
          />
        </view>
        <view wx:for="{{tailwindCalculatedDisplayRegisters}}" wx:key="name" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
          </view>
          <view class="param-value">{{item.writeValue || '--'}}{{item.unit ? ' ' + item.unit : ''}}</view>
        </view>
        <view
          wx:for="{{tailwindAtoBandwidthDisplayRegisters}}"
          wx:for-item="atoItem"
          wx:key="name"
          class="param-row input-row"
        >
          <view class="param-main">
            <view class="param-name">{{atoItem.name}}</view>
            <view class="param-meta {{atoItem.isDirty ? 'param-meta--dirty' : ''}}">KP 0x{{atoItem.kpAddress}} {{atoItem.kpWriteValue || '--'}}  KI 0x{{atoItem.kiAddress}} {{atoItem.kiWriteValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input {{atoItem.unit ? 'value-input--with-unit' : ''}}"
              type="{{atoItem.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{atoItem.inputValue}}"
              data-index="{{atoItem.sourceIndex}}"
              data-input-group="ato"
              bindinput="onAtoBandwidthInput"
              bindblur="onInputBlur"
            />
          </view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">预定位配置</view>
        <view wx:for="{{prepositionSwitchRegisters}}" wx:key="address" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue}}</view>
          </view>
          <switch
            checked="{{item.value}}"
            color="#0f766e"
            disabled="{{!connectedDevice}}"
            data-index="{{item.sourceIndex}}"
            bindchange="onTailwindSwitchChange"
          />
        </view>
        <view wx:for="{{prepositionParameterDisplayRegisters}}" wx:key="name" class="param-row input-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input {{item.unit ? 'value-input--with-unit' : ''}}"
              type="{{item.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{item.inputValue}}"
              data-index="{{item.sourceIndex}}"
              data-input-group="preposition"
              bindinput="onPrepositionParameterInput"
              bindblur="onInputBlur"
            />
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'speed'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title">速度环路</view>
        <view wx:for="{{speedLoopInputDisplayRegisters}}" wx:key="name">
          <view class="param-row input-row">
            <view class="param-main">
              <view class="param-name">{{item.name}}</view>
              <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
            </view>
            <view class="input-wrap">
              <input
                class="value-input {{item.unit ? 'value-input--with-unit' : ''}}"
                type="{{item.unit ? 'text' : 'digit'}}"
                placeholder="--"
                value="{{item.inputValue}}"
                data-index="{{item.sourceIndex}}"
                data-input-group="parameter"
                bindinput="onInputChange"
                bindblur="onInputBlur"
              />
            </view>
          </view>
        </view>
        <view wx:for="{{speedLoopExtraDisplayRegisters}}" wx:key="name">
          <view class="param-row input-row">
            <view class="param-main">
              <view class="param-name">{{item.name}}</view>
              <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
            </view>
            <view class="input-wrap">
              <input
                class="value-input {{item.unit ? 'value-input--with-unit' : ''}}"
                type="{{item.unit ? 'text' : 'digit'}}"
                placeholder="--"
                value="{{item.inputValue}}"
                data-index="{{item.sourceIndex}}"
                data-input-group="speedLoopExtra"
                bindinput="onSpeedLoopExtraInput"
                bindblur="onInputBlur"
              />
            </view>
          </view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">VSP曲线</view>
        <view wx:for="{{vspCurveRegisters}}" wx:key="name">
          <view class="param-row input-row">
            <view class="param-main">
              <view class="param-name">{{item.name}}</view>
              <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}{{item.actualText ? '  ' + item.actualText : ''}}</view>
            </view>
            <view class="input-wrap">
              <input
                class="value-input {{item.unit ? 'value-input--with-unit' : ''}}"
                type="{{item.unit ? 'text' : 'digit'}}"
                placeholder="--"
                value="{{item.inputValue}}"
                data-index="{{item.sourceIndex}}"
                data-input-group="parameter"
                bindinput="onInputChange"
                bindblur="onInputBlur"
              />
            </view>
          </view>
        </view>
        <view class="param-row">
          <view class="param-main">
            <view class="param-name">{{speedSlopeRegister.name}}</view>
            <view class="param-meta {{speedSlopeRegister.isDirty ? 'param-meta--dirty' : ''}}">{{speedSlopeRegister.addressDisplay}} {{speedSlopeRegister.writeValue || '--'}}</view>
          </view>
          <view class="param-value">{{speedSlopeRegister.writeValue || '--'}}{{speedSlopeRegister.unit ? ' ' + speedSlopeRegister.unit : ''}}</view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">上油参数</view>
        <view wx:for="{{oilParameterInputRegisters}}" wx:key="name" class="param-row input-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta {{item.isDirty ? 'param-meta--dirty' : ''}}">{{item.addressDisplay}} {{item.writeValue || '--'}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input {{item.unit ? 'value-input--with-unit' : ''}}"
              type="{{item.unit ? 'text' : 'digit'}}"
              placeholder="--"
              value="{{item.inputValue}}"
              data-index="{{index}}"
              data-input-group="oil"
              bindinput="onOilParameterInput"
              bindblur="onInputBlur"
            />
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'genericModbus'}}">
      <view wx:if="{{!genericModbusGroups.length && !genericModbusDialog.visible}}" class="empty-state generic-empty-state">
        <view class="empty-title">暂无寄存器组</view>
        <view class="empty-text">点击右上角 + 添加，或从聊天记录导入 JSON</view>
      </view>

      <view
        wx:for="{{genericModbusGroups}}"
        wx:for-item="group"
        wx:key="id"
        class="generic-group-shell {{group.deleteVisible ? 'is-delete-visible' : ''}}"
      >
        <view
          wx:if="{{!group.expanded && group.deleteVisible}}"
          class="generic-delete-action"
          data-group-id="{{group.id}}"
          bindtap="deleteGenericModbusGroup"
        >
          -
        </view>
        <view
          class="panel generic-group-panel {{group.expanded ? '' : 'panel--collapsed'}}"
          data-group-id="{{group.id}}"
          bindtouchstart="onGenericGroupTouchStart"
          bindtouchend="onGenericGroupTouchEnd"
        >
          <view class="panel-header panel-header--with-actions">
            <view
              class="panel-heading-toggle"
              data-group-id="{{group.id}}"
              bindtap="openGenericModbusGroup"
            >
              <view class="panel-icon icon-terminal"></view>
              <view class="generic-group-title-wrap">
                <view class="panel-title" data-group-id="{{group.id}}" catchlongpress="openGenericGroupEdit">{{group.name}}</view>
                <view class="param-meta generic-group-meta">{{group.addressRangeText}} · {{group.quantity}}/{{group.wordQuantity}}{{group.addressWarningText ? ' · ' + group.addressWarningText : ''}}</view>
              </view>
            </view>
            <view class="panel-actions generic-group-actions">
              <view
                class="panel-action-button {{connectedDevice && !group.addressOverflow ? '' : 'is-disabled'}}"
                data-group-id="{{group.id}}"
                bindtap="readGenericModbusGroup"
              >
                读取
              </view>
              <view
                wx:if="{{group.writable}}"
                class="panel-action-button {{connectedDevice && !group.addressOverflow ? '' : 'is-disabled'}}"
                data-group-id="{{group.id}}"
                bindtap="writeGenericModbusGroup"
              >
                写入
              </view>
              <view class="entry-chevron"></view>
            </view>
          </view>

        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'genericModbusGroup'}}">
      <view wx:if="{{activeGenericGroup}}" class="panel generic-group-detail-panel">
        <view class="generic-group-detail-meta">
          {{activeGenericGroup.addressRangeText}} · {{activeGenericGroup.quantity}}/{{activeGenericGroup.wordQuantity}}{{activeGenericGroup.addressWarningText ? ' · ' + activeGenericGroup.addressWarningText : ''}}
        </view>
        <view
          wx:for="{{activeGenericRegisterRows.length ? activeGenericRegisterRows : activeGenericGroup.registers}}"
          wx:for-item="register"
          wx:for-index="registerIndex"
          wx:key="id"
          class="generic-register-row {{register.dragClass}}"
          style="{{register.dragStyle}}"
        >
          <view
            wx:if="{{!activeGenericGroup.isStructLayout}}"
            class="generic-register-drag-handle {{register.dragHandleClass}}"
            data-group-id="{{activeGenericGroup.id}}"
            data-index="{{register.sourceIndex !== undefined ? register.sourceIndex : registerIndex}}"
            catchtouchstart="onGenericRegisterDragStart"
            catchtouchmove="onGenericRegisterDragMove"
            catchtouchend="onGenericRegisterDragEnd"
            catchtouchcancel="onGenericRegisterDragCancel"
          >
            <view class="generic-register-drag-bar"></view>
            <view class="generic-register-drag-bar"></view>
            <view class="generic-register-drag-bar"></view>
          </view>
          <view wx:else class="generic-register-layout-spacer"></view>
          <view class="generic-register-main">
            <view
              class="generic-register-name"
              data-group-id="{{activeGenericGroup.id}}"
              data-index="{{register.sourceIndex !== undefined ? register.sourceIndex : registerIndex}}"
              bindtap="openGenericRegisterInfo"
              catchlongpress="openGenericRegisterEdit"
            >
              {{register.name}}
            </view>
            <view class="generic-register-meta">
              <text>{{register.addressText}} {{register.rawValueText}}</text>
            </view>
          </view>
          <view class="generic-register-input-wrap {{register.showUnit && register.unit ? 'generic-register-input-wrap--unit' : ''}}">
            <block wx:if="{{activeGenericGroup.writable}}">
              <input
                class="value-input generic-register-value {{register.isDirty ? 'value-input--dirty' : ''}}"
                placeholder="--"
                data-group-id="{{activeGenericGroup.id}}"
                data-index="{{register.sourceIndex !== undefined ? register.sourceIndex : registerIndex}}"
                value="{{register.inputValue}}"
                bindinput="onGenericRegisterValueInput"
                bindblur="onGenericRegisterValueBlur"
              />
              <view wx:if="{{register.showUnit && register.unit}}" class="generic-register-unit">{{register.unit}}</view>
            </block>
            <view wx:else class="param-value generic-readonly-value">{{register.displayValue || '--'}}{{register.showUnit && register.unit ? ' ' + register.unit : ''}}</view>
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeParamView == 'status'}}">
      <view wx:for="{{statusRegisterGroups}}" wx:for-item="group" wx:key="key" class="panel params-section-panel">
        <view class="params-section-title">{{group.title}}</view>
        <view wx:for="{{group.registers}}" wx:for-item="item" wx:key="name" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta">{{item.addressDisplay}} {{item.rawValue}}</view>
          </view>
          <view class="param-value">{{item.displayValue}}{{item.displayUnit ? ' ' + item.displayUnit : ''}}</view>
        </view>
      </view>
      <view wx:if="{{userStatusRegisters.length}}" class="panel params-section-panel">
        <view class="params-section-title">用户状态</view>
        <view wx:for="{{userStatusRegisters}}" wx:for-item="item" wx:key="name" class="param-row">
          <view class="param-main">
            <view class="param-name">{{item.name}}</view>
            <view class="param-meta">{{item.addressDisplay}} {{item.rawValue}}</view>
          </view>
          <view class="param-value">{{item.displayValue}}{{item.displayUnit ? ' ' + item.displayUnit : ''}}</view>
        </view>
      </view>
    </block>

    <block wx:else>
      <view class="panel panel--collapsed param-entry-panel" data-view="driver" bindtap="openParamView">
        <view class="panel-header panel-header--with-actions">
          <view class="panel-heading-toggle">
            <view class="panel-icon icon-chip"></view>
            <view class="panel-title">驱动器参数</view>
          </view>
          <view class="entry-chevron"></view>
        </view>
      </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="estimator" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-bars"></view>
          <view class="panel-title">估算器参数</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="dq" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-tune"></view>
          <view class="panel-title">DQ轴电流环参数</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="startup" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-target"></view>
          <view class="panel-title">启动位置管理</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="speed" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-speed"></view>
          <view class="panel-title">速度管理</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="protection" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-shield-check"></view>
          <view class="panel-title">保护</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>

    <view class="panel panel--collapsed param-entry-panel" data-view="status" bindtap="openParamView">
      <view class="panel-header panel-header--with-actions">
        <view class="panel-heading-toggle">
          <view class="panel-icon icon-status"></view>
          <view class="panel-title">状态</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>
    </block>
  </view>
</scroll-view>
<view wx:if="{{genericModbusDialog.visible}}" class="generic-dialog-mask {{themeClass}}" bindtap="closeGenericModbusDraft">
  <view class="generic-dialog" catchtap="noop">
    <view class="generic-dialog-header">
      <view class="generic-dialog-title">{{genericModbusDialog.title}}</view>
      <view class="generic-dialog-close" bindtap="closeGenericModbusDraft">×</view>
    </view>

    <block wx:if="{{genericModbusDialog.mode == 'createGroup' || genericModbusDialog.mode == 'editGroup'}}">
      <view class="generic-dialog-body">
        <view class="generic-config-row">
          <view class="param-main">
            <view class="param-name">寄存器组名</view>
            <view class="param-meta">每组寄存器地址连续</view>
          </view>
          <input
            class="value-input generic-value-input"
            data-field="groupName"
            value="{{genericModbusDialog.groupName}}"
            bindinput="onGenericDraftInput"
          />
        </view>
        <view class="generic-config-row">
          <view class="param-main">
            <view class="param-name">寄存器类型</view>
            <view class="param-meta">决定读取功能码与是否可写</view>
          </view>
          <picker
            mode="selector"
            range="{{genericModbusRegisterTypeOptions}}"
            range-key="label"
            value="{{genericModbusDialog.registerTypeIndex}}"
            bindchange="onGenericDraftTypeChange"
          >
            <view class="generic-picker-value">{{genericModbusDialog.registerTypeText}}</view>
          </picker>
        </view>
        <view class="generic-config-row">
          <view class="param-main">
            <view class="param-name">寄存器起始地址</view>
            <view class="param-meta">16进制，例如 00A0</view>
          </view>
          <input
            class="value-input generic-value-input"
            data-field="startAddress"
            value="{{genericModbusDialog.startAddress}}"
            bindinput="onGenericDraftInput"
          />
        </view>
        <view class="generic-config-row">
          <view class="param-main">
            <view class="param-name">寄存器数量</view>
            <view class="param-meta">{{genericModbusDialog.structParsedSummary || '1 - 256'}}</view>
          </view>
          <input
            class="value-input generic-value-input"
            type="number"
            data-field="quantity"
            value="{{genericModbusDialog.quantity}}"
            bindinput="onGenericDraftInput"
          />
        </view>
        <view wx:if="{{genericModbusDialog.mode == 'createGroup'}}" class="generic-struct-section">
          <view class="generic-struct-header">
            <view class="param-main">
              <view class="param-name">结构体定义</view>
              <view class="param-meta">支持 typedef struct、typedef 别名与数组</view>
            </view>
            <view class="panel-action-button" bindtap="parseGenericStructDefinition">解析</view>
          </view>
          <textarea
            class="generic-struct-input"
            maxlength="-1"
            placeholder="粘贴 C 结构体定义"
            data-field="structDefinition"
            value="{{genericModbusDialog.structDefinition}}"
            bindinput="onGenericDraftInput"
          />
        </view>
      </view>
    </block>

    <block wx:elif="{{genericModbusDialog.mode == 'editRegister' || genericModbusDialog.mode == 'viewRegister'}}">
      <view class="generic-dialog-body">
        <view class="generic-info-stack">
          <view class="generic-info-row">
            <view class="generic-info-label">名称</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.name}}</view>
            <input wx:else class="value-input generic-value-input" data-field="name" value="{{genericModbusDialog.name}}" bindinput="onGenericDraftInput" />
          </view>
          <view class="generic-info-row">
            <view class="generic-info-label">地址</view>
            <view class="generic-info-value">{{genericModbusDialog.addressText}}</view>
          </view>
          <view wx:if="{{genericModbusDialog.showDataType}}" class="generic-info-row">
            <view class="generic-info-label">类型</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.dataTypeText}}</view>
            <picker wx:else mode="selector" range="{{genericModbusDataTypeOptions}}" range-key="label" value="{{genericModbusDialog.dataTypeIndex}}" bindchange="onGenericDialogDataTypeChange">
              <view class="generic-picker-value">{{genericModbusDialog.dataTypeText}}</view>
            </picker>
          </view>
          <view wx:if="{{genericModbusDialog.showTextLength}}" class="generic-info-row">
            <view class="generic-info-label">长度</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.textByteLength || '--'}}B</view>
            <input wx:else class="value-input generic-value-input" type="number" data-field="textByteLength" value="{{genericModbusDialog.textByteLength}}" bindinput="onGenericDraftInput" />
          </view>
          <view class="generic-info-row">
            <view class="generic-info-label">备注</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.remark || '--'}}</view>
            <input wx:else class="value-input generic-value-input" data-field="remark" value="{{genericModbusDialog.remark}}" bindinput="onGenericDraftInput" />
          </view>
          <view wx:if="{{genericModbusDialog.showUnit}}" class="generic-info-row">
            <view class="generic-info-label">单位</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.unit || '--'}}</view>
            <input wx:else class="value-input generic-value-input" data-field="unit" value="{{genericModbusDialog.unit}}" bindinput="onGenericDraftInput" />
          </view>
          <view wx:if="{{genericModbusDialog.mode == 'viewRegister' || genericModbusDialog.showRange}}" class="generic-info-row">
            <view class="generic-info-label">最小值</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.minValue || '--'}}</view>
            <input wx:else class="value-input generic-value-input" data-field="minValue" value="{{genericModbusDialog.minValue}}" bindinput="onGenericDraftInput" />
          </view>
          <view wx:if="{{genericModbusDialog.mode == 'viewRegister' || genericModbusDialog.showRange}}" class="generic-info-row">
            <view class="generic-info-label">最大值</view>
            <view wx:if="{{genericModbusDialog.mode == 'viewRegister'}}" class="generic-info-value">{{genericModbusDialog.maxValue || '--'}}</view>
            <input wx:else class="value-input generic-value-input" data-field="maxValue" value="{{genericModbusDialog.maxValue}}" bindinput="onGenericDraftInput" />
          </view>
        </view>
      </view>
    </block>

    <view class="generic-draft-actions">
      <view class="panel-action-button" bindtap="closeGenericModbusDraft">{{genericModbusDialog.cancelText}}</view>
      <view wx:if="{{genericModbusDialog.confirmText}}" class="panel-action-button is-active" bindtap="confirmGenericModbusDialog">{{genericModbusDialog.confirmText}}</view>
    </view>
  </view>
</view>
