<commit_before>//
//  Created by <NAME> on 2021/01/13.
//
//  Copyright © 2020 Saturday Apps.
//
//  This file is part of Hipstapaper.
//
//  Hipstapaper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Hipstapaper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Hipstapaper.  If not, see <http://www.gnu.org/licenses/>.
//

import SwiftUI
import Localize

extension STZ {
    public enum ACTN {}
}

extension STZ.ACTN {
    public struct Modifier: ViewModifier {
        @Binding public var isPresented: Bool
        public let content: () -> Wrapper
        public func body(content: Content) -> some View {
            let nativeContent = { self.content().nativeValue }
            #if os(macOS)
            return content.popover(isPresented: self.$isPresented,
                                   content: nativeContent)
            #else
            return content.actionSheet(isPresented: self.$isPresented,
                                       content: nativeContent)
            #endif
        }
        public init(isPresented: Binding<Bool>, content: @escaping () -> Wrapper) {
            _isPresented = isPresented
            self.content = content
        }
    }
    
    public struct Wrapper {
        public struct Button {
            public enum Kind {
                case destructive, `default`, cancel
            }
            public var title: LocalizedStringKey
            public var kind: Kind
            public var action: () -> Void
            public init(title: LocalizedStringKey,
                        kind: Kind = .default,
                        action: @escaping () -> Void)
            {
                self.title = title
                self.kind = kind
                self.action = action
            }
        }
        
        public var title: LocalizedStringKey
        public var message: LocalizedStringKey? = nil
        public var buttons: [Button]
        
        public init(title: LocalizedStringKey,
                    message: LocalizedStringKey? = nil,
                    buttons: [Button])
        {
            self.title = title
            self.message = message
            self.buttons = buttons
        }
    }
}

#if os(macOS)
extension STZ.ACTN.Wrapper {
    internal var nativeValue: some View {
        VStack() {
            // TODO: Make this text wrap
            STZ.VIEW.TXT(self.title)
                .modifier(STZ.FNT.ACTN.Body.apply())
                .modifier(STZ.CLR.ACTN.Body.foreground())
                .lineLimit(2) // TODO: Remove hack when possible
                .fixedSize(horizontal: false, vertical: true) // TODO: Remove hack when possible
                .frame(maxWidth: 200)
            ForEach(0..<self.buttons.count, id: \.self) {
                self.buttons[$0].nativeValue
            }
        }
        .modifier(STZ.PDG.Equal())
    }
}

extension STZ.ACTN.Wrapper.Button {
    internal var nativeValue: some View {
        SwiftUI.Button(
            action: self.action,
            label: {
                STZ.VIEW.TXT(self.title)
                    .modifier(STZ.FNT.Button.Done.apply())
                    .modifier(STZ.CLR.ACTN.Button.foreground())
                    .frame(minWidth: 200, maxWidth: 200)
            }
        )
    }
}
#else
extension STZ.ACTN.Wrapper {
    internal var nativeValue: ActionSheet {
        SwiftUI.ActionSheet(
            title: Text(self.title),
            message: self.message.map { Text($0) },
            buttons: self.buttons
                .map { $0.nativeValue }
                + [.cancel(Text(Verb.Cancel))]
        )
    }
}

extension STZ.ACTN.Wrapper.Button {
    internal var nativeValue: Alert.Button {
        switch self.kind {
        case .cancel:
            return .cancel(Text(self.title),
                           action: self.action)
        case .default:
            return .default(Text(self.title),
                            action: self.action)
        case .destructive:
            return .destructive(Text(self.title),
                                action: self.action)
        }
    }
}
#endif
<commit_msg>made text wrap semi-properly<commit_after>//
//  Created by <NAME> on 2021/01/13.
//
//  Copyright © 2020 Saturday Apps.
//
//  This file is part of Hipstapaper.
//
//  Hipstapaper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  Hipstapaper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with Hipstapaper.  If not, see <http://www.gnu.org/licenses/>.
//

import SwiftUI
import Localize

extension STZ {
    public enum ACTN {}
}

extension STZ.ACTN {
    public struct Modifier: ViewModifier {
        @Binding public var isPresented: Bool
        public let content: () -> Wrapper
        public func body(content: Content) -> some View {
            let nativeContent = { self.content().nativeValue }
            #if os(macOS)
            return content.popover(isPresented: self.$isPresented,
                                   content: nativeContent)
            #else
            return content.actionSheet(isPresented: self.$isPresented,
                                       content: nativeContent)
            #endif
        }
        public init(isPresented: Binding<Bool>, content: @escaping () -> Wrapper) {
            _isPresented = isPresented
            self.content = content
        }
    }
    
    public struct Wrapper {
        public struct Button {
            public enum Kind {
                case destructive, `default`, cancel
            }
            public var title: LocalizedStringKey
            public var kind: Kind
            public var action: () -> Void
            public init(title: LocalizedStringKey,
                        kind: Kind = .default,
                        action: @escaping () -> Void)
            {
                self.title = title
                self.kind = kind
                self.action = action
            }
        }
        
        public var title: LocalizedStringKey
        public var message: LocalizedStringKey? = nil
        public var buttons: [Button]
        
        public init(title: LocalizedStringKey,
                    message: LocalizedStringKey? = nil,
                    buttons: [Button])
        {
            self.title = title
            self.message = message
            self.buttons = buttons
        }
    }
}

#if os(macOS)
extension STZ.ACTN.Wrapper {
    internal var nativeValue: some View {
        VStack() {
            Text(self.title)
                .modifier(STZ.FNT.ACTN.Body.apply())
                .modifier(STZ.CLR.ACTN.Body.foreground())
                .lineLimit(2) // TODO: Figure out why text won't wrap properly
                .fixedSize(horizontal: false, vertical: true) // TODO: Figure out why text won't wrap properly
                .frame(maxWidth: 200)
            ForEach(0..<self.buttons.count, id: \.self) {
                self.buttons[$0].nativeValue
            }
        }
        .modifier(STZ.PDG.Equal())
    }
}

extension STZ.ACTN.Wrapper.Button {
    internal var nativeValue: some View {
        SwiftUI.Button(
            action: self.action,
            label: {
                STZ.VIEW.TXT(self.title)
                    .modifier(STZ.FNT.Button.Done.apply())
                    .modifier(STZ.CLR.ACTN.Button.foreground())
                    .frame(minWidth: 200, maxWidth: 200)
            }
        )
    }
}
#else
extension STZ.ACTN.Wrapper {
    internal var nativeValue: ActionSheet {
        SwiftUI.ActionSheet(
            title: Text(self.title),
            message: self.message.map { Text($0) },
            buttons: self.buttons
                .map { $0.nativeValue }
                + [.cancel(Text(Verb.Cancel))]
        )
    }
}

extension STZ.ACTN.Wrapper.Button {
    internal var nativeValue: Alert.Button {
        switch self.kind {
        case .cancel:
            return .cancel(Text(self.title),
                           action: self.action)
        case .default:
            return .default(Text(self.title),
                            action: self.action)
        case .destructive:
            return .destructive(Text(self.title),
                                action: self.action)
        }
    }
}
#endif

{'fraction_non_alphanumeric': 0.09273840769903761, 'fraction_numerical': 0.005905511811023622, 'mean_word_length': 1.546644388749652, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '792111', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2393, 'n_words': 684}