@extends('layouts.admin.theme')
@section("title", env("APP_NAME") . " :: " . __("Criar Menu Reutilizável"))
@section('content')
    <form action="{{ route('admin.menusReutilizaveis.store') }}" method="post">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="card shadow">
                        @php
                            $headLine = __('Criar Menu Reutilizável');
                        @endphp
                        @include('components.buttons._headLineButtonsBackAdd', [
                            'headLine' => $headLine,
                            'routeBack' => 'admin.menusReutilizaveis.index',
                            'routeBackParams' => $filterParams ?? [],
                            'nameBack' => __('Voltar'),
                            'permission' => 'GERENCIADOR_DE_MENUS_REUTILIZAVEIS',
                        ])
                        <div class="card-body">
                            @csrf

                            @if(!empty($filterParams))
                                @foreach($filterParams as $key => $value)
                                    @if($value !== null && $value !== '')
                                        <input type="hidden" name="{{ $key }}" value="{{ $value }}">
                                    @endif
                                @endforeach
                            @endif

                            @if ($errors->any())
                                @foreach ($errors->all() as $error)
                                    <div class="alert alert-danger">
                                        {!! $error !!}
                                    </div>
                                @endforeach
                            @endif

                            @if (session('error'))
                                <div class="alert alert-danger">
                                    {{ session('error') }}
                                </div>
                            @endif

                            <div class="mb-3">
                                <label for="title" class="form-label text-bold">
                                    {{ __('Título do Menu') }} <span class="span-admin-create">*</span>
                                </label>
                                <input type="text"
                                    class="form-control @error('title') is-invalid @enderror"
                                    name="title"
                                    id="title"
                                    autocomplete="off"
                                    value="{{ old('title') }}">
                                @error('title')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3 text-wrap">
                                <label for="summary" class="form-label text-bold">
                                    {{ __('Descrição sumária') }}
                                </label>
                                <textarea class="form-control @error('summary') is-invalid @enderror" name="summary" id="summary">{{ old('summary') }}</textarea>
                                @error('summary')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <div class="mb-3">
                                <label for="status" class="form-label text-bold">{{ __('* Status') }}</label>
                                <select class="form-control @error('status') is-invalid @enderror" name="status" id="status">
                                    @foreach(App\Enums\StatusEnum::cases() as $statusOption)
                                        <option value="{{ $statusOption->name }}" {{ old('status') === $statusOption->name ? 'selected' : '' }}>
                                            {{ $statusOption->value }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('status')
                                    <small class="text-danger text-bold">{{ $message }}</small>
                                @enderror
                            </div>

                            <hr class="my-4" />

                            <div class="mb-3">
                                <h5 class="mb-1">{{ __('Links do Menu') }}</h5>
                                <p class="text-muted small mb-0">
                                    {{ __('Preencha apenas as linhas que deseja criar. Linhas em branco serão ignoradas.') }}
                                </p>
                            </div>

                            @for ($i = 0; $i < 5; $i++)
                                <div class="card mb-3 bg-light">
                                    <div class="card-body">
                                        <div class="d-flex justify-content-between align-items-center mb-3">
                                            <div class="fw-bold">{{ __('Link') }} #{{ $i + 1 }}</div>
                                            <div class="text-muted small">
                                                {{ __('Ordem') }}: {{ old("links.$i.order", $i + 1) }}
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="col-12 col-md-3 mb-3">
                                                <label for="links_{{ $i }}_titulo" class="form-label text-bold">{{ __('Título') }}</label>
                                                <input
                                                    type="text"
                                                    class="form-control @error("links.$i.titulo") is-invalid @enderror"
                                                    name="links[{{ $i }}][titulo]"
                                                    id="links_{{ $i }}_titulo"
                                                    value="{{ old("links.$i.titulo") }}"
                                                >
                                                @error("links.$i.titulo")
                                                    <small class="text-danger text-bold">{{ $message }}</small>
                                                @enderror
                                            </div>

                                            <div class="col-12 col-md-3 mb-3">
                                                <label for="links_{{ $i }}_link" class="form-label text-bold">{{ __('Link') }}</label>
                                                <input
                                                    type="text"
                                                    class="form-control @error("links.$i.link") is-invalid @enderror"
                                                    name="links[{{ $i }}][link]"
                                                    id="links_{{ $i }}_link"
                                                    value="{{ old("links.$i.link") }}"
                                                >
                                                @error("links.$i.link")
                                                    <small class="text-danger text-bold">{{ $message }}</small>
                                                @enderror
                                            </div>

                                            <div class="col-12 col-md-2 mb-3">
                                                <label for="links_{{ $i }}_order" class="form-label text-bold">{{ __('Ordem') }}</label>
                                                <input
                                                    type="number"
                                                    min="1"
                                                    class="form-control @error("links.$i.order") is-invalid @enderror"
                                                    name="links[{{ $i }}][order]"
                                                    id="links_{{ $i }}_order"
                                                    value="{{ old("links.$i.order", $i + 1) }}"
                                                >
                                                @error("links.$i.order")
                                                    <small class="text-danger text-bold">{{ $message }}</small>
                                                @enderror
                                            </div>

                                            <div class="col-12 col-md-4 mb-3">
                                                <label for="links_{{ $i }}_link_status" class="form-label text-bold">{{ __('* Tipo de link') }}</label>
                                                <select
                                                    class="form-control @error("links.$i.link_status") is-invalid @enderror"
                                                    name="links[{{ $i }}][link_status]"
                                                    id="links_{{ $i }}_link_status"
                                                >
                                                    <option value="_SELF" {{ old("links.$i.link_status", "_SELF") === "_SELF" ? 'selected' : '' }}>
                                                        {{ __('Link interno') }}
                                                    </option>
                                                    <option value="_BLANK" {{ old("links.$i.link_status", "_SELF") === "_BLANK" ? 'selected' : '' }}>
                                                        {{ __('Link externo') }}
                                                    </option>
                                                </select>
                                                @error("links.$i.link_status")
                                                    <small class="text-danger text-bold">{{ $message }}</small>
                                                @enderror
                                            </div>

                                            <div class="col-12 mb-2">
                                                <label for="links_{{ $i }}_description" class="form-label text-bold">{{ __('Descrição sumária do link') }}</label>
                                                <textarea
                                                    class="form-control @error("links.$i.description") is-invalid @enderror"
                                                    name="links[{{ $i }}][description]"
                                                    id="links_{{ $i }}_description"
                                                    rows="2"
                                                >{{ old("links.$i.description") }}</textarea>
                                                @error("links.$i.description")
                                                    <small class="text-danger text-bold">{{ $message }}</small>
                                                @enderror
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            @endfor

                            <div class="d-flex gap-2 mt-3">
                                <a href="{{ route('admin.menusReutilizaveis.index', $filterParams ?? []) }}"
                                    class="btn btn-secondary">{{ __('Voltar') }}</a>
                                <button class="btn btn-dark" type="submit">{{ __('Salvar') }}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
@endsection

