skill-web 0.3.0

Web interface for Skill Engine - built with Yew and WebAssembly
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
//! Settings page with full API integration
//!
//! Provides configuration for:
//! - Appearance (theme)
//! - Execution defaults (timeout, metadata, history)
//! - Search pipeline (embedding provider, vector store, hybrid search, reranking)
//! - Data management (import/export, clear history)

use std::rc::Rc;
use wasm_bindgen_futures::spawn_local;
use yew::prelude::*;
use yewdux::prelude::*;

use crate::api::{
    Api, AppConfig, SearchConfigResponse, UpdateSearchConfigRequest,
};
use crate::components::card::Card;
use crate::components::{use_import_config_modal, use_notifications, ImportConfigModal, Tooltip};
use crate::store::ui::{UiAction, UiStore};

/// Settings state
#[derive(Clone, PartialEq)]
struct SettingsState {
    // Appearance
    theme: String,
    // Execution
    default_timeout_secs: u64,
    max_concurrent_executions: usize,
    include_metadata: bool,
    enable_history: bool,
    max_history_entries: usize,
    // Search
    embedding_provider: String,
    embedding_model: String,
    vector_backend: String,
    ollama_url: Option<String>,
    qdrant_url: Option<String>,
    hybrid_search_enabled: bool,
    reranking_enabled: bool,
    indexed_documents: usize,
    // Advanced embedding model override
    use_advanced_model: bool,
    // Agent
    agent_runtime: String,
    agent_provider: String,
    agent_model: String,
    agent_temperature: f32,
    agent_max_tokens: usize,
    agent_timeout_secs: u64,
}

impl Default for SettingsState {
    fn default() -> Self {
        Self {
            theme: "system".to_string(),
            default_timeout_secs: 30,
            max_concurrent_executions: 10,
            include_metadata: false,
            enable_history: true,
            max_history_entries: 1000,
            embedding_provider: "fastembed".to_string(),
            embedding_model: "all-minilm".to_string(),
            vector_backend: "file".to_string(),
            ollama_url: Some("http://localhost:11434".to_string()),
            qdrant_url: Some("http://localhost:6333".to_string()),
            hybrid_search_enabled: true,
            reranking_enabled: false,
            indexed_documents: 0,
            use_advanced_model: false,
            agent_runtime: "claude-code".to_string(),
            agent_provider: "anthropic".to_string(),
            agent_model: "claude-sonnet-4".to_string(),
            agent_temperature: 0.7,
            agent_max_tokens: 4096,
            agent_timeout_secs: 300,
        }
    }
}

impl SettingsState {
    fn from_config(config: &AppConfig) -> Self {
        // Check if model is a non-standard value (advanced)
        let model = &config.search.embedding_model;
        let provider = &config.search.embedding_provider;
        let is_standard_model = Self::is_standard_model(provider, model);

        Self {
            theme: "system".to_string(),
            default_timeout_secs: config.default_timeout_secs,
            max_concurrent_executions: config.max_concurrent_executions,
            include_metadata: false,
            enable_history: config.enable_history,
            max_history_entries: config.max_history_entries,
            embedding_provider: provider.clone(),
            embedding_model: model.clone(),
            vector_backend: config.search.vector_backend.clone(),
            ollama_url: Some("http://localhost:11434".to_string()),
            qdrant_url: Some("http://localhost:6333".to_string()),
            hybrid_search_enabled: config.search.hybrid_search_enabled,
            reranking_enabled: config.search.reranking_enabled,
            indexed_documents: config.search.indexed_documents,
            use_advanced_model: !is_standard_model,
            // Agent defaults (not user-configurable anymore)
            agent_runtime: "claude-code".to_string(),
            agent_provider: "anthropic".to_string(),
            agent_model: "claude-sonnet-4".to_string(),
            agent_temperature: 0.7,
            agent_max_tokens: 4096,
            agent_timeout_secs: 300,
        }
    }

    fn is_standard_model(provider: &str, model: &str) -> bool {
        match provider {
            "fastembed" => matches!(model, "all-minilm" | "bge-small" | "bge-base" | "bge-large"),
            "openai" => matches!(model, "text-embedding-ada-002" | "text-embedding-3-small" | "text-embedding-3-large"),
            "ollama" => matches!(model, "nomic-embed-text" | "mxbai-embed-large" | "all-minilm"),
            _ => false,
        }
    }

    fn get_default_model(provider: &str) -> &'static str {
        match provider {
            "fastembed" => "all-minilm",
            "openai" => "text-embedding-3-small",
            "ollama" => "nomic-embed-text",
            _ => "all-minilm",
        }
    }
}

/// Test result for vector DB testing
#[derive(Clone, PartialEq)]
struct TestResult {
    success: bool,
    message: String,
    duration_ms: u128,
    details: Option<String>,
}

/// Settings page component
#[function_component(SettingsPage)]
pub fn settings_page() -> Html {
    let (_, ui_dispatch) = use_store::<UiStore>();
    let notifications = use_notifications();
    let import_modal = use_import_config_modal();

    // API client
    let api = use_memo((), |_| Rc::new(Api::new()));

    // State
    let settings = use_state(SettingsState::default);
    let loading = use_state(|| true);
    let saving = use_state(|| false);
    let error = use_state(|| Option::<String>::None);
    let has_changes = use_state(|| false);

    // Vector DB testing state
    let test_connection_loading = use_state(|| false);
    let test_pipeline_loading = use_state(|| false);
    let test_result = use_state(|| Option::<TestResult>::None);

    // Load settings on mount
    {
        let api = api.clone();
        let settings = settings.clone();
        let loading = loading.clone();
        let error = error.clone();

        use_effect_with((), move |_| {
            spawn_local(async move {
                match api.config.get().await {
                    Ok(config) => {
                        settings.set(SettingsState::from_config(&config));
                        loading.set(false);
                    }
                    Err(e) => {
                        error.set(Some(e.to_string()));
                        loading.set(false);
                    }
                }
            });
        });
    }

    // Theme change handler
    let on_theme_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        let ui_dispatch = ui_dispatch.clone();
        Callback::from(move |value: String| {
            let mut new_settings = (*settings).clone();
            new_settings.theme = value.clone();
            settings.set(new_settings);
            has_changes.set(true);
            // Apply theme immediately
            ui_dispatch.apply(UiAction::SetDarkMode(value == "dark"));
        })
    };

    // Timeout change handler
    let on_timeout_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            if let Ok(value) = input.value().parse::<u64>() {
                let mut new_settings = (*settings).clone();
                new_settings.default_timeout_secs = value;
                settings.set(new_settings);
                has_changes.set(true);
            }
        })
    };

    // Max concurrent change handler
    let on_max_concurrent_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            if let Ok(value) = input.value().parse::<usize>() {
                let mut new_settings = (*settings).clone();
                new_settings.max_concurrent_executions = value;
                settings.set(new_settings);
                has_changes.set(true);
            }
        })
    };

    // History entries change handler
    let on_history_entries_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            if let Ok(value) = input.value().parse::<usize>() {
                let mut new_settings = (*settings).clone();
                new_settings.max_history_entries = value;
                settings.set(new_settings);
                has_changes.set(true);
            }
        })
    };

    // Enable history toggle
    let on_enable_history_toggle = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |_: MouseEvent| {
            let mut new_settings = (*settings).clone();
            new_settings.enable_history = !new_settings.enable_history;
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Include metadata toggle
    let on_include_metadata_toggle = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |_: MouseEvent| {
            let mut new_settings = (*settings).clone();
            new_settings.include_metadata = !new_settings.include_metadata;
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Embedding provider change
    let on_embedding_provider_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: Event| {
            let select: web_sys::HtmlSelectElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            let new_provider = select.value();
            new_settings.embedding_provider = new_provider.clone();

            // Auto-set default model for new provider if not in advanced mode
            if !new_settings.use_advanced_model {
                new_settings.embedding_model = SettingsState::get_default_model(&new_provider).to_string();
            }

            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Vector backend change
    let on_vector_backend_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: Event| {
            let select: web_sys::HtmlSelectElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            new_settings.vector_backend = select.value();
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Embedding model dropdown change (for standard models)
    let on_embedding_model_select = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: Event| {
            let select: web_sys::HtmlSelectElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            new_settings.embedding_model = select.value();
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Embedding model text input change (for advanced/custom models)
    let on_embedding_model_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            new_settings.embedding_model = input.value();
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Toggle advanced model mode
    let on_advanced_model_toggle = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |_: MouseEvent| {
            let mut new_settings = (*settings).clone();
            new_settings.use_advanced_model = !new_settings.use_advanced_model;

            // If switching to standard mode, set default model for current provider
            if !new_settings.use_advanced_model {
                new_settings.embedding_model = SettingsState::get_default_model(&new_settings.embedding_provider).to_string();
            }

            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Ollama URL change
    let on_ollama_url_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            new_settings.ollama_url = Some(input.value());
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Qdrant URL change
    let on_qdrant_url_change = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |e: InputEvent| {
            let input: web_sys::HtmlInputElement = e.target_unchecked_into();
            let mut new_settings = (*settings).clone();
            new_settings.qdrant_url = Some(input.value());
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Hybrid search toggle
    let on_hybrid_toggle = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |_: MouseEvent| {
            let mut new_settings = (*settings).clone();
            new_settings.hybrid_search_enabled = !new_settings.hybrid_search_enabled;
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Reranking toggle
    let on_reranking_toggle = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        Callback::from(move |_: MouseEvent| {
            let mut new_settings = (*settings).clone();
            new_settings.reranking_enabled = !new_settings.reranking_enabled;
            settings.set(new_settings);
            has_changes.set(true);
        })
    };

    // Save changes handler
    let on_save = {
        let api = api.clone();
        let settings = settings.clone();
        let saving = saving.clone();
        let has_changes = has_changes.clone();
        let notifications = notifications.clone();

        Callback::from(move |_: MouseEvent| {
            let current_settings = (*settings).clone();
            saving.set(true);

            let api = api.clone();
            let saving = saving.clone();
            let has_changes = has_changes.clone();
            let notifications = notifications.clone();

            spawn_local(async move {
                // Update app config
                let app_result = api
                    .config
                    .update(&crate::api::UpdateAppConfigRequest {
                        default_timeout_secs: Some(current_settings.default_timeout_secs),
                        max_concurrent_executions: Some(current_settings.max_concurrent_executions),
                        enable_history: Some(current_settings.enable_history),
                        max_history_entries: Some(current_settings.max_history_entries),
                    })
                    .await;

                // Update search config
                let search_result = api
                    .config
                    .update_search_config(&UpdateSearchConfigRequest {
                        embedding_provider: Some(current_settings.embedding_provider),
                        embedding_model: None,
                        vector_backend: Some(current_settings.vector_backend),
                        enable_hybrid: Some(current_settings.hybrid_search_enabled),
                        enable_reranking: Some(current_settings.reranking_enabled),
                    })
                    .await;

                saving.set(false);

                match (app_result, search_result) {
                    (Ok(_), Ok(_)) => {
                        has_changes.set(false);
                        notifications.success("Settings Saved", "Your settings have been updated");
                    }
                    (Err(e), _) | (_, Err(e)) => {
                        notifications.error("Save Failed", &e.to_string());
                    }
                }
            });
        })
    };

    // Reset to defaults handler
    let on_reset = {
        let settings = settings.clone();
        let has_changes = has_changes.clone();
        let notifications = notifications.clone();

        Callback::from(move |_: MouseEvent| {
            settings.set(SettingsState {
                theme: "system".to_string(),
                default_timeout_secs: 30,
                max_concurrent_executions: 4,
                include_metadata: false,
                enable_history: true,
                max_history_entries: 1000,
                embedding_provider: "fastembed".to_string(),
                embedding_model: "all-minilm".to_string(),
                vector_backend: "file".to_string(),
                ollama_url: Some("http://localhost:11434".to_string()),
                qdrant_url: Some("http://localhost:6333".to_string()),
                hybrid_search_enabled: false,
                reranking_enabled: false,
                indexed_documents: 0,
                use_advanced_model: false,
                // Agent defaults
                agent_runtime: "claude-code".to_string(),
                agent_provider: "anthropic".to_string(),
                agent_model: "claude-sonnet-4".to_string(),
                agent_temperature: 0.7,
                agent_max_tokens: 4096,
                agent_timeout_secs: 300,
            });
            has_changes.set(true);
            notifications.info("Settings Reset", "Settings have been reset to defaults");
        })
    };

    // Test connection handler (quick validation)
    let on_test_connection = {
        let api = api.clone();
        let settings = settings.clone();
        let test_connection_loading = test_connection_loading.clone();
        let test_result = test_result.clone();
        let notifications = notifications.clone();

        Callback::from(move |_: MouseEvent| {
            test_connection_loading.set(true);
            test_result.set(None);

            let api = api.clone();
            let settings = (*settings).clone();
            let test_connection_loading = test_connection_loading.clone();
            let test_result = test_result.clone();
            let notifications = notifications.clone();

            spawn_local(async move {
                let request = crate::api::TestConnectionRequest {
                    embedding_provider: settings.embedding_provider,
                    embedding_model: settings.embedding_model,
                    vector_backend: settings.vector_backend,
                    qdrant_url: settings.qdrant_url.clone(),
                    ollama_url: settings.ollama_url.clone(),
                };

                match api.search.test_connection(&request).await {
                    Ok(response) => {
                        let details = format!(
                            "Embedding: {} | Backend: {}",
                            if response.embedding_provider_status.healthy { "✓" } else { "✗" },
                            if response.vector_backend_status.healthy { "✓" } else { "✗" }
                        );

                        let success = response.success;
                        let duration_ms = response.duration_ms;
                        let message = response.message.clone();

                        test_result.set(Some(TestResult {
                            success,
                            message: message.clone(),
                            duration_ms,
                            details: Some(details),
                        }));

                        if success {
                            notifications.success(
                                "Connection Test Passed",
                                &format!("All components healthy ({}ms)", duration_ms)
                            );
                        } else {
                            notifications.error("Connection Test Failed", &message);
                        }
                    }
                    Err(e) => {
                        notifications.error("Test Failed", &format!("Error: {}", e));
                        test_result.set(Some(TestResult {
                            success: false,
                            message: format!("Error: {}", e),
                            duration_ms: 0,
                            details: None,
                        }));
                    }
                }
                test_connection_loading.set(false);
            });
        })
    };

    // Test pipeline handler (full test with indexing)
    let on_test_pipeline = {
        let api = api.clone();
        let settings = settings.clone();
        let test_pipeline_loading = test_pipeline_loading.clone();
        let test_result = test_result.clone();
        let notifications = notifications.clone();

        Callback::from(move |_: MouseEvent| {
            test_pipeline_loading.set(true);
            test_result.set(None);

            let api = api.clone();
            let settings = (*settings).clone();
            let test_pipeline_loading = test_pipeline_loading.clone();
            let test_result = test_result.clone();
            let notifications = notifications.clone();

            spawn_local(async move {
                let request = crate::api::TestPipelineRequest {
                    embedding_provider: settings.embedding_provider,
                    embedding_model: settings.embedding_model,
                    vector_backend: settings.vector_backend,
                    enable_hybrid: settings.hybrid_search_enabled,
                    enable_reranking: settings.reranking_enabled,
                    qdrant_url: settings.qdrant_url.clone(),
                };

                match api.search.test_pipeline(&request).await {
                    Ok(response) => {
                        let details = format!(
                            "Indexed {} docs | Found {} results",
                            response.index_stats.documents_indexed,
                            response.search_results.len()
                        );

                        let success = response.success;
                        let duration_ms = response.duration_ms;
                        let message = response.message.clone();

                        test_result.set(Some(TestResult {
                            success,
                            message: message.clone(),
                            duration_ms,
                            details: Some(details),
                        }));

                        if success {
                            notifications.success(
                                "Pipeline Test Passed",
                                &format!("Pipeline working correctly ({}ms)", duration_ms)
                            );
                        } else {
                            notifications.error("Pipeline Test Failed", &message);
                        }
                    }
                    Err(e) => {
                        notifications.error("Test Failed", &format!("Error: {}", e));
                        test_result.set(Some(TestResult {
                            success: false,
                            message: format!("Error: {}", e),
                            duration_ms: 0,
                            details: None,
                        }));
                    }
                }
                test_pipeline_loading.set(false);
            });
        })
    };

    // Import config handler
    let on_import_click = {
        let import_modal = import_modal.clone();
        Callback::from(move |_: MouseEvent| {
            import_modal.open();
        })
    };

    // Reload settings after import
    let on_config_imported = {
        let api = api.clone();
        let settings = settings.clone();
        let notifications = notifications.clone();
        Callback::from(move |count: usize| {
            let api = api.clone();
            let settings = settings.clone();
            spawn_local(async move {
                if let Ok(config) = api.config.get().await {
                    settings.set(SettingsState::from_config(&config));
                }
            });
        })
    };

    // Clear history handler
    let on_clear_history = {
        let api = api.clone();
        let notifications = notifications.clone();
        Callback::from(move |_: MouseEvent| {
            let api = api.clone();
            let notifications = notifications.clone();

            // Show confirmation
            if !web_sys::window()
                .and_then(|w| w.confirm_with_message("Are you sure you want to clear all execution history? This cannot be undone.").ok())
                .unwrap_or(false)
            {
                return;
            }

            spawn_local(async move {
                match api.executions.clear_history().await {
                    Ok(_) => {
                        notifications.success("History Cleared", "Execution history cleared successfully");
                    }
                    Err(e) => {
                        notifications.error("Clear Failed", &format!("Failed to clear history: {}", e));
                    }
                }
            });
        })
    };

    // Current settings
    let current = (*settings).clone();

    html! {
        <div class="space-y-6 animate-fade-in">
            // Import Config Modal
            <ImportConfigModal on_imported={on_config_imported} />

            // Page header
            <div class="flex items-center justify-between">
                <div>
                    <h1 class="text-2xl font-bold text-gray-900 dark:text-white">
                        { "Settings" }
                    </h1>
                    <p class="text-gray-500 dark:text-gray-400 mt-1">
                        { "Configure your Skill Engine preferences" }
                    </p>
                </div>
                if *has_changes {
                    <div class="flex items-center gap-2 px-3 py-1 bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300 rounded-full text-sm">
                        <svg class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
                        </svg>
                        { "Unsaved changes" }
                    </div>
                }
            </div>

            // Error alert
            if let Some(err) = (*error).clone() {
                <div class="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4">
                    <div class="flex items-center gap-3">
                        <svg class="w-5 h-5 text-red-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
                        </svg>
                        <p class="text-sm text-red-700 dark:text-red-300">{ err }</p>
                    </div>
                </div>
            }

            // Loading state
            if *loading {
                <div class="space-y-6">
                    { for (0..4).map(|_| html! { <SettingsCardSkeleton /> }) }
                </div>
            } else {
                // Appearance settings
                <Card title="Appearance">
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
                                { "Theme" }
                            </label>
                            <div class="flex gap-4">
                                { for ["light", "dark", "system"].iter().map(|t| {
                                    let is_selected = current.theme == *t;
                                    let on_change = on_theme_change.clone();
                                    let value = t.to_string();

                                    html! {
                                        <button
                                            onclick={Callback::from(move |_: MouseEvent| on_change.emit(value.clone()))}
                                            class={classes!(
                                                "flex", "items-center", "gap-2", "px-4", "py-2", "rounded-lg", "border", "cursor-pointer", "transition-colors",
                                                if is_selected {
                                                    "border-primary-500 bg-primary-50 dark:bg-primary-900/30"
                                                } else {
                                                    "border-gray-200 dark:border-gray-700 hover:border-gray-300"
                                                }
                                            )}
                                        >
                                            <span class="capitalize">{ *t }</span>
                                        </button>
                                    }
                                }) }
                            </div>
                        </div>
                    </div>
                </Card>

                // Execution settings
                <Card title="Execution">
                    <div class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Default timeout (seconds)" }
                                </label>
                                <input
                                    type="number"
                                    class="input w-full"
                                    value={current.default_timeout_secs.to_string()}
                                    min="1"
                                    max="300"
                                    oninput={on_timeout_change}
                                />
                                <p class="text-xs text-gray-500 mt-1">
                                    { "Maximum time a skill can run (1-300 seconds)" }
                                </p>
                            </div>

                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Max concurrent executions" }
                                </label>
                                <input
                                    type="number"
                                    class="input w-full"
                                    value={current.max_concurrent_executions.to_string()}
                                    min="1"
                                    max="16"
                                    oninput={on_max_concurrent_change}
                                />
                                <p class="text-xs text-gray-500 mt-1">
                                    { "Number of skills that can run in parallel (1-16)" }
                                </p>
                            </div>
                        </div>

                        <div class="space-y-3 pt-2">
                            <ToggleSwitch
                                label="Include execution metadata by default"
                                description="Attach timing and environment info to results"
                                checked={current.include_metadata}
                                on_toggle={on_include_metadata_toggle}
                            />

                            <ToggleSwitch
                                label="Enable execution history"
                                description="Track and store execution history for analysis"
                                checked={current.enable_history}
                                on_toggle={on_enable_history_toggle}
                            />
                        </div>
                    </div>
                </Card>

                // Search pipeline settings
                <Card title="Search Pipeline">
                    <div class="space-y-4">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            <div>
                                <label class="flex items-center text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Embedding Provider" }
                                    <Tooltip text="Converts text into numerical vectors for semantic search. FastEmbed runs locally, OpenAI uses API, Ollama is self-hosted." />
                                </label>
                                <select
                                    class="input w-full"
                                    value={current.embedding_provider.clone()}
                                    onchange={on_embedding_provider_change}
                                >
                                    <option value="fastembed" selected={current.embedding_provider == "fastembed"}>
                                        { "FastEmbed (Local)" }
                                    </option>
                                    <option value="openai" selected={current.embedding_provider == "openai"}>
                                        { "OpenAI" }
                                    </option>
                                    <option value="ollama" selected={current.embedding_provider == "ollama"}>
                                        { "Ollama" }
                                    </option>
                                </select>
                                <p class="text-xs text-gray-500 mt-1">
                                    { "FastEmbed runs locally with no API key required" }
                                </p>
                            </div>

                            <div>
                                <label class="flex items-center text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Vector Store" }
                                    <Tooltip text="Database for storing and searching document embeddings. File-based is persistent and fast. InMemory is faster but data is lost on restart. Qdrant requires Docker." />
                                </label>
                                <select
                                    class="input w-full"
                                    value={current.vector_backend.clone()}
                                    onchange={on_vector_backend_change}
                                >
                                    <option value="file" selected={current.vector_backend == "file"}>
                                        { "File-based (Persistent)" }
                                    </option>
                                    <option value="memory" selected={current.vector_backend == "memory"}>
                                        { "In-Memory" }
                                    </option>
                                    <option value="qdrant" selected={current.vector_backend == "qdrant"}>
                                        { "Qdrant (Docker)" }
                                    </option>
                                </select>
                                <p class="text-xs text-gray-500 mt-1">
                                    { "File-based stores vectors locally with persistence. In-memory is fastest but temporary." }
                                </p>
                            </div>
                        </div>

                        // Embedding Model selection
                        <div>
                            <div class="flex items-center justify-between mb-2">
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300">
                                    { "Embedding Model" }
                                </label>
                                <button
                                    type="button"
                                    class="text-xs text-primary-600 dark:text-primary-400 hover:underline"
                                    onclick={on_advanced_model_toggle}
                                >
                                    { if current.use_advanced_model { "Use Standard Models" } else { "Advanced (Custom Model)" } }
                                </button>
                            </div>

                            if current.use_advanced_model {
                                // Advanced: Free-form text input
                                <input
                                    type="text"
                                    class="input w-full font-mono text-sm"
                                    value={current.embedding_model.clone()}
                                    oninput={on_embedding_model_change}
                                    placeholder={
                                        match current.embedding_provider.as_str() {
                                            "fastembed" => "all-minilm",
                                            "openai" => "text-embedding-3-small",
                                            "ollama" => "nomic-embed-text",
                                            _ => "model-name"
                                        }
                                    }
                                />
                                <p class="text-xs text-gray-500 mt-1">
                                    { "Enter a custom embedding model name" }
                                </p>
                            } else {
                                // Standard: Dropdown with predefined models
                                <select
                                    class="input w-full"
                                    value={current.embedding_model.clone()}
                                    onchange={on_embedding_model_select}
                                >
                                    { match current.embedding_provider.as_str() {
                                        "fastembed" => html! {
                                            <>
                                                <option value="all-minilm" selected={current.embedding_model == "all-minilm"}>
                                                    { "all-MiniLM (384 dims) - Recommended" }
                                                </option>
                                                <option value="bge-small" selected={current.embedding_model == "bge-small"}>
                                                    { "BGE-Small (384 dims)" }
                                                </option>
                                                <option value="bge-base" selected={current.embedding_model == "bge-base"}>
                                                    { "BGE-Base (768 dims)" }
                                                </option>
                                                <option value="bge-large" selected={current.embedding_model == "bge-large"}>
                                                    { "BGE-Large (1024 dims)" }
                                                </option>
                                            </>
                                        },
                                        "openai" => html! {
                                            <>
                                                <option value="text-embedding-3-small" selected={current.embedding_model == "text-embedding-3-small"}>
                                                    { "text-embedding-3-small (1536 dims) - Recommended" }
                                                </option>
                                                <option value="text-embedding-3-large" selected={current.embedding_model == "text-embedding-3-large"}>
                                                    { "text-embedding-3-large (3072 dims)" }
                                                </option>
                                                <option value="text-embedding-ada-002" selected={current.embedding_model == "text-embedding-ada-002"}>
                                                    { "text-embedding-ada-002 (1536 dims) - Legacy" }
                                                </option>
                                            </>
                                        },
                                        "ollama" => html! {
                                            <>
                                                <option value="nomic-embed-text" selected={current.embedding_model == "nomic-embed-text"}>
                                                    { "nomic-embed-text - Recommended" }
                                                </option>
                                                <option value="mxbai-embed-large" selected={current.embedding_model == "mxbai-embed-large"}>
                                                    { "mxbai-embed-large" }
                                                </option>
                                                <option value="all-minilm" selected={current.embedding_model == "all-minilm"}>
                                                    { "all-minilm" }
                                                </option>
                                            </>
                                        },
                                        _ => html! {
                                            <option value="all-minilm">{ "all-minilm" }</option>
                                        }
                                    }}
                                </select>
                                <p class="text-xs text-gray-500 mt-1">
                                    { "Select from recommended models for " }
                                    <span class="capitalize">{ current.embedding_provider.clone() }</span>
                                </p>
                            }
                        </div>

                        // Conditional Ollama URL input (only shown when provider = "ollama")
                        if current.embedding_provider == "ollama" {
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Ollama Server URL" }
                                </label>
                                <input
                                    type="text"
                                    class="input w-full font-mono text-sm"
                                    value={current.ollama_url.clone().unwrap_or_else(|| "http://localhost:11434".to_string())}
                                    oninput={on_ollama_url_change}
                                    placeholder="http://localhost:11434"
                                />
                                <p class="text-xs text-gray-500 mt-1">
                                    { "URL of your Ollama server instance" }
                                </p>
                            </div>
                        }

                        // Conditional Qdrant URL input (only shown when backend = "qdrant")
                        if current.vector_backend == "qdrant" {
                            <div>
                                <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                    { "Qdrant Server URL" }
                                </label>
                                <input
                                    type="text"
                                    class="input w-full font-mono text-sm"
                                    value={current.qdrant_url.clone().unwrap_or_else(|| "http://localhost:6333".to_string())}
                                    oninput={on_qdrant_url_change}
                                    placeholder="http://localhost:6333"
                                />
                                <p class="text-xs text-gray-500 mt-1">
                                    { "URL of your Qdrant server instance (requires Docker)" }
                                </p>
                            </div>
                        }

                        <div class="p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
                            <div class="flex items-center justify-between text-sm">
                                <span class="text-gray-600 dark:text-gray-400">{ "Indexed Documents" }</span>
                                <span class="font-mono text-gray-900 dark:text-white">{ current.indexed_documents }</span>
                            </div>
                        </div>

                        // Vector DB Testing Section
                        <div class="border-t border-gray-200 dark:border-gray-700 pt-4 mt-4">
                            <h4 class="text-sm font-medium text-gray-900 dark:text-white mb-3">
                                { "Connection Testing" }
                            </h4>
                            <p class="text-xs text-gray-600 dark:text-gray-400 mb-3">
                                { "Test your embedding provider and vector backend configuration before saving." }
                            </p>

                            <div class="flex gap-2">
                                <button
                                    class="btn btn-secondary text-sm"
                                    onclick={on_test_connection}
                                    disabled={*test_connection_loading || *loading}
                                >
                                    if *test_connection_loading {
                                        <span class="flex items-center gap-2">
                                            <span class="animate-spin">{ "⟳" }</span>
                                            { "Testing..." }
                                        </span>
                                    } else {
                                        { "Quick Test" }
                                    }
                                </button>

                                <button
                                    class="btn btn-secondary text-sm"
                                    onclick={on_test_pipeline}
                                    disabled={*test_pipeline_loading || *loading}
                                >
                                    if *test_pipeline_loading {
                                        <span class="flex items-center gap-2">
                                            <span class="animate-spin">{ "⟳" }</span>
                                            { "Testing..." }
                                        </span>
                                    } else {
                                        { "Full Pipeline Test" }
                                    }
                                </button>
                            </div>

                            // Test result display
                            if let Some(result) = &*test_result {
                                <div class={classes!(
                                    "mt-3", "p-3", "rounded", "text-sm",
                                    if result.success {
                                        "bg-success-50 dark:bg-success-900/20 border border-success-200 dark:border-success-800"
                                    } else {
                                        "bg-error-50 dark:bg-error-900/20 border border-error-200 dark:border-error-800"
                                    }
                                )}>
                                    <div class="flex items-start gap-2">
                                        if result.success {
                                            <svg class="w-4 h-4 text-success-500 flex-shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
                                            </svg>
                                        } else {
                                            <svg class="w-4 h-4 text-error-500 flex-shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
                                            </svg>
                                        }
                                        <div class="flex-1">
                                            <p class={classes!(
                                                "font-medium",
                                                if result.success { "text-success-700 dark:text-success-300" }
                                                else { "text-error-700 dark:text-error-300" }
                                            )}>
                                                { &result.message }
                                            </p>
                                            if let Some(details) = &result.details {
                                                <p class="text-xs mt-1 text-gray-600 dark:text-gray-400">
                                                    { details }
                                                </p>
                                            }
                                            <p class="text-xs mt-1 text-gray-500 dark:text-gray-500">
                                                { format!("Completed in {}ms", result.duration_ms) }
                                            </p>
                                        </div>
                                    </div>
                                </div>
                            }
                        </div>

                        <div class="space-y-3 pt-2">
                            <ToggleSwitch
                                label="Enable Hybrid Search"
                                description="Combines semantic (AI-based) and keyword (BM25) search for better results across different query types"
                                checked={current.hybrid_search_enabled}
                                on_toggle={on_hybrid_toggle}
                            />

                            <ToggleSwitch
                                label="Enable Reranking"
                                description="Re-orders results using cross-encoder model for better accuracy. Slower but more precise."
                                checked={current.reranking_enabled}
                                on_toggle={on_reranking_toggle}
                            />
                        </div>
                    </div>
                </Card>

                // Data settings
                <Card title="Data Management">
                    <div class="space-y-4">
                        <div>
                            <label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
                                { "History retention" }
                            </label>
                            <div class="flex items-center gap-2">
                                <input
                                    type="number"
                                    class="input w-32"
                                    value={current.max_history_entries.to_string()}
                                    min="100"
                                    max="10000"
                                    oninput={on_history_entries_change}
                                />
                                <span class="text-gray-500 dark:text-gray-400">{ "executions" }</span>
                            </div>
                            <p class="text-xs text-gray-500 mt-1">
                                { "Older entries will be automatically removed (100-10,000)" }
                            </p>
                        </div>

                        <div class="flex flex-wrap gap-3 pt-2">
                            <button class="btn btn-secondary" onclick={on_clear_history}>
                                <svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
                                </svg>
                                { "Clear History" }
                            </button>
                            <button class="btn btn-secondary">
                                <svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
                                </svg>
                                { "Export Config" }
                            </button>
                            <button class="btn btn-secondary" onclick={on_import_click}>
                                <svg class="w-4 h-4 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
                                </svg>
                                { "Import Config" }
                            </button>
                        </div>
                    </div>
                </Card>

                // About section
                <Card title="About">
                    <div class="space-y-3">
                        <div class="flex justify-between py-1">
                            <span class="text-gray-500 dark:text-gray-400">{ "Version" }</span>
                            <span class="font-mono text-gray-900 dark:text-white">{ "0.2.2" }</span>
                        </div>
                        <div class="flex justify-between py-1">
                            <span class="text-gray-500 dark:text-gray-400">{ "Build Date" }</span>
                            <span class="font-mono text-gray-900 dark:text-white">{ "2025-12-22" }</span>
                        </div>
                        <div class="flex justify-between py-1">
                            <span class="text-gray-500 dark:text-gray-400">{ "Embedding Model" }</span>
                            <span class="font-mono text-gray-900 dark:text-white">{ &current.embedding_model }</span>
                        </div>
                    </div>
                    <div class="mt-4 pt-4 border-t border-gray-200 dark:border-gray-700">
                        <a
                            href="https://github.com/your-repo/skill-engine"
                            target="_blank"
                            rel="noopener noreferrer"
                            class="btn btn-secondary"
                        >
                            <svg class="w-4 h-4 mr-2" fill="currentColor" viewBox="0 0 24 24">
                                <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
                            </svg>
                            { "View on GitHub" }
                        </a>
                    </div>
                </Card>

                // Save buttons
                <div class="flex justify-end gap-4 sticky bottom-6 bg-gray-50 dark:bg-gray-900 py-4 -mx-6 px-6 border-t border-gray-200 dark:border-gray-800">
                    <button
                        class="btn btn-secondary"
                        onclick={on_reset}
                        disabled={*saving}
                    >
                        { "Reset to Defaults" }
                    </button>
                    <button
                        class="btn btn-primary"
                        onclick={on_save}
                        disabled={!*has_changes || *saving}
                    >
                        if *saving {
                            <svg class="animate-spin -ml-1 mr-2 h-4 w-4" fill="none" viewBox="0 0 24 24">
                                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                            </svg>
                            { "Saving..." }
                        } else {
                            { "Save Changes" }
                        }
                    </button>
                </div>
            }
        </div>
    }
}

/// Toggle switch component props
#[derive(Properties, PartialEq)]
struct ToggleSwitchProps {
    label: &'static str,
    description: &'static str,
    checked: bool,
    on_toggle: Callback<MouseEvent>,
}

/// Toggle switch component
#[function_component(ToggleSwitch)]
fn toggle_switch(props: &ToggleSwitchProps) -> Html {
    html! {
        <div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
            <div>
                <p class="text-sm font-medium text-gray-900 dark:text-white">
                    { props.label }
                </p>
                <p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
                    { props.description }
                </p>
            </div>
            <button
                type="button"
                role="switch"
                aria-checked={props.checked.to_string()}
                onclick={props.on_toggle.clone()}
                class={classes!(
                    "relative", "inline-flex", "h-6", "w-11", "flex-shrink-0",
                    "cursor-pointer", "rounded-full", "border-2", "border-transparent",
                    "transition-colors", "duration-200", "ease-in-out",
                    "focus:outline-none", "focus:ring-2", "focus:ring-primary-500", "focus:ring-offset-2",
                    if props.checked { "bg-primary-600" } else { "bg-gray-200 dark:bg-gray-600" }
                )}
            >
                <span
                    class={classes!(
                        "pointer-events-none", "inline-block", "h-5", "w-5",
                        "transform", "rounded-full", "bg-white", "shadow",
                        "ring-0", "transition", "duration-200", "ease-in-out",
                        if props.checked { "translate-x-5" } else { "translate-x-0" }
                    )}
                />
            </button>
        </div>
    }
}

/// Skeleton loader for settings cards
#[function_component(SettingsCardSkeleton)]
fn settings_card_skeleton() -> Html {
    html! {
        <div class="card p-6 animate-pulse">
            <div class="h-5 w-32 bg-gray-200 dark:bg-gray-700 rounded mb-4"></div>
            <div class="space-y-4">
                <div class="h-10 w-full bg-gray-200 dark:bg-gray-700 rounded"></div>
                <div class="h-10 w-3/4 bg-gray-200 dark:bg-gray-700 rounded"></div>
            </div>
        </div>
    }
}