@extends('setting.nav')

@section('title', 'Domain Email')

@section('content')
<div class="container mt-4">
    @if (session('success'))
        <div class="alert alert-success alert-dismissible fade show" role="alert">
            {{ session('success') }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    @endif

    <div class="row ">
        <div class="col-8">
            <div class="col-10">
                <div class="d-flex gap-3">
                    <div class="position-relative">
                        <a href="#" class="btn btn-secondary rounded-pill px-4" data-bs-toggle="modal"
                            data-bs-target="#importantMailModal">Domain Match
                        </a>
                        <span id="countis_spam"
                            class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                            {{ $match_domain ?? 0 }}
                        </span>
                    </div>
                    <!-- Modal for Important Mail -->
                    <div class="modal fade" id="importantMailModal" tabindex="-1" aria-labelledby="importantMailLabel"
                        aria-hidden="true">
                        <div class="modal-dialog modal-xl modal-dialog-scrollable">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="importantMailLabel">Domain Match Mails</h5>
                                    {{-- <h5 class="modal-title" id="importantMailLabel">Important Mails</h5> --}}
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                        aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <!-- Display Important Mails Here -->
                                    <div class="container">
                                        <h2>Domain Match Mails</h2>
                                        {{-- <h2>Important Mails</h2> --}}
                                        <table id="importantMailsTable" class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>ID</th>
                                                    <th>Sender Name</th>
                                                    <th>Sender Email</th>
                                                    <th style="width: 150px;">Actions</th> <!-- New Column for Button -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach ($match_domain_data as $mail)
                                                    <tr>
                                                        <td>{{ $mail->id }}</td>
                                                        <td>{{ $mail->sender_name }}</td>
                                                        <td>{{ $mail->sender_email }}</td>
                                                        <td>
                                                            <div class="d-flex flex-wrap gap-3">
                                                                <div class="position-relative">
                                                                    {{-- <a href="#"
                                                                        class="btn btn-secondary rounded-pill px-4">All
                                                                        Mails</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->total_count }}
                                                                    </span> --}}
                                                                     <form action="{{ route('show_all_mail') }}" method="POST">
                                                                    @csrf
                                                                    <input type="hidden" name="user_id"
                                                                        value="{{ $mail->user_id }}">
                                                                    <input type="hidden" name="sender_email"
                                                                        value="{{ $mail->sender_email }}">
                                                                    <button type="submit"
                                                                        class="btn btn-secondary rounded-pill px-4">
                                                                        All Mails
                                                                    </button>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->total_count }}
                                                                    </span>
                                                                </form>
                                                                </div>
                                                                {{-- <div class="position-relative">
                                                                    <a href="#"
                                                                        class="btn btn-primary rounded-pill px-4"> Bad</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->is_spam_count }}
                                                                    </span>
                                                                </div>
                                                                <div class="position-relative">
                                                                    <a href="#"
                                                                        class="btn btn-success rounded-pill px-4">Good</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->is_not_spam_count }}
                                                                    </span>
                                                                </div> --}}
                                                            </div>
                                                        </td>
                                                    </tr>
                                                @endforeach
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
    
                    <div class="position-relative">
                        <a href="#" class="btn btn-warning rounded-pill px-4" data-bs-toggle="modal"
                            data-bs-target="#notImportantMailModal">Domain not match
                        </a>
                        <span id="countis_spam"
                            class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                            {{ $notmatch_domain ?? 0 }}
                        </span>
                    </div>
    
                    <!-- Modal for Not Important Mail -->
                    <div class="modal fade" id="notImportantMailModal" tabindex="-1" aria-labelledby="notImportantMailLabel"
                        aria-hidden="true">
                        <div class="modal-dialog modal-xl modal-dialog-scrollable">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="notImportantMailLabel">Domain Not Match Mails</h5>
                                    {{-- <h5 class="modal-title" id="notImportantMailLabel">Not Important Mails</h5> --}}
                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                        aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                    <!-- Display Not Important Mails Here -->
                                    <div class="container">
                                        <h2>Domain Not Match Mails</h2>
                                        {{-- <h2>Non-Important Mails</h2> --}}
                                        <table id="nonImportantMailsTable" class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th>ID</th>
                                                    <th>Sender Name</th>
                                                    <th>Sender Email</th>
                                                    <th style="width: 150px;">Actions</th> <!-- New Column for Button -->
                                                </tr>
                                            </thead>
                                            <tbody>
                                                @foreach ($notmatch_domain_data as $mail)
                                                    <tr>
                                                        <td>{{ $mail->id }}</td>
                                                        <td>{{ $mail->sender_name }}</td>
                                                        <td>{{ $mail->sender_email }}</td>
                                                        <td>
                                                            <div class="d-flex flex-wrap gap-3">
                                                                <div class="position-relative">
                                                                    {{-- <a href="#"
                                                                        class="btn btn-secondary rounded-pill px-4">All
                                                                        Mails</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->total_count }}
                                                                    </span> --}}
                                                                    <form action="{{ route('show_all_mail') }}" method="POST">
                                                                    @csrf
                                                                    <input type="hidden" name="user_id"
                                                                        value="{{ $mail->user_id }}">
                                                                    <input type="hidden" name="sender_email"
                                                                        value="{{ $mail->sender_email }}">
                                                                    <button type="submit"
                                                                        class="btn btn-secondary rounded-pill px-4">
                                                                        All Mails
                                                                    </button>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->total_count }}
                                                                    </span>
                                                                </form>
                                                                </div>
                                                                {{-- <div class="position-relative">
                                                                    <a href="#"
                                                                        class="btn btn-primary rounded-pill px-4"> Bad</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->is_spam_count }}
                                                                    </span>
                                                                </div>
                                                                <div class="position-relative">
                                                                    <a href="#"
                                                                        class="btn btn-success rounded-pill px-4">Good</a>
                                                                    <span
                                                                        class="position-absolute top-0 start-100 translate-middle badge rounded-pill bg-danger">
                                                                        {{ $mail->is_not_spam_count }}
                                                                    </span>
                                                                </div> --}}
                                                            </div>
                                                        </td>
                                                    </tr>
                                                @endforeach
                                            </tbody>
                                        </table>
                                    </div>
    
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-4">
            <form method="POST" action="{{ route('domain.store') }}" class="d-flex align-items-center">
                @csrf
                <input type="text" name="domain_name" class="form-control me-2" placeholder="Enter domain name" required
                value="{{ old('domain_name', $domain->domain_name ?? '@gmail.com') }}">
                <button type="submit" class="btn btn-primary">Save</button>
            </form>
        </div>
    </div>
</div>
<script>
    $(document).ready(function() {
            $('#importantMailsTable').DataTable({
                "paging": true,
                "searching": true,
                "ordering": true,
                "info": true,
            });
            $('#nonImportantMailsTable').DataTable({
                "paging": true,
                "searching": true,
                "ordering": true,
                "info": true
            });
        })
</script>
@endsection
