@extends('layouts.csd.app')

@section('content')
<script src="https://cdn.ckeditor.com/4.14.0/standard/ckeditor.js"></script>

<main id="main" class="main">
    <div class="pagetitle">
        <h1>Send Email</h1>
        <nav>
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="index.html">Home</a></li>
                <li class="breadcrumb-item active">Compose Email</li>
            </ol>
        </nav>
    </div><!-- End Page Title -->

    <section class="section">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-body">
                        @foreach (['danger', 'warning', 'success', 'info'] as $msg)
                            @if(Session::has('alert-' . $msg))
                                <div class="alert alert-{{ $msg }} alert-dismissible fade show" role="alert">
                                    {{ Session::get('alert-' . $msg) }}
                                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                                </div>
                            @endif
                        @endforeach
                        
                        <h5 class="card-title">Compose New Email</h5>
                        
                        <form action="{{url('/csd/sendmail')}}" method="post" id="formadd" enctype="multipart/form-data" class="row g-3 needs-validation" novalidate>
                            @csrf
                            
                            <div class="col-md-12">
                                <label for="site_name" class="form-label">Select Site<span class="text-danger">*</span></label>
                                <select name="site_name" id="site_name" class="form-select" required>
                                    <option value="" selected disabled>Select Site</option>
                                    @foreach($siteDetails as $siteinfos)
                                        <option value="{{$siteinfos->site_name}}">{{$siteinfos->site_domain}}</option>
                                    @endforeach
                                </select>
                                <div class="invalid-feedback">Please select a site.</div>
                            </div>
                            
                            <div class="col-md-6">
                                <label for="u_name" class="form-label">Customer Name<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="u_name" id="u_name" placeholder="Enter customer name" required>
                                <div class="invalid-feedback">Please enter customer name.</div>
                            </div>
                            
                            <div class="col-md-6">
                                <label for="u_email" class="form-label">Customer Email<span class="text-danger">*</span></label>
                                <input type="email" class="form-control" name="u_email" id="u_email" placeholder="Enter customer email" required>
                                <div class="invalid-feedback">Please enter a valid email address.</div>
                            </div>
                            
                            <div class="col-12">
                                <label for="sub" class="form-label">Subject<span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="sub" id="sub" placeholder="Enter email subject" required>
                                <div class="invalid-feedback">Please enter a subject.</div>
                            </div>
                            
                            <div class="col-12">
                                <label for="mail_body" class="form-label">Content<span class="text-danger">*</span></label>
                                <textarea class="form-control" rows="8" name="mail_body" id="mail_body" placeholder="Write your message here" required></textarea>
                                <div class="invalid-feedback">Please enter the email content.</div>
                            </div>
                            
                            <div class="col-12">
                                <label for="img" class="form-label">Attachment</label>
                                <input type="file" class="form-control" name="img" id="img">
                                <div class="form-text">Optional file attachment</div>
                            </div>
                            
                            <div class="text-center">
                                <button type="submit" class="btn btn-primary">
                                    <i class="bi bi-send-fill me-1"></i> Send Email
                                </button>
                                <button type="reset" class="btn btn-secondary">
                                    <i class="bi bi-eraser me-1"></i> Reset
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>

    <!-- <table class="table table-striped table-bordered" style="font-size:14px">
        <thead>
            <tr>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <form action="{{url('/csd/mail')}}" method="post" enctype="multipart/form-data">
            @csrf
        <tbody>
            <tr>
                <td colspan="2">
                    <select name="site_name" id="site_name" class="form-control" required>
                        <option value="0" selected>Please Selete Site Name</option>
                        @foreach($siteDetails as $siteinfos)
                            <option value="{{$siteinfos->site_sort_name}}">{{$siteinfos->site_sort_name}}</option>
                        @endforeach
                    </select>
                </td>
            </tr>
            <tr>
                <td style="width: 10%;">User Email :</td>
                <td><input class="form-control" name="u_email" id="u_email" placeholder="Enter User Email" required/>
            </tr>
            <tr>
                <td style="width: 10%;">Subject :</td>
                <td><input class="form-control" name="sub" id="sub" placeholder="Enter Subject" required/></td>
            </tr>
            <tr>
                <td colspan="2">
                <textarea class="form-control" name="mail_body" id="mail_body"  placeholder="Enter Mail Body" required></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="file" class="form-control" name="img" id="img"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align:center;">
                    <button type="submit" class="btn btn-primary">Send</button>
                </td>
            </tr>
        </tbody>
        </form>
     

    </table> -->
<style>
    .ck-editor__editable {
        min-height: 300px;
    }
    .form-label .text-danger {
        margin-left: 3px;
    }
</style>

<script>
    // Initialize CKEditor
    CKEDITOR.replace('mail_body', {
        toolbar: [
            { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', '-', 'RemoveFormat'] },
            { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Blockquote'] },
            { name: 'links', items: ['Link', 'Unlink'] },
            { name: 'insert', items: ['Image', 'Table'] },
            { name: 'document', items: ['Source'] }
        ]
    });

    // Form validation
    (function () {
        'use strict'
        const forms = document.querySelectorAll('.needs-validation')
        
        Array.from(forms).forEach(form => {
            form.addEventListener('submit', event => {
                if (!form.checkValidity()) {
                    event.preventDefault()
                    event.stopPropagation()
                }
                
                form.classList.add('was-validated')
            }, false)
        })
    })()
</script>
@endsection