<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ $project->name }}: {{ __('Edit AUK') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    <div class="w-96 mx-auto">
                        @if ($errors->any())
                            <div class="alert alert-danger text-red-500 p-2">
                                <ul class="list-unstyled alert alert-danger">
                                    @foreach ($errors->all() as $error)
                                        <li>{{ $error }}</li>
                                    @endforeach
                                </ul>
                            </div>
                        @endif
                        <form method="POST" action="{{ route('auks.update', $auk->id) }}">
                            @csrf
                            @method('PUT')
                            <input type="hidden" id="id" name="id" value="{{ $auk->id }}">
                            <div>
                                <x-label for="c" value="{{ __('Title') }}" />

                                <x-input id="auk_name" class="block mt-1 w-full" type="text" name="auk_name"
                                    value="{{ $auk->auk_name }}" required autofocus />
                            </div>

                            <div>
                                <x-label for="auk_path" value="{{ __('Path') }}" />

                                <x-input id="auk_path" class="block mt-1 w-full" type="text" name="auk_path"
                                    value="{{ $auk->auk_path }}" required />
                            </div>

                            <div>
                                <x-label for="image_dir" value="{{ __('Image Dir') }}" />

                                <x-input id="image_dir" class="block mt-1 w-full" type="text" name="image_dir"
                                    value="{{ $auk->image_dir }}" required />
                            </div>

                            <div>
                                <x-label for="parent_id" value="{{ __('Parent AUK') }}" />

                                <x-select id="parent_id" class="block mt-1 w-full" name="parent_id" required>
                                    <option value="0">---</option>
                                    @foreach ($top_auks as $top_auk)
                                        @if ($auk->parent_id == $top_auk->id)
                                            <option value="{{ $top_auk->id }}" selected>{{ $top_auk->auk_name }}
                                                ({{ $top_auk->auk_path }})</option>
                                        @else
                                            <option value="{{ $top_auk->id }}">{{ $top_auk->auk_name }}
                                                ({{ $top_auk->auk_path }})</option>
                                        @endif
                                        @if (count($top_auk->childs))
                                            @include('auks.optionChildSelected', [
                                                'childs' => $top_auk->childs,
                                                'parent_id' => $top_auk->parent_id,
                                                'level' => 1,
                                            ])
                                        @endif
                                    @endforeach
                                </x-select>
                            </div>


                            <div class="flex items-center justify-end mt-4">
                                <button
                                    class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-full">
                                    <i class="fa fa-add pr-2"></i>{{ __('Save AUK') }}
                                </button>
                                <div class="pl-2">
                                    <a href="{{ route('auks.index') }}"
                                        class="btn bg-gray-500 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded-full">
                                        <i class="fa fa-cancel pr-2"></i>{{ __('Cancel') }}
                                    </a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
