//
// WatchSettingsView.swift
// Workouts Watch App
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//

import SwiftUI

/// The watch's small settings sheet — just the rest time today, adjusted with the
/// same 1-second stepper as the iPhone. The value lives in the shared defaults key
/// the phone pushes; edits are forwarded back so the phone (the durable owner)
/// re-echoes them to every device.
struct WatchSettingsView: View {
    @Environment(WatchConnectivityBridge.self) private var bridge

    /// Shared with the phone via the same defaults key (see `WCPayload.restSecondsKey`).
    @AppStorage("restSeconds") private var restSeconds: Int = 45

    var body: some View {
        Form {
            Section {
                Stepper(value: $restSeconds, in: 10...180, step: 1) {
                    Text("\(restSeconds)s")
                        .font(.system(.title3, design: .rounded, weight: .semibold))
                        .monospacedDigit()
                }
            } header: {
                Text("Rest Between Sets")
            } footer: {
                Text("Used between sets and, when auto-advancing, between exercises. A routine's custom rest time overrides it.")
            }
        }
        .navigationTitle("Settings")
        .onChange(of: restSeconds) { _, seconds in
            bridge.sendRestSeconds(seconds)
        }
    }
}
