///
/// HybridAirPlayButtonComponent.cpp
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

#include "HybridAirPlayButtonComponent.hpp"

#include <string>
#include <exception>
#include <utility>
#include <NitroModules/NitroDefines.hpp>
#include <NitroModules/JSIConverter.hpp>
#include <NitroModules/PropNameIDCache.hpp>
#include <react/renderer/core/RawValue.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/ComponentDescriptor.h>
#include <react/renderer/components/view/ViewProps.h>

namespace margelo::nitro::aviation::views {

  extern const char HybridAirPlayButtonComponentName[] = "AirPlayButton";

  HybridAirPlayButtonProps::HybridAirPlayButtonProps(const react::PropsParserContext& context,
                                                     const HybridAirPlayButtonProps& sourceProps,
                                                     const react::RawProps& rawProps):
    react::ViewProps(context, sourceProps, rawProps, filterObjectKeys),
    tintColor([&]() -> CachedProp<std::string> {
      try {
        const react::RawValue* rawValue = rawProps.at("tintColor", nullptr, nullptr);
        if (rawValue == nullptr) return sourceProps.tintColor;
        const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
        return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.tintColor);
      } catch (const std::exception& exc) {
        throw std::runtime_error(std::string("AirPlayButton.tintColor: ") + exc.what());
      }
    }()),
    activeTintColor([&]() -> CachedProp<std::string> {
      try {
        const react::RawValue* rawValue = rawProps.at("activeTintColor", nullptr, nullptr);
        if (rawValue == nullptr) return sourceProps.activeTintColor;
        const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
        return CachedProp<std::string>::fromRawValue(*runtime, value, sourceProps.activeTintColor);
      } catch (const std::exception& exc) {
        throw std::runtime_error(std::string("AirPlayButton.activeTintColor: ") + exc.what());
      }
    }()),
    hybridRef([&]() -> CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridAirPlayButtonSpec>& /* ref */)>>> {
      try {
        const react::RawValue* rawValue = rawProps.at("hybridRef", nullptr, nullptr);
        if (rawValue == nullptr) return sourceProps.hybridRef;
        const auto& [runtime, value] = (std::pair<jsi::Runtime*, jsi::Value>)*rawValue;
        return CachedProp<std::optional<std::function<void(const std::shared_ptr<HybridAirPlayButtonSpec>& /* ref */)>>>::fromRawValue(*runtime, value.asObject(*runtime).getProperty(*runtime, PropNameIDCache::get(*runtime, "f")), sourceProps.hybridRef);
      } catch (const std::exception& exc) {
        throw std::runtime_error(std::string("AirPlayButton.hybridRef: ") + exc.what());
      }
    }()) { }

  bool HybridAirPlayButtonProps::filterObjectKeys(const std::string& propName) {
    switch (hashString(propName)) {
      case hashString("tintColor"): return true;
      case hashString("activeTintColor"): return true;
      case hashString("hybridRef"): return true;
      default: return false;
    }
  }

  HybridAirPlayButtonComponentDescriptor::HybridAirPlayButtonComponentDescriptor(const react::ComponentDescriptorParameters& parameters)
    : ConcreteComponentDescriptor(parameters,
                                  react::RawPropsParser(/* enableJsiParser */ true)) {}

  std::shared_ptr<const react::Props> HybridAirPlayButtonComponentDescriptor::cloneProps(const react::PropsParserContext& context,
                                                                                         const std::shared_ptr<const react::Props>& props,
                                                                                         react::RawProps rawProps) const {
    // 1. Prepare raw props parser
    rawProps.parse(rawPropsParser_);
    // 2. Copy props with Nitro's cached copy constructor
    return HybridAirPlayButtonShadowNode::Props(context, /* & */ rawProps, props);
  }

#ifdef ANDROID
  void HybridAirPlayButtonComponentDescriptor::adopt(react::ShadowNode& shadowNode) const {
    // This is called immediately after `ShadowNode` is created, cloned or in progress.
    // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
    auto& concreteShadowNode = static_cast<HybridAirPlayButtonShadowNode&>(shadowNode);
    const std::shared_ptr<const HybridAirPlayButtonProps>& constProps = concreteShadowNode.getConcreteSharedProps();
    const std::shared_ptr<HybridAirPlayButtonProps>& props = std::const_pointer_cast<HybridAirPlayButtonProps>(constProps);
    HybridAirPlayButtonState state{props};
    concreteShadowNode.setStateData(std::move(state));
  }
#endif

} // namespace margelo::nitro::aviation::views
