// generated by bun run generate from the SwiftUI SDK and codegen/catalog.ts.
// edit the generator or catalog, then regenerate.
import SwiftUI
import UIKit

final class OneNativeEnvironmentModel: ObservableObject {
  @Published var colorScheme = ""
  @Published var dynamicTypeSize = ""
  @Published var controlSize = ""
  @Published var locale = ""
  @Published var tint: UIColor?
  @Published var isEnabled = ""

  func configure(
    colorScheme: String, dynamicTypeSize: String, controlSize: String, locale: String,
    tint: UIColor?, isEnabled: String
  ) {
    if self.colorScheme != colorScheme { self.colorScheme = colorScheme }
    if self.dynamicTypeSize != dynamicTypeSize { self.dynamicTypeSize = dynamicTypeSize }
    if self.controlSize != controlSize { self.controlSize = controlSize }
    if self.locale != locale { self.locale = locale }
    if self.tint != tint { self.tint = tint }
    if self.isEnabled != isEnabled { self.isEnabled = isEnabled }
  }

  func reset() {
    colorScheme = ""
    dynamicTypeSize = ""
    controlSize = ""
    locale = ""
    tint = nil
    isEnabled = ""
  }
}

struct OneNativeEnvironment<Content: View>: View {
  @ObservedObject var model: OneNativeEnvironmentModel
  let content: Content

  var body: some View {
    content
      .oneNativeColorScheme(model.colorScheme)
      .oneNativeDynamicTypeSize(model.dynamicTypeSize)
      .oneNativeControlSize(model.controlSize)
      .oneNativeLocale(model.locale)
      .oneNativeEnvironmentTint(model.tint)
      .oneNativeIsEnabled(model.isEnabled)
  }
}

extension View {
  @ViewBuilder func oneNativeColorScheme(_ value: String) -> some View {
    if value.isEmpty { self }
    else { self.environment(\.colorScheme, OneNativeGenerated.colorScheme(value)) }
  }

  @ViewBuilder func oneNativeDynamicTypeSize(_ value: String) -> some View {
    if value.isEmpty { self }
    else { self.environment(\.dynamicTypeSize, OneNativeGenerated.dynamicTypeSize(value)) }
  }

  @ViewBuilder func oneNativeControlSize(_ value: String) -> some View {
    if value.isEmpty { self }
    else { self.environment(\.controlSize, OneNativeGenerated.controlSize(value)) }
  }

  @ViewBuilder func oneNativeLocale(_ value: String) -> some View {
    if value.isEmpty { self }
    else { self.environment(\.locale, Locale(identifier: value)) }
  }

  @ViewBuilder func oneNativeEnvironmentTint(_ value: UIColor?) -> some View {
    if let value { self.tint(Color(uiColor: value)) }
    else { self }
  }

  @ViewBuilder func oneNativeIsEnabled(_ value: String) -> some View {
    if value.isEmpty { self }
    else { self.environment(\.isEnabled, value == "enabled") }
  }
}
