<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="{{activeSettingsView}}" class="subpage-fixed-header {{themeClass}}">
  <view class="subpage-page-header">
    <view class="subpage-back" bindtap="backToSettingsHome">
      <view class="subpage-back-icon"></view>
    </view>
    <view class="subpage-page-title">{{activeSettingsTitle}}</view>
  </view>
</view>
<scroll-view class="scrollarea {{themeClass}} {{activeSettingsView ? 'scrollarea--subpage' : ''}}" scroll-y type="list">
  <view class="page-shell">
    <block wx:if="{{activeSettingsView}}">
    <block wx:if="{{activeSettingsView == 'bootloader'}}">
      <view class="panel params-section-panel upgrade-panel">
        <view class="panel-header panel-header--with-actions">
          <view class="panel-icon icon-chip">
            <image class="panel-icon-image" src="/assets/icons/chip-white.png" mode="aspectFit" />
          </view>
          <view class="panel-title">BootLoader</view>
          <view class="panel-actions upgrade-actions">
            <view
              class="panel-action-button {{isBootloaderBusy ? 'is-disabled' : ''}}"
              bindtap="chooseFirmwareFile"
            >
              加载
            </view>
            <view
              class="panel-action-button {{connectedDevice && !isBootloaderBusy ? '' : 'is-disabled'}}"
              bindtap="handshakeBootloader"
            >
              握手
            </view>
            <view
              class="panel-action-button {{connectedDevice && !isBootloaderBusy ? '' : 'is-disabled'}}"
              bindtap="readProgramChecksum"
            >
              读取
            </view>
            <view
              class="panel-action-button {{connectedDevice && !isBootloaderBusy ? '' : 'is-disabled'}}"
              bindtap="exitBootloader"
            >
              退出
            </view>
            <view
              class="panel-action-button {{connectedDevice && isFirmwareReady && !isBootloaderBusy ? '' : 'is-disabled'}}"
              bindtap="startFirmwareUpgrade"
            >
              升级
            </view>
          </view>
        </view>
        <view class="upgrade-body">
          <view class="upgrade-row">
            <text class="upgrade-label">芯片型号</text>
            <text class="upgrade-value">{{chipModel}}</text>
          </view>
          <view class="upgrade-row upgrade-row--file">
            <view class="upgrade-file-head">
              <text class="upgrade-label">固件文件</text>
              <view class="upgrade-file-meta">
                <text class="upgrade-file-meta-item upgrade-file-meta-item--program">{{deviceProgramCrcText}}</text>
                <text class="upgrade-file-meta-item upgrade-file-meta-item--checksum">{{firmwareChecksumText}}</text>
                <text class="upgrade-file-meta-item upgrade-file-meta-item--size">{{firmwareSizeText}}</text>
              </view>
            </view>
            <text class="upgrade-file-name">{{firmwareName ? firmwareName : '--'}}</text>
          </view>
          <view class="upgrade-row">
            <text class="upgrade-label">Bootloader</text>
            <text class="upgrade-value">{{bootloaderVersion}} / {{bootloaderChipId}}</text>
          </view>
          <view wx:if="{{bootloaderStatusText || bootloaderDetailText}}" class="upgrade-status {{isFirmwareReady ? 'upgrade-status--ready' : ''}}">
            {{bootloaderStatusText}}<text wx:if="{{bootloaderDetailText}}"> · {{bootloaderDetailText}}</text>
          </view>
          <view class="upgrade-progress">
            <view class="upgrade-progress-bar" style="width: {{bootloaderProgress}}%;"></view>
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'crc'}}">
      <view class="panel params-section-panel crc-algorithm-panel {{crcAlgorithmCollapsed ? 'panel--collapsed' : ''}}">
        <view class="param-row input-row">
          <picker
            class="crc-algorithm-picker"
            mode="selector"
            range="{{crcPresetOptions}}"
            range-key="label"
            value="{{crcPresetIndex}}"
            bindchange="onCrcPresetChange"
          >
            <view class="crc-algorithm-picker-content">
              <view class="param-main">
                <view class="param-name">算法</view>
              </view>
              <view class="generic-picker-value crc-picker-value">{{crcPresetOptions[crcPresetIndex].label}}</view>
            </view>
          </picker>
          <view
            class="collapse-toggle {{crcAlgorithmCollapsed ? 'is-collapsed' : ''}}"
            bindtap="toggleCrcAlgorithmPanel"
          >
            <view class="collapse-indicator"></view>
          </view>
        </view>
        <view wx:if="{{!crcAlgorithmCollapsed && (crcShowCrcConfig || crcShowHmacKey || crcShowPbkdf2Config)}}" class="crc-algorithm-fields">
          <block wx:if="{{crcShowCrcConfig}}">
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">位宽</view>
                <view class="param-meta">1 - 64</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" type="number" data-field="crcWidth" value="{{crcWidth}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">Poly</view>
                <view class="param-meta">HEX</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" data-field="crcPoly" value="{{crcPoly}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">初始值</view>
                <view class="param-meta">HEX</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" data-field="crcInitialValue" value="{{crcInitialValue}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">结果异或值</view>
                <view class="param-meta">HEX</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" data-field="crcXorOut" value="{{crcXorOut}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="crc-switch-row">
              <view class="crc-switch-field">
                <view class="param-name">输入反转</view>
                <switch checked="{{crcReflectIn}}" color="#0f766e" data-field="crcReflectIn" bindchange="onCrcReflectChange" />
              </view>
              <view class="crc-switch-field">
                <view class="param-name">输出反转</view>
                <switch checked="{{crcReflectOut}}" color="#0f766e" data-field="crcReflectOut" bindchange="onCrcReflectChange" />
              </view>
            </view>
          </block>
          <block wx:elif="{{crcShowHmacKey}}">
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">密钥</view>
                <view class="param-meta">UTF-8</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" data-field="crcHmacKey" value="{{crcHmacKey}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
          </block>
          <block wx:elif="{{crcShowPbkdf2Config}}">
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">盐值</view>
                <view class="param-meta">UTF-8</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" data-field="crcPbkdf2Salt" value="{{crcPbkdf2Salt}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">迭代次数</view>
                <view class="param-meta">1 - 100000</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" type="number" data-field="crcPbkdf2Iterations" value="{{crcPbkdf2Iterations}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
            <view class="param-row input-row">
              <view class="param-main">
                <view class="param-name">输出长度</view>
                <view class="param-meta">1 - 4096 Byte</view>
              </view>
              <view class="input-wrap">
                <input class="value-input crc-config-input" type="number" data-field="crcPbkdf2Length" value="{{crcPbkdf2Length}}" bindinput="onCrcConfigInput" />
              </view>
            </view>
          </block>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title crc-data-card-header">
          <view class="crc-data-title">数据</view>
          <view class="crc-data-header-actions">
            <picker
              class="crc-data-type-picker"
              mode="selector"
              range="{{crcInputTypeOptions}}"
              range-key="label"
              value="{{crcInputTypeIndex}}"
              bindchange="onCrcInputTypeChange"
            >
              <view class="crc-data-type-value">{{crcInputTypeOptions[crcInputTypeIndex].label}}</view>
            </picker>
            <view class="panel-action-button" bindtap="loadCrcFileFromMessage">加载</view>
            <view class="panel-action-button" bindtap="clearCrcInput">清空</view>
            <view class="panel-action-button is-active" bindtap="calculateCrc">计算</view>
          </view>
        </view>
        <view wx:if="{{crcFileName}}" class="param-row">
          <view class="param-main">
            <view class="param-name">文件</view>
            <view class="param-meta">{{crcFileSizeText}}</view>
          </view>
          <view class="crc-file-name">{{crcFileName}}</view>
        </view>
        <view class="crc-data-wrap">
          <textarea
            class="crc-data-input"
            maxlength="-1"
            auto-height
            value="{{crcDataText}}"
            bindinput="onCrcDataInput"
          />
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">结果</view>
        <view class="param-row crc-calc-result-row">
          <view class="param-main crc-calc-result-main">
            <view class="param-name">HEX</view>
            <view class="crc-calc-result-value" data-value="{{crcResultHex}}" bindtap="copyToolResult">{{crcResultHex}}</view>
          </view>
        </view>
        <view wx:if="{{crcShowBinResult}}" class="param-row crc-calc-result-row crc-calc-result-row--bin">
          <view class="param-main crc-calc-result-main">
            <view class="param-name">BIN</view>
            <view class="crc-calc-result-value crc-calc-result-value--bin" data-value="{{crcResultBin}}" bindtap="copyToolResult">
              <text wx:for="{{crcResultBinLines}}" wx:key="id" class="crc-result-bin-line">{{item.text}}</text>
            </view>
          </view>
        </view>
        <view class="param-row crc-calc-result-row">
          <view class="param-main crc-calc-result-main">
            <view class="param-name">Base64</view>
            <view class="crc-calc-result-value" data-value="{{crcResultBase64}}" bindtap="copyToolResult">{{crcResultBase64}}</view>
          </view>
        </view>
        <view wx:if="{{crcErrorText}}" class="param-row">
          <view class="param-main">
            <view class="param-name">错误</view>
          </view>
          <view class="crc-error-value">{{crcErrorText}}</view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'filter'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title filter-section-title">
          <view class="filter-section-title-text">参数</view>
          <view class="filter-mode-actions">
            <view class="filter-mode-button" bindtap="toggleFilterNetwork">{{filterNetworkText}}</view>
            <view class="filter-mode-button" bindtap="toggleFilterResponse">{{filterResponseText}}</view>
            <view class="filter-mode-button" bindtap="clearFilterInputs">清除</view>
          </view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">电阻 R</view>
            <view wx:if="{{filterComputedKey == 'resistance'}}" class="param-meta">自动计算</view>
          </view>
          <view class="filter-input-wrap">
            <input
              class="value-input filter-value-input {{filterComputedKey == 'resistance' ? 'filter-value-input--computed' : ''}}"
              type="digit"
              placeholder="--"
              data-field="resistance"
              value="{{filterResistanceDisplayValue}}"
              bindinput="onFilterResistanceInput"
              bindblur="onFilterValueBlur"
            />
            <picker
              class="filter-unit-picker"
              mode="selector"
              range="{{filterResistanceUnitOptions}}"
              range-key="label"
              value="{{filterResistanceUnitIndex}}"
              bindchange="onFilterResistanceUnitChange"
            >
              <view class="filter-unit-value">{{filterResistanceUnitText}}</view>
            </picker>
          </view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">{{filterReactiveName}} {{filterReactiveSymbol}}</view>
            <view wx:if="{{filterComputedKey == 'reactive'}}" class="param-meta">自动计算</view>
          </view>
          <view class="filter-input-wrap">
            <input
              class="value-input filter-value-input {{filterComputedKey == 'reactive' ? 'filter-value-input--computed' : ''}}"
              type="digit"
              placeholder="--"
              data-field="reactive"
              value="{{filterReactiveDisplayValue}}"
              bindinput="onFilterReactiveInput"
              bindblur="onFilterValueBlur"
            />
            <picker
              class="filter-unit-picker"
              mode="selector"
              range="{{filterReactiveUnitOptions}}"
              range-key="label"
              value="{{filterReactiveUnitIndex}}"
              bindchange="onFilterReactiveUnitChange"
            >
              <view class="filter-unit-value">{{filterReactiveUnitText}}</view>
            </picker>
          </view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">-3dB截止频率</view>
            <view wx:if="{{filterComputedKey == 'frequency'}}" class="param-meta">自动计算</view>
          </view>
          <view class="filter-input-wrap">
            <input
              class="value-input filter-value-input {{filterComputedKey == 'frequency' ? 'filter-value-input--computed' : ''}}"
              type="digit"
              placeholder="--"
              data-field="frequency"
              value="{{filterFrequencyDisplayValue}}"
              bindinput="onFilterFrequencyInput"
              bindblur="onFilterValueBlur"
            />
            <picker
              class="filter-unit-picker"
              mode="selector"
              range="{{filterFrequencyUnitOptions}}"
              range-key="label"
              value="{{filterFrequencyUnitIndex}}"
              bindchange="onFilterFrequencyUnitChange"
            >
              <view class="filter-unit-value">{{filterFrequencyUnitText}}</view>
            </picker>
          </view>
        </view>
        <view wx:if="{{filterErrorText}}" class="filter-error-inline">{{filterErrorText}}</view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title filter-diagram-title">
          <view>电路图</view>
          <view class="filter-diagram-mode">{{filterNetworkText}} · {{filterResponseText}}</view>
        </view>
        <view class="filter-diagram">
          <view class="filter-schematic">
            <view class="filter-schematic-label filter-schematic-label--input">Vin</view>
            <view class="filter-schematic-label filter-schematic-label--output">Vout</view>

            <view class="filter-schematic-dot filter-schematic-dot--input-top"></view>
            <view class="filter-schematic-dot filter-schematic-dot--input-bottom"></view>
            <view class="filter-schematic-dot filter-schematic-dot--node-top"></view>
            <view class="filter-schematic-dot filter-schematic-dot--node-bottom"></view>
            <view class="filter-schematic-dot filter-schematic-dot--output-top"></view>
            <view class="filter-schematic-dot filter-schematic-dot--output-bottom"></view>

            <view class="filter-schematic-wire filter-schematic-wire--top-input"></view>
            <view class="filter-schematic-wire filter-schematic-wire--top-middle"></view>
            <view class="filter-schematic-wire filter-schematic-wire--top-output"></view>
            <view class="filter-schematic-wire filter-schematic-wire--bottom-input"></view>
            <view class="filter-schematic-wire filter-schematic-wire--bottom-output"></view>
            <view class="filter-schematic-wire filter-schematic-wire--branch-top"></view>
            <view class="filter-schematic-wire filter-schematic-wire--branch-bottom"></view>

            <view class="filter-schematic-mark filter-schematic-mark--series">{{filterSeriesLabel}}</view>
            <view class="filter-schematic-component filter-schematic-component--series">
              <image class="filter-schematic-symbol" src="{{filterSeriesComponentSrc}}" mode="aspectFit" />
            </view>

            <view class="filter-schematic-mark filter-schematic-mark--shunt">{{filterShuntLabel}}</view>
            <view class="filter-schematic-component filter-schematic-component--shunt">
              <image class="filter-schematic-symbol filter-schematic-symbol--vertical" src="{{filterShuntComponentSrc}}" mode="aspectFit" />
            </view>
          </view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'reactance'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title filter-section-title">
          <view class="filter-section-title-text">参数</view>
          <view class="filter-mode-actions">
            <view class="filter-mode-button" bindtap="toggleReactanceMode">{{reactanceModeText}}</view>
            <view class="filter-mode-button" bindtap="clearReactanceInputs">清除</view>
          </view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">频率 f</view>
          </view>
          <view class="filter-input-wrap">
            <input
              class="value-input filter-value-input"
              type="digit"
              placeholder="--"
              data-field="frequency"
              value="{{reactanceFrequencyDisplayValue}}"
              bindinput="onReactanceFrequencyInput"
              bindblur="onReactanceValueBlur"
            />
            <picker
              class="filter-unit-picker"
              mode="selector"
              range="{{reactanceFrequencyUnitOptions}}"
              range-key="label"
              value="{{reactanceFrequencyUnitIndex}}"
              bindchange="onReactanceFrequencyUnitChange"
            >
              <view class="filter-unit-value">{{reactanceFrequencyUnitText}}</view>
            </picker>
          </view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">{{reactanceReactiveName}} {{reactanceReactiveSymbol}}</view>
          </view>
          <view class="filter-input-wrap">
            <input
              class="value-input filter-value-input"
              type="digit"
              placeholder="--"
              data-field="reactive"
              value="{{reactanceReactiveDisplayValue}}"
              bindinput="onReactanceReactiveInput"
              bindblur="onReactanceValueBlur"
            />
            <picker
              class="filter-unit-picker"
              mode="selector"
              range="{{reactanceReactiveUnitOptions}}"
              range-key="label"
              value="{{reactanceReactiveUnitIndex}}"
              bindchange="onReactanceReactiveUnitChange"
            >
              <view class="filter-unit-value">{{reactanceReactiveUnitText}}</view>
            </picker>
          </view>
        </view>
        <view wx:if="{{reactanceErrorText}}" class="filter-error-inline">{{reactanceErrorText}}</view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title filter-diagram-title">
          <view>结果</view>
          <view class="filter-diagram-mode">{{reactanceModeText}}</view>
        </view>
        <view
          wx:for="{{reactanceResultRows}}"
          wx:for-item="row"
          wx:key="label"
          class="param-row smd-result-row"
        >
          <view class="param-main">
            <view class="param-name">{{row.label}}</view>
            <view class="param-meta">{{row.meta}}</view>
          </view>
          <view class="smd-result-value">{{row.value}}</view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'smdCode'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title smd-section-title">
          <view class="smd-section-title-text">类型</view>
          <view class="smd-mode-actions">
            <view
              wx:for="{{smdKindOptions}}"
              wx:key="key"
              class="smd-mode-button {{smdKindKey == item.key ? 'is-active' : ''}}"
              data-kind="{{item.key}}"
              bindtap="onSmdKindTap"
            >
              {{item.label}}
            </view>
          </view>
        </view>
        <view class="smd-format-row">
          <view
            wx:for="{{smdFormatOptions}}"
            wx:key="key"
            class="smd-format-button {{smdFormatKey == item.key ? 'is-active' : ''}}"
            data-format="{{item.key}}"
            bindtap="onSmdFormatTap"
          >
            {{item.label}}
          </view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title smd-section-title">
          <view class="smd-section-title-text">编码</view>
          <view wx:if="{{smdCodeText}}" class="panel-action-button" bindtap="clearSmdCodeInput">清空</view>
        </view>
        <view class="param-row input-row">
          <view class="param-main">
            <view class="param-name">EIA</view>
            <view class="param-meta">{{smdKindText}} · {{smdFormatText}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input smd-code-input"
              placeholder="{{smdFormatKey == 'eia96' ? '01A' : smdFormatKey == 'eia198' ? 'A4' : '103'}}"
              value="{{smdCodeText}}"
              bindinput="onSmdCodeInput"
            />
          </view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">结果</view>
        <view class="param-row smd-result-row">
          <view class="param-main">
            <view class="param-name">显示值</view>
            <view class="param-meta {{smdErrorText ? 'param-meta--dirty' : ''}}">{{smdErrorText || smdFormulaText || '输入编码后自动计算'}}</view>
          </view>
          <view class="smd-result-value {{smdErrorText ? 'smd-result-value--error' : ''}}">{{smdResultText}}</view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'refrigeration'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title smd-section-title refrigeration-title-row">
          <view class="smd-section-title-text">公式</view>
          <picker
            class="refrigeration-mode-picker"
            mode="selector"
            range="{{coolingModeOptions}}"
            range-key="label"
            value="{{coolingModeIndex}}"
            bindchange="onCoolingModeChange"
          >
            <view class="generic-picker-value refrigeration-picker-value">
              {{coolingModeText}}
            </view>
          </picker>
        </view>
        <view class="smd-format-row refrigeration-formula-row">
          <view class="refrigeration-formula-text">{{coolingFormulaText}}</view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title smd-section-title">
          <view class="smd-section-title-text">输入</view>
          <view wx:if="{{coolingAnyInput}}" class="panel-action-button" bindtap="clearCoolingInputs">清空</view>
        </view>
        <view
          wx:for="{{coolingFieldRows}}"
          wx:for-item="field"
          wx:key="key"
          class="param-row input-row"
        >
          <view class="param-main">
            <view class="param-name">{{field.label}}</view>
            <view class="param-meta">{{field.unit}}</view>
          </view>
          <view class="input-wrap">
            <input
              class="value-input smd-code-input refrigeration-input"
              type="text"
              placeholder="{{field.placeholder}}"
              value="{{field.value}}"
              data-field="{{field.key}}"
              bindinput="onCoolingInput"
            />
          </view>
        </view>
      </view>

      <view class="panel params-section-panel">
        <view class="params-section-title">结果</view>
        <view wx:if="{{coolingErrorText}}" class="filter-error-inline">{{coolingErrorText}}</view>
        <view wx:if="{{!coolingResultRows.length && !coolingErrorText}}" class="param-row smd-result-row">
          <view class="param-main">
            <view class="param-name">显示值</view>
            <view class="param-meta">输入参数后自动计算</view>
          </view>
          <view class="smd-result-value">--</view>
        </view>
        <view
          wx:for="{{coolingResultRows}}"
          wx:for-item="row"
          wx:key="label"
          class="param-row smd-result-row"
        >
          <view class="param-main">
            <view class="param-name">{{row.label}}</view>
          </view>
          <view class="smd-result-value">{{row.value}}</view>
        </view>
      </view>
    </block>

    <block wx:elif="{{activeSettingsView == 'threePhasePower'}}">
      <view class="panel params-section-panel">
        <view class="params-section-title smd-section-title">
          <view class="smd-section-title-text">参数</view>
          <view class="smd-mode-actions">
            <view
              wx:for="{{threePhaseConnectionOptions}}"
              wx:key="key"
              class="smd-mode-button {{threePhaseConnectionKey == item.key ? 'is-active' : ''}}"
              data-connection="{{item.key}}"
              bindtap="onThreePhaseConnectionTap"
            >
              {{item.label}}
            </view>
            <view class="panel-action-button" bindtap="clearThreePhaseInputs">清除</view>
          </view>
        </view>
        <view wx:if="{{threePhaseErrorText}}" class="filter-error-inline">{{threePhaseErrorText}}</view>
        <view
          wx:for="{{threePhaseRows}}"
          wx:for-item="row"
          wx:key="key"
          class="param-row {{row.editable ? 'input-row' : ''}}"
        >
          <view class="param-main">
            <view class="param-name">{{row.label}}</view>
            <view wx:if="{{row.unit}}" class="param-meta">{{row.unit}}</view>
          </view>
          <view wx:if="{{!row.editable}}" class="smd-result-value">{{row.value}}</view>
          <view wx:if="{{row.editable}}" class="input-wrap">
            <input
              class="value-input smd-code-input three-phase-input"
              type="text"
              placeholder="{{row.placeholder}}"
              value="{{row.value}}"
              data-field="{{row.field}}"
              bindinput="onThreePhaseInput"
            />
          </view>
        </view>
      </view>
    </block>


    </block>
    <block wx:else>
    <view class="panel settings-section-panel">
      <view class="params-section-title">通用设置</view>
      <view class="settings-row">
        <view class="settings-row-main">
          <view class="param-name">夜间模式启用</view>
          <view class="param-meta">当前 {{themeMode === 'dark' ? '夜间' : '日间'}}</view>
        </view>
        <switch
          checked="{{nightModeEnabledSwitch}}"
          color="#0f766e"
          disabled="{{nightModeFollowSystem}}"
          bindchange="onNightModeEnabledChange"
        />
      </view>
      <view class="settings-row">
        <view class="settings-row-main">
          <view class="param-name">夜间模式跟随系统</view>
          <view class="param-meta">{{nightModeFollowSystem ? '已跟随' : '手动控制'}}</view>
        </view>
        <switch
          checked="{{nightModeFollowSystem}}"
          color="#0f766e"
          bindchange="onNightModeFollowSystemChange"
        />
      </view>
    </view>

    <view class="panel settings-section-panel">
      <view class="params-section-title">协议</view>
      <view class="settings-row">
        <view class="settings-row-main">
          <view class="param-name">协议模式</view>
          <view class="param-meta">{{isStorageAccessProtocol ? '单主单从存储访问' : '标准功能码寄存器'}}</view>
        </view>
        <picker
          mode="selector"
          range="{{protocolOptions}}"
          range-key="label"
          value="{{protocolIndex}}"
          bindchange="onProtocolModeChange"
        >
          <view class="settings-picker-value">{{protocolText}}</view>
        </picker>
      </view>
      <view wx:if="{{isModbusProtocol}}" class="settings-row settings-row--input">
        <view class="settings-row-main">
          <view class="param-name">从机地址</view>
          <view class="param-meta">00 - FF</view>
        </view>
        <view class="settings-input-wrap">
          <input
            class="value-input settings-value-input settings-value-input--hex"
            maxlength="2"
            value="{{modbusSlaveAddress}}"
            bindblur="onModbusSlaveAddressBlur"
            bindconfirm="onModbusSlaveAddressBlur"
          />
        </view>
      </view>
      <view class="settings-row">
        <view class="settings-row-main">
          <view class="param-name">自动轮询</view>
          <view class="param-meta">{{parameterAutoPollEnabled ? '已启用' : '已停止'}}</view>
        </view>
        <switch
          checked="{{parameterAutoPollEnabled}}"
          color="#0f766e"
          bindchange="onParameterAutoPollChange"
        />
      </view>
      <view class="settings-row settings-row--input">
        <view class="settings-row-main">
          <view class="param-name">轮询间隔</view>
          <view class="param-meta">{{statusPollMinInterval}} - {{statusPollMaxInterval}} ms</view>
        </view>
        <view class="settings-input-wrap settings-input-wrap--unit">
          <input
            class="value-input settings-value-input settings-value-input--unit"
            type="number"
            value="{{parameterPollInterval}}"
            bindblur="onParameterPollIntervalBlur"
            bindconfirm="onParameterPollIntervalBlur"
          />
          <text class="settings-unit settings-unit--inside">ms</text>
        </view>
      </view>
      <view class="settings-row settings-row--input">
        <view class="settings-row-main">
          <view class="param-name">最大包长</view>
          <view class="param-meta">0 为无限制，最小 {{parameterMinPacketLength}} 字节</view>
        </view>
        <view class="settings-input-wrap settings-input-wrap--unit">
          <input
            class="value-input settings-value-input settings-value-input--unit"
            type="number"
            value="{{parameterMaxPacketLength}}"
            bindblur="onParameterMaxPacketLengthBlur"
            bindconfirm="onParameterMaxPacketLengthBlur"
          />
          <text class="settings-unit settings-unit--inside">B</text>
        </view>
      </view>
    </view>

    <view class="panel settings-section-panel">
      <view class="params-section-title">工具</view>
      <view
        wx:for="{{toolEntries}}"
        wx:key="view"
        class="settings-row settings-tool-row"
        data-view="{{item.view}}"
        bindtap="openToolEntry"
      >
        <view class="settings-tool-main">
          <view class="settings-tool-icon-frame {{item.icon}}">
            <image class="settings-tool-icon-image" src="{{item.iconSrc}}" mode="aspectFit" />
          </view>
          <view class="param-name settings-tool-title">{{item.label}}</view>
        </view>
        <view class="entry-chevron"></view>
      </view>
    </view>
    </block>
  </view>
</scroll-view>
