File size: 1,394 Bytes
b8370f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import SwiftUI

struct ChatCompletedWorkDisclosure<Content: View>: View {
    let work: ChatTranscriptRow.CompletedWork
    @ViewBuilder let messageContent: (OpenClawChatMessage) -> Content
    @State private var isExpanded = false

    var body: some View {
        DisclosureGroup(isExpanded: self.$isExpanded) {
            VStack(alignment: .leading, spacing: 12) {
                ForEach(self.work.messages) { message in
                    self.messageContent(message)
                }
            }
            .padding(.top, 8)
        } label: {
            Text(self.label)
                .font(OpenClawChatTypography.caption)
                #if os(iOS)
                .foregroundStyle(Color.secondary)
                .frame(minHeight: 44)
                #else
                .foregroundStyle(.secondary)
                #endif
        }
        .accessibilityIdentifier("chat-completed-work-\(self.work.anchorID)")
        .frame(maxWidth: .infinity, alignment: .leading)
    }

    private var label: String {
        guard let milliseconds = self.work.durationMilliseconds else { return String(localized: "Worked") }
        let duration = Duration.seconds(max(1, (milliseconds / 1000).rounded()))
            .formatted(.units(allowed: [.hours, .minutes, .seconds], width: .abbreviated))
        return String(format: String(localized: "Worked for %@"), duration)
    }
}