<x-app-layout>
    @section('title')
        Pages Management
    @endsection

    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">
                Create
            </h6>
        </div>
        <div class="card-body">
            <form action="{{ route('admin.partnerrules.update',$data->id) }}" method="POST">
                @csrf
                @method('put')
                <div class="row">
                    <div class="col-12">
                        <label for="">Title</label>
                        <input type="text" value="{{ $data->title }}" class="form-control" name="title"
                            placeholder="Title">
                    </div>
                    <div class="col-12">
                        <label for="">Description</label>
                        <textarea name="description" placeholder="Description" class="form-control">{{ $data->description }}</textarea>
                    </div>

                    <div class="col-12">
                        <label for="">Rule</label>
                        @foreach ($data->rules as $key => $dt)
                            <div id="rulesContainer">
                                <div class="rule-input-container ">

                                    <input type="text" class="form-control rule-input" value="{{ $dt }}"
                                        name="rules[]" placeholder="Rule">
                                    <button type="button" class="btn btn-danger delete-rule">Delete</button>
                                    @if ($key == 0)
                                        <button type="button" class="btn btn-secondary add-rule">Add More</button>
                                    @endif
                                </div>
                            </div>
                        @endforeach


                    </div>
                    <div class="col-12">
                        <div class="mt-3">
                            <button type="submit" class="btn btn-primary">Update</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script>
        $(document).ready(function() {
            $(document).on('click', '.add-rule', function() {
                $(this).closest('.rule-input-container').after(
                    '<div class="rule-input-container"><input type="text" class="form-control rule-input" name="rules[]" placeholder="Rule"><button type="button" class="btn btn-danger delete-rule">Delete</button>  </div>'
                );
            });

            $(document).on('click', '.delete-rule', function() {
                $(this).closest('.rule-input-container').remove();
            });
        });
    </script>
</x-app-layout>
