vOOice/VoiceInk/Views/Dictionary/DictionarySettingsView.swift
2025-07-23 10:34:08 +05:45

137 lines
4.4 KiB
Swift

import SwiftUI
struct DictionarySettingsView: View {
@State private var selectedSection: DictionarySection = .replacements
let whisperPrompt: WhisperPrompt
enum DictionarySection: String, CaseIterable {
case replacements = "Word Replacements"
case spellings = "Correct Spellings"
var description: String {
switch self {
case .spellings:
return "Train VoiceInk to recognize industry terms, names, and technical words"
case .replacements:
return "Automatically replace specific words/phrases with custom formatted text "
}
}
var icon: String {
switch self {
case .spellings:
return "character.book.closed.fill"
case .replacements:
return "arrow.2.squarepath"
}
}
}
var body: some View {
ScrollView {
VStack(spacing: 0) {
heroSection
mainContent
}
}
.frame(minWidth: 600, minHeight: 500)
.background(Color(NSColor.controlBackgroundColor))
}
private var heroSection: some View {
VStack(spacing: 24) {
Image(systemName: "brain.filled.head.profile")
.font(.system(size: 40))
.foregroundStyle(.blue)
.padding(20)
.background(Circle()
.fill(Color(.windowBackgroundColor).opacity(0.9))
.shadow(color: .black.opacity(0.1), radius: 10, y: 5))
VStack(spacing: 8) {
Text("Dictionary Settings")
.font(.system(size: 28, weight: .bold))
Text("Enhance VoiceInk's transcription accuracy by teaching it your vocabulary")
.font(.system(size: 15))
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
.frame(maxWidth: 400)
}
}
.padding(.vertical, 40)
.frame(maxWidth: .infinity)
}
private var mainContent: some View {
VStack(spacing: 40) {
sectionSelector
selectedSectionContent
}
.padding(.horizontal, 32)
.padding(.vertical, 40)
}
private var sectionSelector: some View {
VStack(alignment: .leading, spacing: 20) {
Text("Select Section")
.font(.title2)
.fontWeight(.semibold)
HStack(spacing: 20) {
ForEach(DictionarySection.allCases, id: \.self) { section in
SectionCard(
section: section,
isSelected: selectedSection == section,
action: { selectedSection = section }
)
}
}
}
}
private var selectedSectionContent: some View {
VStack(alignment: .leading, spacing: 20) {
switch selectedSection {
case .spellings:
DictionaryView(whisperPrompt: whisperPrompt)
.background(CardBackground(isSelected: false))
case .replacements:
WordReplacementView()
.background(CardBackground(isSelected: false))
}
}
}
}
struct SectionCard: View {
let section: DictionarySettingsView.DictionarySection
let isSelected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
VStack(alignment: .leading, spacing: 12) {
Image(systemName: section.icon)
.font(.system(size: 28))
.symbolRenderingMode(.hierarchical)
.foregroundStyle(isSelected ? .blue : .secondary)
VStack(alignment: .leading, spacing: 4) {
Text(section.rawValue)
.font(.headline)
Text(section.description)
.font(.subheadline)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
.background(CardBackground(isSelected: isSelected))
}
.buttonStyle(.plain)
}
}