<commit_before>package com.eden.orchid.netlifycms.util

import com.eden.orchid.Orchid
import com.eden.orchid.api.options.OptionHolderDescription
import com.eden.orchid.api.options.OptionsDescription
import com.eden.orchid.api.options.OptionsExtractor
import com.eden.orchid.api.theme.components.ComponentHolder
import com.eden.orchid.api.theme.components.OrchidComponent
import com.eden.orchid.api.theme.menus.OrchidMenu
import com.eden.orchid.api.theme.menus.menuItem.OrchidMenuItem
import com.eden.orchid.impl.relations.AssetRelation
import com.eden.orchid.utilities.camelCase
import com.eden.orchid.utilities.from
import com.eden.orchid.utilities.titleCase
import com.eden.orchid.utilities.to
import org.json.JSONArray
import org.json.JSONObject
import java.awt.MenuItem
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime

fun OptionsDescription.toNetlifyCmsField(): JSONObject {
    val field = JSONObject()
    field.put("label", this.key.from { camelCase() }.to { titleCase() })
    field.put("name", this.key)
    field.put("description", this.description)
    field.put("required", false)

    var widget = if (Number::class.java.isAssignableFrom(this.optionType)) {
        "number"
    }
    else if (Boolean::class.java.isAssignableFrom(this.optionType)) {
        "boolean"
    }
    else if (this.optionType.isArray) {
        "list"
    }
    else {
        when (this.optionType) {
            LocalDate::class.java -> "date"
            LocalTime::class.java -> "datetime"
            LocalDateTime::class.java -> "datetime"
            ComponentHolder::class.java -> "list"
            OrchidMenu::class.java -> "list"
            AssetRelation::class.java -> "image"
            String::class.java -> "string"
            else -> "string"
        }
    }

    if(this.optionType.isArray) {
        field.put("field", "string")
    }
    else if(this.optionType == ComponentHolder::class.java) {
        val extractor = Orchid.getInstance().context.injector.getInstance(OptionsExtractor::class.java)
        field.put("fields", extractor.describeAllOptions(OrchidComponent::class.java).getNetlifyCmsFields())
    }
    else if(this.optionType == OrchidComponent::class.java) {
        val typeField = JSONObject()
        typeField.put("label", "Type")
        typeField.put("name", "Type")
        typeField.put("description", "The Component type")
        typeField.put("required", false)
        field.put("type", typeField)
    }
    else if(this.optionType == OrchidMenu::class.java) {
        val extractor = Orchid.getInstance().context.injector.getInstance(OptionsExtractor::class.java)<commit_msg>Fixes bug where pages with tags would crash Netlify CMS<commit_after>package com.eden.orchid.netlifycms.util

import com.eden.orchid.Orchid
import com.eden.orchid.api.options.OptionHolderDescription
import com.eden.orchid.api.options.OptionsDescription
import com.eden.orchid.api.options.OptionsExtractor
import com.eden.orchid.api.theme.components.ComponentHolder
import com.eden.orchid.api.theme.components.OrchidComponent
import com.eden.orchid.api.theme.menus.OrchidMenu
import com.eden.orchid.api.theme.menus.menuItem.OrchidMenuItem
import com.eden.orchid.impl.relations.AssetRelation
import com.eden.orchid.utilities.camelCase
import com.eden.orchid.utilities.from
import com.eden.orchid.utilities.titleCase
import com.eden.orchid.utilities.to
import org.json.JSONArray
import org.json.JSONObject
import java.awt.MenuItem
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime

fun OptionsDescription.toNetlifyCmsField(): JSONObject {
    val field = JSONObject()
    field.put("label", this.key.from { camelCase() }.to { titleCase() })
    field.put("name", this.key)
    field.put("description", this.description)
    field.put("required", false)

    var widget = if (Number::class.java.isAssignableFrom(this.optionType)) {
        "number"
    }
    else if (Boolean::class.java.isAssignableFrom(this.optionType)) {
        "boolean"
    }
    else if (this.optionType.isArray) {
        "list"
    }
    else {
        when (this.optionType) {
            LocalDate::class.java -> "date"
            LocalTime::class.java -> "datetime"
            LocalDateTime::class.java -> "datetime"
            ComponentHolder::class.java -> "list"
            OrchidMenu::class.java -> "list"
            AssetRelation::class.java -> "image"
            String::class.java -> "string"
            else -> "string"
        }
    }

    if(this.optionType.isArray) {
        val typeField = JSONObject()
    }
    else if(this.optionType == ComponentHolder::class.java) {
        val extractor = Orchid.getInstance().context.injector.getInstance(OptionsExtractor::class.java)
        field.put("fields", extractor.describeAllOptions(OrchidComponent::class.java).getNetlifyCmsFields())
    }
    else if(this.optionType == OrchidComponent::class.java) {
        val typeField = JSONObject()
        typeField.put("label", "Type")
        typeField.put("name", "Type")
        typeField.put("description", "The Component type")
        typeField.put("required", false)
        field.put("type", typeField)
    }
    else if(this.optionType == OrchidMenu::class.java) {
        val extractor = Orchid.getInstance().context.injector.getInstance(OptionsExtractor::class.java)
{'fraction_non_alphanumeric': 0.12752053771471247, 'fraction_numerical': 0.0, 'mean_word_length': 3.409053497942387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '424413', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1629, 'n_words': 257}