@extends('layouts.masterHome2')

@section('content')
 

 <style>
        :root {
            --primary-color: #2c3e50;
            --secondary-color: #3498db;
            --accent-color: #e74c3c;
            --light-color: #f8f9fa;
            --dark-color: #343a40;
            --success-color: #28a745;
            --border-color: #dee2e6;
            --shadow-color: rgba(0, 0, 0, 0.1);
        }
        
        body {
            font-family: 'Tajawal', sans-serif;
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
        }
        
        .form-container {
            max-width: 1000px;
            margin: 30px auto;
            background: white;
            border-radius: 12px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }
        
        .form-header {
            background: linear-gradient(135deg, var(--primary-color) 0%, #4a6580 100%);
            color: white;
            padding: 25px;
            text-align: center;
            position: relative;
        }
        
        .form-title {
            font-size: 28px;
            font-weight: 700;
            margin-bottom: 12px;
            color: #ffd700;
        }
        
        .form-subtitle {
            font-size: 18px;
            margin-bottom: 8px;
            font-weight: 600;
        }
        
        .form-body {
            padding: 30px;
        }
        
        .form-section {
            margin-bottom: 30px;
            border: 1px solid var(--border-color);
            border-radius: 10px;
            padding: 20px;
            background: #fff;
        }
        
        .section-title {
            font-size: 20px;
            font-weight: 700;
            color: var(--primary-color);
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 2px solid var(--primary-color);
        }
        
        .form-row {
            display: flex;
            margin-bottom: 20px;
            gap: 20px;
        }
        
        .form-group {
            flex: 1;
        }
        
        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: var(--dark-color);
        }
        
        .form-input, .form-select, .form-textarea {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            font-family: 'Tajawal', sans-serif;
            font-size: 16px;
            transition: all 0.3s;
        }
        
        .form-input:focus, .form-select:focus, .form-textarea:focus {
            outline: none;
            border-color: var(--secondary-color);
            box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
        }
        
        .form-textarea {
            min-height: 100px;
            resize: vertical;
        }
        
        .calculation-row {
            background-color: #f1f6fd;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .calc-label {
            font-weight: 600;
            color: var(--primary-color);
        }
        
        .calc-value {
            font-weight: 700;
            color: var(--dark-color);
            background: white;
            padding: 8px 15px;
            border-radius: 5px;
            min-width: 150px;
            text-align: center;
        }
        
        .form-actions {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 30px;
        }
        
        .btn {
            padding: 12px 25px;
            border: none;
            border-radius: 8px;
            font-family: 'Tajawal', sans-serif;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 16px;
        }
        
        .btn-primary {
            background: var(--primary-color);
            color: white;
        }
        
        .btn-secondary {
            background: var(--secondary-color);
            color: white;
        }
        
        .btn-success {
            background: var(--success-color);
            color: white;
        }
        
        .btn-danger {
            background: var(--accent-color);
            color: white;
        }
        
        .btn-primary:hover {
            background: #1e2a36;
        }
        
        .btn-secondary:hover {
            background: #1d6fa5;
        }
        
        .btn-success:hover {
            background: #218838;
        }
        
        .btn-danger:hover {
            background: #c82333;
        }
        
        .signature-section {
            display: flex;
            justify-content: space-between;
            padding: 20px 50px;
            background: #f8f9fa;
            border-radius: 10px;
            border: 1px dashed #ced4da;
            margin-top: 30px;
        }
        
        .signature-item {
            text-align: center;
            font-weight: 700;
            color: var(--primary-color);
            padding: 15px 25px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
            min-width: 120px;
        }
        
        .stamp-placeholder {
            height: 60px;
            width: 100%;
            border-bottom: 2px dashed #ced4da;
            margin-top: 10px;
        }
        
        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 15px;
            }
            
            .signature-section {
                flex-direction: column;
                gap: 15px;
                padding: 20px;
            }
            
            .calculation-row {
                flex-direction: column;
                gap: 10px;
                text-align: center;
            }
        }
    </style>
<br/>
<div class="row">
<div class="col-md-2"></div>
  <div class="col-md-8">

      <div class="card card-info">
          <div class="card-header">
            <h3 class="card-title">تقرير صنف</h3>
          </div>
          <!-- /.card-header -->
          <!-- form start -->

            <form   role="form" method="POST" action="{{ url('/sanfreport/create') }}">
                        {{ csrf_field() }}
              <div class="box-body">
              <div class="card-body">

              <div class="col-md-12" style="display: flex;flex-flow: row;justify-content: space-around;" >  
                <div class="form-group col-md-6" >
                    <label for="exampleInputPassword1">Date from  </label>
                    <input type="date" id="sanf_report_from" name="from" class="form-control"  placeholder="Date from " required>
                  </div>



                  <div class="form-group col-md-6">
                    <label for="exampleInputPassword1">Date to</label>
                    <input type="date" id="sanf_report_to"  name="to" class="form-control"  onchange="getSellStores()"  placeholder="Date to " required>
                  </div>
                </div>


              <div class="form-group">
                <label class="form-label">اسم الصنف</label>
                    <select class="form-control select2 select2-hidden-accessible"  multiple="multiple"  name="stores[]"   style="width: 100%;text-align:right" onchange="getClients()"  id="stores" required>
                    <option value="">اختر اسم الصنف</option>    
                    @foreach( $sell_stores as $store ) 
                        <option value="{{ $store->id }}"  >{{$store->store->sell_name}} </option>
                        @endforeach
                    </select>                           
              </div>

              <div class="form-group">
                <label class="form-label">اسم العميل</label>
                    <select class="form-control select2 select2-hidden-accessible"  multiple="multiple"  name="clients[]"   style="width: 100%;text-align:right"  id="clients" required>
                    <option value="">اختر اسم العميل</option>    
                    
                    </select>                           
              </div>

                </div> </div>
              <!-- /.box-body -->

              <div class="card-footer">
                <button type="submit" class="btn btn-warning">Create</button>
              </div>
            </form>

            </div>


</div>
      <!-- /.row -->
</div>
<br/><br/><br/>


<script>



	function getSellStores() {

	
  const formData = {
            from: $('#sanf_report_from').val(),
            to: $('#sanf_report_to').val()
        };

        

	$.ajax({
            url: 'get_stores',
            type: 'POST',
            data: formData,
            headers: {
                'X-CSRF-TOKEN': "{{ csrf_token() }}"
            },
            success: function(response) {
                if (response.success) {
                    
                  $('#clients').empty();
                  var sel = $('#stores').empty();
                  var stores = response.stores ;
                  sel.append('<option> Choose Items</option>');
                  for (var i = 0; i < stores.length; ++i) {
                    sel.append('<option value="' + stores[i].sell_store_id + '">' + stores[i].sell_name + '</option>');			
                  } 
                    
                } else {
                    alert('حدث خطأ أثناء الحفظ: ' + response.message);
                }
            },
            error: function(xhr) {
                alert('حدث خطأ في الاتصال بالخادم');
                console.error(xhr.responseText);
            }
        });
  
		 
	}

	function getClients() {

	
  const formData = {
            from: $('#sanf_report_from').val(),
            to: $('#sanf_report_to').val(),
            items: $('#stores').val()
        };

        

	$.ajax({
            url: 'get_clients',
            type: 'POST',
            data: formData,
            headers: {
                'X-CSRF-TOKEN': "{{ csrf_token() }}"
            },
            success: function(response) {
                if (response.success) {
                    
                  var sel = $('#clients').empty();
                  var clients = response.items ;
                  sel.append('<option> Choose Clients</option>');
                  for (var i = 0; i < clients.length; ++i) {
                    sel.append('<option value="' + clients[i].id + '">' + clients[i].name + '</option>');			
                  } 
                    
                } else {
                    alert('حدث خطأ أثناء الحفظ: ' + response.message);
                }
            },
            error: function(xhr) {
                alert('حدث خطأ في الاتصال بالخادم');
                console.error(xhr.responseText);
            }
        });
  
		 
	}
</script>
@endsection