@extends('adminlte::page')

@section('content_header')
    <h1>Crea una regola di importazione</h1>
@stop

@section('content')
<div class="container">
    <p>Compila il modulo per creare una nuova regola di importazione.</p>

    <div class="card">
        <div class="card-header">
            <h3 class="card-title">Nuova Regola di Importazione</h3>
        </div>
        <div class="card-body">
            <form action="{{ route('import_rules.store') }}" method="POST">
                @csrf
                <div class="form-group">
                    <label for="pattern">Pattern</label>
                    <input type="text" name="pattern" id="pattern" class="form-control" required>
                </div>
                <div class="form-group">
                    <label for="category_id">Categoria</label>
                    <select name="category_id" id="category_id" class="form-control" required>
                        <option value="">Seleziona una categoria</option>
                        @foreach($categorie as $category)
                            <option value="{{ $category->id }}">{{ $category->cat_name }}</option>
                        @endforeach
                        <option value="nuovo">Crea nuova categoria</option>
                    </select>
                    <input type="text" name="nuovo_valore" id="nuovo_valore" class="form-control mt-2" placeholder="Nome nuova categoria" style="display:none;">
                    <button type="button" class="btn btn-primary mt-2" id="nuovo_aggiungi" style="display:none;">Crea Categoria</button>
                <div class="form-group">
                    <label for="description">Descrizione</label>
                    <textarea name="description" id="description" class="form-control" rows="3" required></textarea>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-primary">Crea Regola</button>
                    <a href="{{ route('import_rules.index') }}" class="btn btn-secondary">Annulla</a>
                </div>
            </form>
        </div>

    <div class="card-footer">
        <a href="{{ route('import_rules.index') }}" class="btn btn-secondary">Torna alla lista</a>
    </div>
</div>
</div>
@endsection

@section('js')
    <script src="/js/app/import_rules.js"></script>
@endsection')
