<?php
/*
 * Copyright (c) 2022.
 * Aidyn Sapargaliyev
 * Nur-Sultan (Astana), Kazakhstan
 * ТОО Дизайн лаборатория А7
 * https://a7.kz
 */
/**
 * @var \A7kz\Platform\Modules\Platform\Core\Services\Application\BaseApplication $app
 * @var \A7kz\Platform\Modules\Platform\Core\Services\UI\FormBuilder $form
 */
?>
@if($app->withHeader())
    <x-component name="Tabs" :module="$module"/>
@endif
{!! $app->show_message() !!}
<x-component name="Js.Before" :params="['app'=>$app, 'form'=>$form]" :module="$module"/>
<div class="@if($form->hasContainer()){{$form->container()}}@endif">
    <form method="post"
          action="{{$app->getPath()}}/{{$form->action()}}@if($app->data->hasPkValue())?pk={{$app->data->getPkValue()}}@endif"
          onsubmit="return submit_prepare()">
        <div class="global-actions">
            <div class="left-content">
                <h5 class="global-title">@lang($form->title())</h5>
            </div>
            <div class="right-content">
                @if(count($form->submits()))
                    <x-component name="Form.Submits" :params="['app'=>$app, 'form'=>$form]"
                                 :module="$module"/>
                @endif
            </div>
        </div>
        <div class="card">
            <div class="card-body">
                @if($form->action() == "show")
                @if(!isset($form->getConfig()->hide_prev_next_pk))
                    <div class="row">
                        <div class="col text-center">
                                <?php $next = $app->data->getNextPkValue(); $prev = $app->data->getPrevPkValue(); ?>
                            @if($prev) <a class="btn btn-primary" href="{{$app->getPath()}}/{{$form->action()}}?pk={{$prev}}"><i class="bi bi-caret-left-fill"></i></a> @endif
                            @if($next) <a class="btn btn-primary" href="{{$app->getPath()}}/{{$form->action()}}?pk={{$next}}"><i class="bi bi-caret-right-fill"></i></a> @endif
                        </div>
                    </div>
                @endif
                @endif
                <div class="row">
                    <div class="@if($app->isProcess()) col-md-8 col-xs-12 @else col @endif">

                        @if($app->data->isAutoincrement() && $app->data->getPkValue())
                            <input type="hidden" name="{{$app->data->getPk()}}" value="{{$app->data->getPkValue()}}">
                        @endif
                        @if($app->data->getParentValue())
                            <input type="hidden" id="{{$app->data->getParentField()}}" value="{{$app->data->getParentValue()}}">
                        @endif

                        <x-component name="Form.Row" :params="['rows'=>$form->rows(),'app'=>$app, 'form'=>$form]"
                                     :module="$module"/>
                        @if(count($form->tabs()))
                            <x-component name="Form.Tab" :params="['app'=>$app, 'form'=>$form]"
                                         :module="$module"/>
                        @endif

                        @if($app->hasComments())
                            {!! $app->comment->getComments() !!}
                        @endif

                    </div>
                    @if($app->isProcess())
                        <div class="col-md-4 col-xs-12">
                            {!! $app->documentState->form(); !!}
                        </div>
                    @endif
                </div>
            </div>
        </div>
        {{ csrf_field() }}
        <x-component name="Form.CFCinput" :params="['app'=>$app, 'form'=>$form]"
                     :module="$module"/>
    </form>
</div>
<x-component name="Additional.Modal" :module="$module"/>
<x-component name="Js.After" :params="['app'=>$app]" :module="$module"/>
<x-component name="Additional.ImportAction" :params="['app'=>$app]" :module="$module"/>

@foreach($form->getInjectComponent() as $inject_component)
    <x-component :name="$inject_component" :module="$module" :params="['app'=>$app]"/>
@endforeach


@if(!empty($form->getOnRenderEmitFunctions()))
    <x-component name="Js.OnRenderEmitFunctions" :module="$module"
        :params="['app' => $app, 'emitFunctions' => $form->getOnRenderEmitFunctions()]"
    />
@endif

@if($app->withHeader())
<div class="row mt-5">
    <div class="col">
        <hr>
        <div class="text-end"><span style="color: #e00b0b">*</span> - @lang('Поля обязательные к заполнению')</div>
    </div>
</div>
@endif
