<link href="<?php echo e(asset('plugins/select2/css/select2.css')); ?>" rel="stylesheet">
<div class="card-body">
   
    <form class="flex flex-row" method="POST" id="formblast">
        <?php echo csrf_field(); ?>
        <input type="hidden" name="type" value="text">
        
            <label for="textmessage" class="form-label">Sender</label>
            <select name="sender" id="sender" class="form-control" style="width: 100%;" required>
               <?php $__currentLoopData = $numbers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $number): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
               <option value="<?php echo e($number->body); ?>"><?php echo e($number->body); ?></option>
               <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
               
            </select>
        
        

            
                
                <div class="tagsOption">
                    <label for="inputEmail4" class="form-label">Phone Book</label>
                    <select name="tag" id="tag" class="form-control" style="width: 100%; height:200px;">
                      <?php $__currentLoopData = $tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                          
                      <option value="<?php echo e($tag->id); ?>"><?php echo e($tag->name); ?></option>
                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                       
                    </select>
                </div>
<div class="d-flex justify-content-rounded">

    <div class="col ">

        <label for="delay" class="form-label">Delay</label>
        <input type="number" id="delay" min="1" max="60" name="delay" class="form-control"  required>
    </div>
    <div class="col mx-2">
        <label for="tipe" class="form-label">Type</label>
        <select name="tipe" id="tipe" class="form-control" style="width: 100%; height:200px;">
           <option value="immediately">Immediately</option>
           <option value="schedule">Schedule</option>
             
          </select>
    </div>
    <div class="col d-none" id="datetime">

        <label for="datetime" class="form-label">Date Time</label>
        <input type="datetime-local" id="datetime2"  name="datetime" class="form-control">
    </div>
    
</div>
                
                
    
            
            <div class="col">
                <label for="inputPassword4" class="form-label">Start Blast</label>
                <textarea name="message" id="message" cols="30" rows="10" class="form-control">This is your message,, use {name} to get a name.</textarea>
            </div>
         
        

        <div class="mt-2 col" id="buttonblast">
            <button type="submit" id="buttonStartBlast" name="submit" class="btn btn-primary">Start Blast</button>
        </div>
        </div>
    </form>
</div>

<script src="<?php echo e(asset('js/pages/select2.js')); ?>"></script>
<script src="<?php echo e(asset('plugins/select2/js/select2.full.min.js')); ?>"></script>
<script>
    
     
$('#tipe').on('change',function(){
    
   if($(this).val() === 'schedule'){
       $('#datetime').removeClass('d-none')
   } else {
    $('#datetime').addClass('d-none')
   }
})
      $('#buttonStartBlast').click((e)=> {
        e.preventDefault();
        
          let selected = []
        $('#lists option:selected').each(function() {
            selected.push($(this).val())
        });

        if(!$('#sender').val()    || !$('#message').val() || !$('#tag').val() || !$('#delay').val()  ){
            return alert('Please fill all field needed!');
        }

        if($('#tipe').val() === 'schedule' && !$('#datetime2').val()){
            return alert('Please set datetime if the tipe message is schedule');
        }
        //  if(checkboxAll === 0 && checkboxTag === 0 && selected.length === 0){
        //     return alert('Please fill number or select all, or select the tag!');
        // } 

        
       
     //  return console.log($('#datetime2').val());
            const data = {
                type : 'text',
                tag : $('#tag').val(),
                sender : $('#sender').val(),
                message : $('#message').val(),
                delay : $('#delay').val(),
                tipe : $('#tipe').val(),
                datetime : $('#datetime2').val()
            }
           // console.log(data.datetime)
          
        $('#buttonStartBlast').html(`<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
                                                Prossess Blasting...`)
       $.ajax({
           method : 'POST',
           headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
           url : '<?php echo e(route('blast')); ?>',
           data : data,
           dataType : 'json',
           success : (result) => {
           // return console.log(result)
           window.location = ''
           },
           error : (err) => {
                console.log(err);
           }
       })
      })
    
    
</script><?php /**PATH /Users/ilmans/Documents/applications/wamd/resources/views/ajax/blast/formBlastText.blade.php ENDPATH**/ ?>