11import SwiftUI
22
3- struct CustomDomainsSubsetSection : View {
4- let available : [ String ]
3+ struct CustomDomainSubsetRow : View {
4+ let domain : String
55 @ Binding var selected : [ String ]
6+ var isEditable : Bool = true
67
7- var body : some View {
8- Section {
9- if available . isEmpty {
10- Text ( " No custom domains yet. Add them in App Select. " )
11- . foregroundStyle ( . secondary )
12- } else {
13- ForEach ( available , id : \. self ) { domain in
14- row ( for : domain )
15- }
16- }
17- } header : {
18- Text ( " Custom Domains " )
19- }
20- }
8+ private var isOn : Bool { selected . contains ( domain ) }
219
22- private func row ( for domain : String ) -> some View {
23- let isOn = selected . contains ( domain )
24- return Button {
25- toggle ( domain )
26- } label : {
10+ var body : some View {
11+ Button ( action : toggle ) {
2712 HStack ( spacing : DS . Spacing . md ) {
2813 Image ( systemName : isOn ? " checkmark.circle.fill " : " circle " )
2914 . font ( . title2 )
@@ -34,15 +19,81 @@ struct CustomDomainsSubsetSection: View {
3419 . contentShape ( . rect )
3520 }
3621 . buttonStyle ( . plain )
22+ . disabled ( ! isEditable )
3723 . sensoryFeedback ( . selection , trigger : isOn )
3824 . accessibilityIdentifier ( " customDomains.row. \( domain ) " )
3925 }
4026
41- private func toggle ( _ domain : String ) {
27+ private func toggle ( ) {
4228 if let index = selected . firstIndex ( of : domain ) {
4329 selected . remove ( at : index )
4430 } else {
4531 selected . append ( domain )
4632 }
4733 }
4834}
35+
36+ struct CustomDomainsSubsetSection : View {
37+ let available : [ String ]
38+ @ Binding var selected : [ String ]
39+
40+ var body : some View {
41+ Section ( " Custom Domains " ) {
42+ if available . isEmpty {
43+ Text ( " No custom domains yet. Add them in App Select. " )
44+ . foregroundStyle ( . secondary )
45+ } else {
46+ ForEach ( available , id : \. self ) { domain in
47+ CustomDomainSubsetRow ( domain : domain , selected : $selected )
48+ }
49+ }
50+ }
51+ }
52+ }
53+
54+ struct CustomDomainsSubsetLink : View {
55+ let available : [ String ]
56+ @ Binding var selected : [ String ]
57+ var isEditable : Bool = true
58+
59+ private var effectiveCount : Int {
60+ CustomDomains . subset ( selected , of : available ) . count
61+ }
62+
63+ var body : some View {
64+ NavigationLink {
65+ CustomDomainsSubsetEditor ( available : available , selected : $selected , isEditable : isEditable )
66+ } label : {
67+ CountRow ( title : " Custom Domains " , count : effectiveCount )
68+ . opacity ( isEditable ? 1 : DS . Opacity . dim )
69+ }
70+ . accessibilityIdentifier ( " customDomains.subsetLink " )
71+ }
72+ }
73+
74+ struct CustomDomainsSubsetEditor : View {
75+ let available : [ String ]
76+ @ Binding var selected : [ String ]
77+ var isEditable : Bool = true
78+
79+ var body : some View {
80+ Form {
81+ Section {
82+ if available . isEmpty {
83+ Text ( " No custom domains yet. Add them in App Select. " )
84+ . foregroundStyle ( . secondary )
85+ } else {
86+ ForEach ( available , id : \. self ) { domain in
87+ CustomDomainSubsetRow ( domain : domain , selected : $selected , isEditable : isEditable )
88+ }
89+ }
90+ } footer : {
91+ if ! isEditable {
92+ Text ( BlockedMessage . customDomains )
93+ }
94+ }
95+ }
96+ . navigationTitle ( " Custom Domains " )
97+ . navigationBarTitleDisplayMode ( . inline )
98+ }
99+ }
0 commit comments