<?php
/*
 * Copyright (c) 2022.
 * Aidyn Sapargaliyev
 * Nur-Sultan (Astana), Kazakhstan
 * ТОО Дизайн лаборатория А7
 * https://a7.kz
 */
/**
 * @var \A7kz\Platform\Modules\Platform\Core\Services\Application\CrudApplication $app
 */
?>
@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(event)">
        <div class="global-actions">
            <div class="left-content">
                <h5 class="global-title">{{$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(!isset($form->getConfig()->form->hide_prev_next_pk))
                    <div class="row">
                        <div class="col text-center" style="flex-direction: row;display: flex;justify-content: center;column-gap: 1rem; margin-bottom: 1rem;">
                                <?php $next = $app->data->getNextPkValue(); $prev = $app->data->getPrevPkValue(); ?>
                            @if($prev) <a class="btn btn-primary" style='font-size: 0.875rem;' href="{{$app->getPath()}}/{{$form->action()}}?pk={{$prev}}"><i class="bi bi-caret-left-fill" style="margin:0 7px 0 0; font-size: 0.6rem;"></i>Вперед</a> @endif
                            @if($next) <a class="btn btn-primary" style='font-size: 0.875rem;' href="{{$app->getPath()}}/{{$form->action()}}?pk={{$next}}">Назад<i class="bi bi-caret-right-fill" style="margin:0 0 0 7px; font-size: 0.6rem;"></i></a> @endif
                        </div>
                    </div>
                @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
                        <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() }}
    </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
