@extends($activeTemplate . 'partials.tools')
@section('tools')

    <div class="seo-tool-details__block seo-tool-details-form-wrap">
        <form id="toolsForm" action="{{ route($tool->route) }}" method="post" class="seo-tool-details-form">
            @csrf

            <div id="processingMessage" class="alert alert-info mt-3 d-none text-center" role="alert">
                <i class="fas fa-cog fa-spin"></i> @lang('Processing your request')... @lang('This may take a few moments.')
            </div>

            <div class="seo-tool-details-form__body">
                <div class="form-group mb-3">
                    <label for="domain" class="form--label fw-bold">@lang('Keyword')</label>
                    <input type="text" class="form--control form-control" id="domain" name="keyword" value="{{ old('keyword') }}" placeholder="@lang('Enter Keyword')" required>
                </div>
                <div class="text-center">
                    <button type="submit" id="rewriteBtn" class="btn btn--base btn-lg">
                        <span class="button-text">@lang('Search')</span>
                        <span class="spinner-border spinner-border-sm d-none" role="status" aria-hidden="true"></span>
                    </button>
                </div>
            </div>
        </form>
    </div>

    @if (isset($results))
        <div id="results-section" class="card border-0 seo-tool-details__result">
            <div class="card-header text-center">
                <h5 class="mb-0 tool-block__title">@lang('Keyword Suggestion for') "{{ $keyword }}"</h5>
            </div>
            @if (empty($results))
                <p class="text-center text-muted">@lang('No results found').</p>
            @else
                <div class="table-responsive">
                    <table class="table table--responsive--md">
                        <thead>
                            <tr>
                                <th>@lang('SL')</th>
                                <th>@lang('Keyword')</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($results as $result)
                                <tr>
                                    <td>{{ $loop->iteration }}</td>
                                    <td>{{ $result }}</td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif

        </div>
    @elseif(isset($keyword))
        <div class="alert alert-danger mt-3">
            @lang('Keyword research could not be performed for') "{{ $keyword }}". @lang('Please try again later').
        </div>
    @endif

@endsection

@push('style')
    <style>
        .keyword-difficulty {
            height: 20px;
        }

        .competition-badge {
            font-size: 0.8em;
            padding: 0.3em 0.6em;
        }
    </style>
@endpush

@push('script')
    <script>
        "use strict";
        (function($) {
            const resultsSection = document.getElementById('results-section');
            if (resultsSection) {
                const headerOffset = 100;
                const elementPosition = resultsSection.getBoundingClientRect().top;
                const offsetPosition = elementPosition + window.pageYOffset - headerOffset;

                window.scrollTo({
                    top: offsetPosition,
                    behavior: 'smooth'
                });
            }

            $(function() {
                $('[data-bs-toggle="tooltip"]').tooltip();
            });
        })(jQuery);
    </script>
@endpush
