<?php

namespace JetStudioModule\DataModel;

use Jet\Form_Renderer;

$form = DataModel_Definition_Model_Related_1toN::getCreateForm();

$current_model = DataModels::getCurrentModel();

$form->renderer()->setDefaultLabelWidth( [Form_Renderer::LJ_SIZE_MEDIUM => 4] );
$form->renderer()->setDefaultFieldWidth( [Form_Renderer::LJ_SIZE_MEDIUM => 8] );

$form->field( 'namespace' )->input()->addJsAction( 'onchange', 'DataModel.create.generateScriptPath(this.form)' );
$form->field( 'class_name' )->input()->addJsAction( 'onkeyup',
	'DataModel.create.generateScriptPath(this.form);'
	.'DataModel.create.generateModelName(this.form);'
	.'DataModel.create.generateRelationPropertyName(this.form, \''.$current_model->getModelName().'\');'
);

echo $form->start();
echo $form->getCommonMessage();
?>
<div class="form-fields" style="grid-template-columns: 0.5fr 2fr">
<?php
echo $form->field( 'type' );
echo $form->field( 'namespace' );
echo $form->field( 'class_name' );
echo $form->field( 'model_name' );
echo $form->field( 'relation_property_name' );
echo $form->field( 'script_path' );

echo $form->field( 'id_controller_class' );
echo $form->field( 'id_property_name' );

foreach( $form->getFields() as $field ) {
	if( !str_starts_with( $field->getName(), 'related_' ) ) {
		continue;
	}

	echo $field;
}
?>
</div>
<?php

echo $form->end();

