Files
Termind/TFM/Features/Settings/WebSearchSettings.swift
T

46 lines
1.6 KiB
Swift

import SwiftUI
import TermindDomain
import TermindPresentation
struct WebSearchSettings: View {
@Environment(AppModel.self) private var app
private var isEnabled: Bool { app.aiConfiguration.webSearch.isEnabled }
private var usesBuiltIn: Bool { app.aiConfiguration.webSearch.prefersBuiltIn }
private func binding(_ keyPath: WritableKeyPath<AIWebSearchPreferences, Bool>) -> Binding<Bool> {
Binding(
get: { app.aiConfiguration.webSearch[keyPath: keyPath] },
set: { value in
var preferences = app.aiConfiguration.webSearch
preferences[keyPath: keyPath] = value
app.aiConfiguration.setWebSearch(preferences)
})
}
var body: some View {
Section {
Toggle(AppStrings.Settings.enableWebSearch.swiftUIKey, isOn: binding(\.isEnabled))
Toggle(AppStrings.Settings.preferBuiltInWebSearch.swiftUIKey, isOn: binding(\.prefersBuiltIn))
.disabled(!isEnabled)
Text(
usesBuiltIn
? String(
localized:
AppStrings.Settings.nativeAndFallbackSearchExplanation
)
: String(
localized:
AppStrings.Settings.webSearchExplanation
)
)
.font(.caption)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
} header: {
Text(AppStrings.Settings.webSearch)
}
}
}