<!DOCTYPE html>
<html lang="en">
{{ template "head" . }}
<body>

<div class="container-fluid">
    {{ $root := . }}
    {{ $devs := .Devices }}
    {{ $temperatures := .Temperatures }}
    {{ $device := .Device }}
    {{ $rgbModes := .Device.RGBModes }}
    {{ $devices := $device.Devices }}
    {{ $rgbDevices := $device.RgbDevices }}
    {{ $rgb := .Rgb }}
    {{ $lcd := .Device.HasLCD }}
    {{ $lcdModes := .Device.LCDModes }}
    {{ $lcdImages := .LCDImages }}
    {{ $lcdMode := .Device.DeviceProfile.LCDMode }}
    {{ $lcdRotations := .Device.LCDRotations }}
    {{ $lcdRotation := .Device.DeviceProfile.LCDRotation }}
    {{ $lcdBrightness := .Device.DeviceProfile.LCDBrightness }}
    {{ $lcdBrightnessLevels := .Device.LCDBrightnessLevels }}
    {{ $lcdImage := .Device.DeviceProfile.LCDImage }}
    {{ $deviceProfile := .Device.DeviceProfile }}
    <input type="hidden" id="deviceId" name="deviceId" value="{{ $device.Serial }}">
    <input type="hidden" id="selectedDevices" name="selectedDevices" value="">
    <div class="row">
        <!-- Sidebar -->
        {{ template "sidebar" . }}

        <!-- Main -->
        <main class="main-content p-4">
            <!-- Temperature bar -->
            {{ if .Dashboard.TemperatureBar }}
            {{ template "temperature-bar" . }}
            {{ end }}

            <!-- Commander Core -->
            <div class="row g-4 mb-4 align-items-start">
                <div class="col-md-2">
                    <div class="stack-gap-4">
                        <!-- Settings -->
                        <div class="card system-card text-center">
                            <div class="card-header">
                                {{ .Device.Product }}
                            </div>
                            <div class="card-body">
                                <div class="settings-list">
                                    <!-- Firmware -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtFirmware" }}</span>
                                        <span class="meta-value">{{ .Device.Firmware }}</span>
                                    </div>

                                    <!-- User profile -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtProfile" }}</span>
                                        <label for="profiles">
                                            <select id="profiles" class="form-select system-select compact auto-width userProfile" name="userProfile">
                                                {{ range $key, $profile := $device.UserProfiles }}
                                                {{ if $profile.Active }}
                                                <option value="{{ $key }}" selected>{{ $key }}</option>
                                                {{ else }}
                                                <option value="{{ $key }}">{{ $key }}</option>
                                                {{ end }}
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <!-- Brightness -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtBrightness" }}</span>
                                        <div class="system-slider no-padding-top">
                                            <label for="brightnessSlider">
                                                <input type="range" id="brightnessSlider" name="brightnessSlider" min="0" max="100" value="{{ $deviceProfile.BrightnessSlider }}" step="1">
                                            </label>
                                            <div class="slider-value" id="brightnessSliderValue">{{ $deviceProfile.BrightnessSlider }} %</div>
                                        </div>
                                    </div>

                                    <!-- RGB Cluster -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtCluster" }}</span>
                                        <label class="system-toggle compact">
                                            <input type="checkbox" id="toggleRgbCluster" class="toggleRgbCluster" {{ if $deviceProfile.RGBCluster }} checked {{ end }}>
                                            <span class="toggle-track"></span>
                                        </label>
                                    </div>

                                    <!-- OpenRGB -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtOpenRGB" }}</span>
                                        <label class="system-toggle compact">
                                            <input type="checkbox" class="toggleOpenRGB" {{ if $deviceProfile.OpenRGBIntegration }} checked {{ end }}>
                                            <span class="toggle-track"></span>
                                        </label>
                                    </div>

                                    <!-- RGB Profile -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtRgb" }}</span>
                                        <label for="globalRgbProfile">
                                            <select id="globalRgbProfile" class="form-select system-select compact auto-width globalRgb" name="globalRgb">
                                                <option value="">None</option>
                                                {{ range $key, $mode := $rgbModes }}
                                                <option value="{{ $mode }}">{{ $mode }}</option>
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <!-- Speed Profile -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtSpeed" }}</span>
                                        <label for="globalSpeedProfile">
                                            <select id="globalSpeedProfile" class="form-select system-select compact auto-width globalTempProfile" name="globalTempProfile">
                                                {{ range $key, $pf := $temperatures }}
                                                {{ if $pf.Hidden }}
                                                {{ continue }}
                                                {{ end }}
                                                <option value="{{ $key }}" {{ if eq $deviceProfile.MultiProfile $key }}selected {{ end }}>{{ $key }}</option>
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <!-- Delete user profile -->
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtDeleteProfile" }}</span>
                                        <label for="deleteUserProfiles">
                                            <select id="deleteUserProfiles" class="form-select system-select compact auto-width deleteUserProfiles" name="deleteUserProfiles">
                                                <option value="none">None</option>
                                                {{ range $key, $profile := $device.UserProfiles }}
                                                {{ if $profile.Active }}
                                                {{ continue }}
                                                {{ else }}
                                                <option value="{{ $key }}">{{ $key }}</option>
                                                {{ end }}
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <!-- Save profile -->
                                    <div class="settings-row">
                                        <button class="system-button center saveUserProfile">{{ .Lang "txtSaveUserProfile" }}</button>
                                        <button class="system-button danger center deleteUserProfile">{{ .Lang "txtDeleteProfile" }}</button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- Custom ARGB Devices -->
                        {{ $freePorts := len $device.FreeLedPorts }}
                        {{ if gt $freePorts 0 }}
                        <div class="card system-card text-center">
                            <div class="card-header">{{ .Lang "txtCustomRgbDevice" }}</div>
                            <div class="card-body">
                                <div class="settings-list">
                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtLedPort" }}</span>
                                        <label for="customLedPort">
                                            <select id="customLedPort" class="form-select system-select compact max-width-120 customLedPort" name="customLedPort">
                                                {{ range $key, $value := $device.FreeLedPorts }}
                                                <option value="{{ $key }}">{{ $value }}</option>
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <div class="settings-row">
                                        <span class="settings-label text-ellipsis">{{ .Lang "txtDevice" }}</span>
                                        <label for="customLedPortLEDAmount">
                                            <select id="customLedPortLEDAmount" class="form-select system-select compact max-width-120 customLedPortLEDAmount" name="customLedPortLEDAmount">
                                                {{ range $key, $externalLedDevice := $device.ExternalLedDevice }}
                                                <option value="{{ $externalLedDevice.Index }}">{{ $externalLedDevice.Name }}</option>
                                                {{ end }}
                                            </select>
                                        </label>
                                    </div>

                                    <div class="settings-row">
                                        <button class="system-button addCustomARGBDevice">
                                            {{ .Lang "txtAddRemoveDevice" }}
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {{ end }}
                    </div>
                </div>
                <div class="col-md-10">
                    <!-- Fans -->
                    <div class="row g-4 mb-4 align-items-start">
                        {{ range $device := $devices }}
                        <div class="col-md-2">
                            <div class="card system-card device-selectable" data-info="{{ $device.ChannelId }}">
                                <div class="card-header header-split">
                                    <span class="header-left">
                                        {{ $device.Name }}
                                    </span>
                                    <input type="hidden" class="deviceData" value="{{ $device.ChannelId }}">
                                    <span class="header-right newLabel">
                                        <input type="hidden" class="deviceData" value="{{ $device.ChannelId }}">
                                        <span class="labelValue">{{ $device.Label }}</span>
                                    </span>
                                </div>
                                <div class="card-body">
                                    <div class="settings-list">
                                        {{ if $device.HasTemps }}
                                        {{ $tempLang := $root.Lang "txtTemperature" }}

                                        {{ if $device.ContainsPump }}
                                        {{ $tempLang = $root.Lang "txtLiquid" }}
                                        {{ end }}

                                        <!-- Temperature -->
                                        {{ if gt $device.Temperature 0.00 }}
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $tempLang }}</span>
                                            <span class="meta-value" id="temperature-{{ .DeviceId }}">{{ $device.TemperatureString }}</span>
                                        </div>
                                        {{ end }}
                                        {{ end }}

                                        {{ if $device.HasSpeed }}
                                        <!-- Speed -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtSpeed" }}</span>
                                            <span class="meta-value" id="speed-{{ .DeviceId }}">{{ $device.Rpm }} RPM</span>
                                        </div>

                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtProfile" }}</span>
                                            <label>
                                                <select class="form-select system-select compact auto-width tempProfile" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $pf := $temperatures }}
                                                    {{ if $pf.Hidden }}
                                                    {{ continue }}
                                                    {{ end }}
                                                    <option value="{{ $device.ChannelId }};{{ $key }}" {{ if eq $device.Profile $key }} selected {{ end }}>{{ $key }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>
                                        {{ end }}

                                        {{ if and $lcd $device.ContainsPump }}
                                        <!-- LCD Modes -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtLcdMode" }}</span>
                                            <label>
                                                <select class="form-select system-select compact max-width-100 lcdMode" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $value := $lcdModes }}
                                                    <option value="{{ $device.ChannelId }};{{ $key }}"{{ if eq $key $lcdMode }} selected {{ end }}>{{ $value }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>

                                        <!-- LCD Image -->
                                        <div class="settings-row lcdImagesHolder" style="{{ if ne $lcdMode 10 }}display:none;{{ end }}">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtLcdImage" }}</span>
                                            <label>
                                                <select class="form-select system-select compact max-width-100 lcdImages" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $value := $lcdImages }}
                                                    <option value="{{ $device.ChannelId }};{{ $value.Name }}"{{ if eq $value.Name $lcdImage }} selected {{ end }}>{{ $value.Name }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>

                                        <!-- LCD Rotation -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtLcdRotation" }}</span>
                                            <label>
                                                <select class="form-select system-select compact max-width-100 lcdRotation" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $value := $lcdRotations }}
                                                    <option value="{{ $device.ChannelId }};{{ $key }}"{{ if eq $key $lcdRotation }} selected {{ end }}>{{ $value }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>

                                        <!-- LCD Brightness -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtLcdBrightness" }}</span>
                                            <label>
                                                <select class="form-select system-select compact max-width-100 lcdBrightness" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $value := $lcdBrightnessLevels }}
                                                    <option value="{{ $device.ChannelId }};{{ $key }}"{{ if eq $key $lcdBrightness }} selected {{ end }}>{{ $value }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>
                                        {{ end }}
                                    </div>
                                </div>
                            </div>
                        </div>
                        {{ end }}
                    </div>

                    <!-- RGB -->
                    <div class="row g-4 mb-4 align-items-start">
                        {{ range $device := $rgbDevices }}
                        <div class="col-md-2">
                            <div class="card system-card device-selectable" data-info="{{ $device.ChannelId }}">
                                <div class="card-header header-split">
                                    <span class="header-left">
                                        {{ $device.Name }}
                                    </span>
                                    <input type="hidden" class="deviceData" value="{{ $device.ChannelId }}">
                                    <span class="header-right newRgbLabel">
                                        <input type="hidden" class="deviceData" value="{{ $device.ChannelId }}">
                                        <span class="labelValue">{{ $device.Label }}</span>
                                    </span>
                                </div>
                                <div class="card-body">
                                    <div class="settings-list">
                                        {{ if gt $device.LedChannels 0 }}
                                        <!-- RGB -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtRgb" }}</span>
                                            <label>
                                                <select class="form-select system-select compact auto-width rgbProfile" name="{{ $device.DeviceId }}">
                                                    {{ range $key, $mode := $rgbModes }}
                                                    <option value="{{ $device.ChannelId }};{{ $mode }}" {{ if eq $mode $device.RGB }} selected{{ end }}>{{ $mode }}</option>
                                                    {{ end }}
                                                </select>
                                            </label>
                                        </div>

                                        <!-- RGB Override -->
                                        <div class="settings-row">
                                            <span class="settings-label text-ellipsis">{{ $root.Lang "txtRgbOverride" }}</span>
                                            <label>
                                                <button class="system-button compact rgbOverride" data-info="{{ $device.ChannelId }}" type="button">{{ $root.Lang "txtConfigure" }}</button>
                                            </label>
                                        </div>
                                        {{ end }}
                                    </div>
                                </div>
                            </div>
                        </div>
                        {{ end }}
                    </div>
                </div>
            </div>
        </main>
    </div>
</div>
<script src="/static/js/overview.js"></script>
<script src="/static/js/sidebar.js"></script>
{{ if .Dashboard.TemperatureBar }}
<script src="/static/js/temperature-bar.js"></script>
{{ end }}
</body>
</html>
