<?php $__env->startSection('content'); ?>

<div class="main-mobile-header doc-mobile-header">
      <a id="menuLink" href="#" class="menu-link"><i class="ri-menu-line"></i></a>
    </div>

   

    



     <div class="main main-app p-3 p-lg-4">
     	
        <div class="mb-4">
          <ol class="breadcrumb fs-sm mb-1">
            <li class="breadcrumb-item"><a href="#">Dashboard</a></li>
            <li class="breadcrumb-item active" aria-current="page">Edit Configuration</li>
          </ol>
        </div>

      

      <div class="">
        
        <div class="row">

          <div class="col-lg-8">
            <h2 class="main-title">Edit Configuration</h2>
            
          </div>
          <div style="text-align: right;" class="col-lg-4 text-right">
             <!--<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addTrailer">Add Trailers</button> -->
          <button style="" id="submitButton" class="btn btn-primary">Save</button>
            <!-- <a href="/form" class="btn btn-primary">Add Taxmaster</a>  -->
          </div>

        </div>

        <hr class="main-separator">        
<script>
$(document).ready(function() {
    $("#submitButton").click(function() {
        // Perform any client-side validation here if needed
       var data = $("#configuration").val();
       if(data!==''){
            // Submit the form when the button is clicked
            $("#myForm").submit(); 
       }
        
      
    });
});
</script>
            
<div class="card card-shadow-apply">
    <div class="card-body">
        
    <div style="text-align: -webkit-right;">
     <div class="axle-btns">
       <button id="removeButton">-</button>
       <div>Axle</div>
       <button id="generateButton">+</button> 
     </div>
    </div>
    
    <form id="myForm" action="/trailer/configuration/save" method="post">
        <?php echo csrf_field(); ?>
        <input type="hidden" name="trailer_id" value="<?php echo e($id); ?>">
        <input type="hidden" name="axle_tyre_configuration" id="configuration" value="" required>
        <div style="text-align: center; margin-top: 20px;">
          <button style="width:  50%; display: none;" class="btn btn-primary">Save</button>
        </div>
    </form>
    
    
    <div class="row">
    


    <div class="col-lg-12">
            <div class="space">
        
    <!-- <label for="noTireInput">Enter Number of Tires: </label>
    <input type="number" id="noTireInput" placeholder="Number of Tires"> -->
    
    

        <div style="text-align: center;"><h4>Trailer No: <?php echo e($id); ?></h4></div>
    <div class="vehicle">
        
        <!-- JavaScript code to generate the axle sections -->
        <script>
            var vehicleId = <?php echo e($id); ?>;

            var vehicleData = <?php echo json_encode($data, 15, 512) ?>;
        

        function installVehicle(vehicleId) {

            // Function to generate the HTML structure for the front axle
            function generateFrontAxleHTML(data) {
                
                // Create the first rod element
    var firstRod = document.createElement('div');
    firstRod.style.width = '80px';
    firstRod.style.height = '80px';
    firstRod.style.borderRadius = '80px';
    firstRod.style.display = 'flex';
    firstRod.style.alignItems = 'center';
    firstRod.style.justifyContent = 'center';
    // firstRod.style.fontSize = '30px';
    firstRod.className = 'rod';
    // firstRod.textContent = 'X';
    
    // Create the <i> element
    // var iconElement = document.createElement('i');
    // iconElement.className = 'ri-close-circle-fill';
    // iconElement.style.fontSize = '50px';

    // // Append the <i> element under the first rod
    // firstRod.appendChild(iconElement);

    // Create the second rod element
    var secondRod = document.createElement('div');
    secondRod.className = 'rod';
                
                var frontAxleDiv = document.createElement('div');
                frontAxleDiv.className = 'front';

                data.tire_labels_left.forEach(function (label) {
                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'wheel';

                    leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftTireLink);
                    frontAxleDiv.appendChild(leftTireDiv);

                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.alignItems = 'center';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'rim';

                    // leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftWheelDiv);
                    frontAxleDiv.appendChild(leftTireDiv);

                });

                var middleDiv = document.createElement('div');
                middleDiv.style.width = '200px';
                middleDiv.style.background = 'darkgray';
                middleDiv.style.height = '10px';
                middleDiv.style.borderRadius = '10px';
                middleDiv.style.border = '1px solid #c1a1a1';
                middleDiv.style.marginTop = '16px';

                var middleInnerDiv = document.createElement('div');
                middleInnerDiv.style.width = '20px';
                middleInnerDiv.style.background = 'darkgray';
                middleInnerDiv.style.height = '50px';
                middleInnerDiv.style.border = '2px solid #c1a1a1';
                middleInnerDiv.style.margin = 'auto';

                var middleInnerDiv1 = document.createElement('div');
                middleInnerDiv1.className = 'tyre_btn';
                middleInnerDiv1.setAttribute('data-position', data.position);
                middleInnerDiv1.style.width = '40px';
                middleInnerDiv1.style.background = 'black';
                middleInnerDiv1.style.height = '40px';
                middleInnerDiv1.style.border = '2px solid #c1a1a1';
                middleInnerDiv1.style.margin = 'auto';
                middleInnerDiv1.style.position = 'relative';
                middleInnerDiv1.style.top = '-20px';
                middleInnerDiv1.style.right = '12px';
                middleInnerDiv1.style.borderRadius = '30px';
                middleInnerDiv1.style.display = 'flex';
                middleInnerDiv1.style.color = '#fff';
                middleInnerDiv1.style.justifyContent = 'center';
                middleInnerDiv1.style.alignItems = 'center';
                middleInnerDiv1.style.fontSize = '40px';
                if(data.no_tyre==2){
                  middleInnerDiv1.textContent='+';                    
                }
                else{
                  middleInnerDiv1.textContent='-';                    

                }
                
                // Create the <i> element
            //     var addElement = document.createElement('i');
            //     addElement.className = 'ri-add-line';
            //     addElement.style.fontSize = '40px';
                
            //      var removeElement = document.createElement('i');
            //     removeElement.className = 'ri-subtract-line';
            //     removeElement.style.fontSize = '40px';

            //   // Append the <i> element under the first rod

            //     if(data.no_tyre==2){
            //     //   middleInnerDiv1.textContent='+';                    
            //          middleInnerDiv1.appendChild(addElement);
            //     }
            //     else{
            //     //   middleInnerDiv1.textContent='-';                    
            //          middleInnerDiv1.appendChild(removeElement);

            //     }
                

                middleInnerDiv.appendChild(middleInnerDiv1);

                middleDiv.appendChild(middleInnerDiv);
                frontAxleDiv.appendChild(middleDiv);

                data.tire_labels_right.forEach(function (label) {

                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.alignItems = 'center';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'rim';

                    // rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightWheelDiv);
                    frontAxleDiv.appendChild(rightTireDiv);


                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'wheel';

                    rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightTireLink);
                    frontAxleDiv.appendChild(rightTireDiv);
                });

                var rodDiv = document.createElement('div');
                rodDiv.className = 'rod';

                var vehicleContainer = document.querySelector('.vehicle');
                vehicleContainer.appendChild(firstRod);
                vehicleContainer.appendChild(secondRod);
                vehicleContainer.appendChild(frontAxleDiv);
                vehicleContainer.appendChild(rodDiv);
            }

            // Function to generate the HTML structure for the middle axle
            function generateMiddleAxleHTML(data) {
                var middleAxleDiv = document.createElement('div');
                middleAxleDiv.className = 'front';

                data.tire_labels_left.forEach(function (label) {
                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'wheel';

                    leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftTireLink);
                    middleAxleDiv.appendChild(leftTireDiv);

                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.alignItems = 'center';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'rim';

                    leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftTireLink);
                    middleAxleDiv.appendChild(leftTireDiv);
                });
                

                var middleDiv = document.createElement('div');
                middleDiv.style.width = '200px';
                middleDiv.style.background = 'darkgray';
                middleDiv.style.height = '10px';
                middleDiv.style.borderRadius = '10px';
                middleDiv.style.border = '1px solid #c1a1a1';
                middleDiv.style.marginTop = '16px';

                var middleInnerDiv = document.createElement('div');
                middleInnerDiv.style.width = '20px';
                middleInnerDiv.style.background = 'darkgray';
                middleInnerDiv.style.height = '100px';
                middleInnerDiv.style.border = '2px solid #c1a1a1';
                middleInnerDiv.style.margin = 'auto';
                middleInnerDiv.style.position = 'relative';
                middleInnerDiv.style.bottom = '50px';

                var middleInnerDiv1 = document.createElement('div');
                middleInnerDiv1.className = 'tyre_btn';
                middleInnerDiv1.setAttribute('data-position', data.position);
                middleInnerDiv1.style.width = '40px';
                middleInnerDiv1.style.background = 'black';
                middleInnerDiv1.style.height = '40px';
                middleInnerDiv1.style.border = '2px solid #c1a1a1';
                middleInnerDiv1.style.margin = 'auto';
                middleInnerDiv1.style.position = 'relative';
                middleInnerDiv1.style.top = '30px';
                middleInnerDiv1.style.right = '12px';
                middleInnerDiv1.style.borderRadius = '30px';
                middleInnerDiv1.style.display = 'flex';
                middleInnerDiv1.style.color = '#fff';
                middleInnerDiv1.style.justifyContent = 'center';
                middleInnerDiv1.style.alignItems = 'center';
                middleInnerDiv1.style.fontSize = '40px';
                if(data.no_tyre==2){
                  middleInnerDiv1.textContent='+';                    
                }
                else{
                  middleInnerDiv1.textContent='-';                    

                }

                middleInnerDiv.appendChild(middleInnerDiv1);

                middleDiv.appendChild(middleInnerDiv);
                middleAxleDiv.appendChild(middleDiv);

                data.tire_labels_right.forEach(function (label) {
                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.alignItems = 'center';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'rim';

                    rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightTireLink);
                    middleAxleDiv.appendChild(rightTireDiv);


                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'wheel';

                    rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightTireLink);
                    middleAxleDiv.appendChild(rightTireDiv);
                });

                var rodDiv = document.createElement('div');
                rodDiv.className = 'rod';

                var vehicleContainer = document.querySelector('.vehicle');
                vehicleContainer.appendChild(middleAxleDiv);
                vehicleContainer.appendChild(rodDiv);
            }

            // Function to generate the HTML structure for the rear axle
            function generateRearAxleHTML(data) {
                var rearAxleDiv = document.createElement('div');
                rearAxleDiv.className = 'front';

                data.tire_labels_left.forEach(function (label) {
                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'wheel';

                    leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftTireLink);
                    rearAxleDiv.appendChild(leftTireDiv);


                    var leftTireDiv = document.createElement('div');
                    leftTireDiv.style.display = 'flex';
                    leftTireDiv.style.alignItems = 'center';
                    leftTireDiv.style.flexDirection = 'column';
                    leftTireDiv.textContent = label;

                    var leftTireLink = document.createElement('a');
                    leftTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var leftWheelDiv = document.createElement('div');
                    leftWheelDiv.className = 'rim';

                    leftTireLink.appendChild(leftWheelDiv);
                    leftTireDiv.appendChild(leftTireLink);
                    rearAxleDiv.appendChild(leftTireDiv);
                });

                var middleDiv = document.createElement('div');
                middleDiv.style.width = '200px';
                middleDiv.style.background = 'darkgray';
                middleDiv.style.height = '10px';
                middleDiv.style.borderRadius = '10px';
                middleDiv.style.border = '1px solid #c1a1a1';
                middleDiv.style.marginTop = '16px';

                var middleInnerDiv = document.createElement('div');
                middleInnerDiv.style.width = '20px';
                middleInnerDiv.style.background = 'darkgray';
                middleInnerDiv.style.height = '50px';
                middleInnerDiv.style.border = '2px solid #c1a1a1';
                middleInnerDiv.style.margin = 'auto';
                middleInnerDiv.style.position = 'relative';
                middleInnerDiv.style.bottom = '50px';

                var middleInnerDiv1 = document.createElement('div');
                middleInnerDiv1.className = 'tyre_btn';
                middleInnerDiv1.setAttribute('data-position', data.position);
                middleInnerDiv1.style.width = '40px';
                middleInnerDiv1.style.background = 'black';
                middleInnerDiv1.style.height = '40px';
                middleInnerDiv1.style.border = '2px solid #c1a1a1';
                middleInnerDiv1.style.margin = 'auto';
                middleInnerDiv1.style.position = 'relative';
                middleInnerDiv1.style.top = '30px';
                middleInnerDiv1.style.right = '12px';
                middleInnerDiv1.style.borderRadius = '30px';
                middleInnerDiv1.style.display = 'flex';
                middleInnerDiv1.style.color = '#fff';
                middleInnerDiv1.style.justifyContent = 'center';
                middleInnerDiv1.style.alignItems = 'center';
                middleInnerDiv1.style.fontSize = '40px';
                if(data.no_tyre==2){
                  middleInnerDiv1.textContent='+';                    
                }
                else{
                  middleInnerDiv1.textContent='-';                    

                }

                middleInnerDiv.appendChild(middleInnerDiv1);

                middleDiv.appendChild(middleInnerDiv);
                rearAxleDiv.appendChild(middleDiv);

                data.tire_labels_right.forEach(function (label) {
                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.alignItems = 'center';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'rim';

                    rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightTireLink);
                    rearAxleDiv.appendChild(rightTireDiv);


                    var rightTireDiv = document.createElement('div');
                    rightTireDiv.style.display = 'flex';
                    rightTireDiv.style.flexDirection = 'column';
                    rightTireDiv.textContent = label;

                    var rightTireLink = document.createElement('a');
                    rightTireLink.href = '/trailer/add/tyre/' + vehicleId + '/' + label;

                    var rightWheelDiv = document.createElement('div');
                    rightWheelDiv.className = 'wheel';

                    rightTireLink.appendChild(rightWheelDiv);
                    rightTireDiv.appendChild(rightTireLink);
                    rearAxleDiv.appendChild(rightTireDiv);
                });

                var vehicleContainer = document.querySelector('.vehicle');
                vehicleContainer.appendChild(rearAxleDiv);
            }

            // Loop through vehicle data and generate HTML based on axle type
            vehicleData.forEach(item => {
                if (item.axle === 'Front Axle') {
                    generateFrontAxleHTML(item);
                } 
            });

            vehicleData.forEach(item => {
                if (item.axle === 'Middle Axle') {
                    generateMiddleAxleHTML(item);
                } 
            });

            vehicleData.forEach(item => {
                if (item.axle === 'Rear Axle') {
                    generateRearAxleHTML(item);
                }
            });

        }

        installVehicle(vehicleId);

        document.getElementById('generateButton').addEventListener('click', function () {
    var vehicle = document.querySelector('.vehicle');
    vehicle.innerHTML = ''; // This will remove all child elements and their content

    // const axleName = document.getElementById('axleInput').value;
    // const numberOfaxle = parseInt(document.getElementById('noTireInput').value);
    const numberOfaxle = 1; // Change this to the actual number of axles to add
    const numberOfTires = 2;
    const numberOfRims = numberOfTires;

    if (isNaN(numberOfTires)) {
        alert('Please enter a valid number for the number of tires.');
        return;
    }

    // Function to find the next available position
    function findNextPosition() {
        if (vehicleData.length === 0) {
            return 'F';
        } else if (vehicleData.length === 1) {
            return 'R';
        } else {
            const existingPositions = vehicleData.map(item => item.position);
            let nextPosition = 1;
            while (existingPositions.includes(nextPosition.toString())) {
                nextPosition++;
            }
            return nextPosition.toString();
        }
    }

    for (let i = 0; i < numberOfaxle; i++) {
        const position = findNextPosition();
         let axle;
        
        if (position === 'F') {
            axle = 'Front Axle';
        } else if (position === 'R') {
            axle = 'Rear Axle';
        } else {
            axle = 'Middle Axle';
        }

        const tireLabelsLeft = [];
        const tireLabelsRight = [];

        // Generate tire labels based on the number of tires
        for (let j = 0; j < numberOfTires; j++) {
            if (numberOfTires === 2) {
                const tireLabel = position + (j === 0 ? 'L' : 'R') + '0';
                if (j === 0) {
                    tireLabelsLeft.push(tireLabel);
                } else {
                    tireLabelsRight.push(tireLabel);
                }
            } else {
                const tireLabel = position + (j % 2 === 0 ? 'L' : 'R') + Math.floor(j / 2);
                if (j % 2 === 0) {
                    tireLabelsLeft.push(tireLabel);
                } else {
                    tireLabelsRight.push(tireLabel);
                }
            }
        }


        const rimLabelsLeft = [];
const rimLabelsRight = [];

// Generate rim labels based on the number of rims
for (let j = 0; j < numberOfRims; j++) {
    if (numberOfRims === 2) {
        const rimLabel = position + (j === 0 ? 'L' : 'R') + '0';
        if (j === 0) {
            rimLabelsLeft.push(rimLabel);
        } else {
            rimLabelsRight.push(rimLabel);
        }
    } else {
        const rimLabel = position + (j % 2 === 0 ? 'L' : 'R') + Math.floor(j / 2);
        if (j % 2 === 0) {
            rimLabelsLeft.push(rimLabel);
        } else {
            rimLabelsRight.push(rimLabel);
        }
    }
}


        vehicleData.push({
            'axle': axle,
            'no_tyre': numberOfTires,
            'position': position,
            'tire_labels_left': tireLabelsLeft,
            'tire_labels_right': tireLabelsRight,
            'rim_labels_left': rimLabelsLeft,
            'rim_labels_right': rimLabelsRight,
        });
    }

    const jsonData = JSON.stringify(vehicleData, null, 2);
    installVehicle();
    
    var axle_configuration = document.querySelector('#configuration');
    axle_configuration.value= jsonData;

    // Log the JSON data to the console
    console.log(jsonData);
});


        // Event listener for the "Remove" button
document.getElementById('removeButton').addEventListener('click', function () {
    var vehicle = document.querySelector('.vehicle');
            vehicle.innerHTML = ''; // This will remove all child elements and their content
    // Check if there are any axles to remove
    if (vehicleData.length > 0) {
        // Remove the last axle from the vehicleData array
        vehicleData.pop();

        // Reinstall the updated vehicle configuration
        installVehicle();

        // Log the updated JSON data to the console
        const jsonData = JSON.stringify(vehicleData, null, 2);
        console.log(jsonData);
        
        var axle_configuration = document.querySelector('#configuration');
       axle_configuration.value= jsonData;
    
    } else {
        alert('No axles to remove.');
    }
});

// Event listener for the "Update Tires" button
// document.getElementById('updateTiresButton').addEventListener('click', function () {
//     var vehicle = document.querySelector('.vehicle');
//     vehicle.innerHTML = ''; // This will remove all child elements and their content
//     // const updatedNumberOfTires = parseInt(document.getElementById('updateTiresInput').value);
//     var tyrebtn = document.querySelector('.tyre_btn'); // Replace 'yourElementId' with the actual ID or element reference
//     console.log('hi')
//     var customTypeValue = tyrebtn.getAttribute('data-position');
//         console.log('bi')

//     console.log(customTypeValue); // This will log the value of the 'data-tyre-type' attribute

//     const updatedNumberOfTires = 8;
//     var position = 'R';

//     // Check if the entered value is a valid number
//     if (isNaN(updatedNumberOfTires) || updatedNumberOfTires < 0) {
//         alert('Please enter a valid number of tires.');
//         return;
//     }

    

//                 const tireLabelsLeft = [];
//                 const tireLabelsRight = [];

//                 // Generate tire labels based on the number of tires
//                 for (let j = 0; j < updatedNumberOfTires; j++) {
//                     if (updatedNumberOfTires === 2) {
//                         const tireLabel = position + (j === 0 ? 'L' : 'R') + '0';
//                         if (j === 0) {
//                             tireLabelsLeft.push(tireLabel);
//                         } else {
//                             tireLabelsRight.push(tireLabel);
//                         }
//                     } else {
//                         const tireLabel = position + (j % 2 === 0 ? 'L' : 'R') + Math.floor(j / 2);
//                         if (j % 2 === 0) {
//                             tireLabelsLeft.push(tireLabel);
//                         } else {
//                             tireLabelsRight.push(tireLabel);
//                         }
//                     }
//                 }
               

//     // Loop through the vehicleData and update numberOfTires where position is '1'
//     vehicleData.forEach(function (item) {
//         if (item.position === 'R') {
//             item.no_tyre = updatedNumberOfTires;
//             item.tire_labels_left = tireLabelsLeft;
//             item.tire_labels_right = tireLabelsRight;
//         }
//     });

//     // Reinstall the updated vehicle configuration
//     installVehicle();

//     // Log the updated JSON data to the console
//     const jsonData = JSON.stringify(vehicleData, null, 2);
//     console.log(jsonData);
// });


document.querySelector('.vehicle').addEventListener('click', function (event) {

    

    const clickedElement = event.target;
        let updatedNumberOfTires;

    // Check if the clicked element has the class 'tyre_btn'
    if (clickedElement.classList.contains('tyre_btn')) {
        

        const position = clickedElement.getAttribute('data-position');
        const currentText = clickedElement.textContent;

        if (currentText === '+') {
            clickedElement.textContent = '-';
            clickedElement.classList.add('minus');
             updatedNumberOfTires = 4;

        } else if (currentText === '-') {
            clickedElement.textContent = '+';
            clickedElement.classList.remove('minus');
             updatedNumberOfTires = 2;
        }

        console.log(position);

    // var position = 'R';
      

                const tireLabelsLeft = [];
                const tireLabelsRight = [];

                // Generate tire labels based on the number of tires
                for (let j = 0; j < updatedNumberOfTires; j++) {
                    if (updatedNumberOfTires === 2) {
                        const tireLabel = position + (j === 0 ? 'L' : 'R') + '0';
                        if (j === 0) {
                            tireLabelsLeft.push(tireLabel);
                        } else {
                            tireLabelsRight.push(tireLabel);
                        }
                    } else {
                        const tireLabel = position + (j % 2 === 0 ? 'L' : 'R') + Math.floor(j / 2);
                        if (j % 2 === 0) {
                            tireLabelsLeft.push(tireLabel);
                        } else {
                            tireLabelsRight.push(tireLabel);
                        }
                    }
                }
               

    // Loop through the vehicleData and update numberOfTires where position is '1'
    vehicleData.forEach(function (item) {
        if (item.position === position) {
            item.no_tyre = updatedNumberOfTires;
            item.tire_labels_left = tireLabelsLeft;
            item.tire_labels_right = tireLabelsRight;
        }
    });

    // Reinstall the updated vehicle configuration
    var vehicle = document.querySelector('.vehicle');
    vehicle.innerHTML = ''; 

    installVehicle();

    // Log the updated JSON data to the console
    const jsonData = JSON.stringify(vehicleData, null, 2);
    console.log(jsonData);
    
    var axle_configuration = document.querySelector('#configuration');
    axle_configuration.value= jsonData;
    
    }
});





        </script>
    </div>
</div>
        
        
    
    </div>
    
    </div>


    </div>
</div>





        <br><br><br>


<div class="modal" id="addTrailer">
  <div class="modal-dialog modal-md">
    <div class="modal-content">
      <!-- Modal Header -->
      <div class="modal-header" >
        <h4 class="modal-title">Add Trailer Tyre</h4>
        <button type="button" class="btn-close" data-bs-dismiss="modal" style="margin-top: 1px;"></button>
      </div>
      <!-- Modal body -->
      <div class="modal-body" style="margin-top: -15px;">
        <div class="card-body">
          <form action="/document/store" method="POST" id="cat" enctype="multipart/form-data">
          <?php echo csrf_field(); ?>
          <br>
          <div class="row">
              
            <div class="col-sm-12">
                <div class="mb-3">
                    <label class="form-label">Date
                <span class="required-field">*</span>
              </label>
                <input type="date" name="brand" id="date" class="form-control" required>
                </div>
            </div>
            
            </div>
            
            <div class="row">

                       
            <div class="col-sm-12">
                <div class="mb-3">
                    <label class="form-label">Trailer
                <span class="required-field">*</span>
              </label>
                <!--<input type="text" name="type" id="type" class="form-control" required>-->
                <select class="form-select">
                    <option>TR0001</option>
                    <option>TR0002</option>
                    <option>TR0003</option>
                </select>
                </div>
            </div>
            
           
            
            <!--<div class="col-sm-12">-->
            <!--    <div class="mb-3">-->
            <!--        <label class="form-label">Attachment-->
            <!--    <span class="required-field">*</span>-->
            <!--  </label>-->
            <!--    <input type="text" name="attachment" id="attachment" class="form-control" required>-->
            <!--    </div>-->
            <!--</div>-->
            
            <div class="col-sm-12">
                <div class="mb-3">
                    <label class="form-label">Remark
                <span class="required-field">*</span>
              </label>
                <!--<input type="text" name="description" id="description" class="form-control" required>-->
                <textarea name="description" id="description" class="form-control"></textarea>
                </div>
            </div>
            
                                        
          </div><!-- Row -->
          <div class="buttons-alignment mt-4 ml-auto">
            <button type="submit" class="btn btn-primary">Submit</button>
          </div>
                </form>
        </div>
      </div>
    </div>
  </div>
</div>

        

      </div><!-- container -->

     
    <style>
    tbody tr:hover {background-color: #F5F5F5;}
    .card-example>.card-body::before {
    content: ""
    }
    </style>
    
        <style>
        /* Vehicle Container */
        .front {
            display: flex;
            align-items: center;
        }

        /* Left Wheel */
        .wheel {
            width: 25px;
            height: 60px;
            background: radial-gradient(#b5aeae, #312e2e);
            border-radius: 20px;
            margin: 0 5px;
        }
        .wheel-danger{
            background: radial-gradient(#f7f7f7, #ed1010)!important;
        }
        .wheel-zero{
            background: radial-gradient(#f7f7f7, #d1b9b9)!important;
        }
        .wheel-green{
            background: radial-gradient(#f7f7f7, #27a511)!important;
        }
        
        .rim {
            width: 10px;
    height: 30px;
    background: radial-gradient(#b5aeae, #a19999);
    border-radius: 20px;
    margin: 0 5px;
        }

        /* Vehicle Body */
        .body {
            width: 100px;
            height: 40px;
            background-color: #333;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        /* Middle Bar */
        .bar {
            width: 10px;
            height: 40px;
            background-color: #333;
        }
        .vehicle{
            display: flex;
    flex-direction: column;
    align-items: center;
        }
        .space{
            width: 500px;
            margin: 30px auto;
        }
        .rod{
            margin-right: 3px;
            width: 4px;
            padding: 8px;
            height: 102px;
            background: darkgray;
            border: 2px solid #c1a1a1;
    
        }
    </style>
    
    <style type="text/css">
     .axle-btns {
    display: flex;
    background: gray;
    width: 200px;
    align-items: center;
    padding: 8px;
    border-radius: 5px;
}

.axle-btns button {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    width: 30px;
    height: 30px;
    border: none;
    font-size: 24px;
    cursor: pointer;
}

.axle-btns button#removeButton {
    color: red;
    margin-right: 10px;
}

.axle-btns button#generateButton {
    color: green;
    margin-left: 10px;
}

.axle-btns div {
    flex-grow: 1;
    text-align: center;
    font-size: 20px;
    color: white;
}
   
</style>



<script>

</script>


<script>
    $(document).ready(function() {
        $("#tour_package").validate({
            rules: {
                package_name: {
                    required: true,
                    maxlength: 20,
                },
                destination: {
                    required: true,
                    maxlength: 20,
                },
                days: {
                    required: true,
                    maxlength: 20,
                },
                hotel_type: {
                    required: true,
                    maxlength: 20,
                },
                meal: {
                    required: true,
                    maxlength: 20,
                },
                currency: {
                    required: true,
                    maxlength: 20,
                },
                price_per_person: {
                    required: true,
                    maxlength: 20,
                },
            },
            messages: {
                package_name: {
                    required: "Package Name is required",
                    maxlength: "Package Name cannot be more than 20 characters"
                },

                destination: {
                    required: "Destination  is required",
                    maxlength: "Destination  cannot be more than 20 characters",
                },

                days: {
                    required: "Day is required",
                    maxlength: "Day cannot be more than 20 characters",
                },

                hotel_type: {
                    required: "Hotel is required",
                    maxlength: "Hotel cannot be more than 20 characters",
                },

                meal: {
                    required: "Meal Price is required",
                    maxlength: "Meal Price cannot be more than 20 characters",
                },

                currency: {
                    required: "Currency is required",
                    maxlength: "Currency cannot be more than 20 characters",
                },

                price_per_person: {
                    required: "Price is required",
                    maxlength: "Price cannot be more than 20 characters",
                },

            }
        });
    });

    $('.select2').select2();
</script>

<?php $__env->stopSection(); ?>


<?php echo $__env->make('layout.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/u842563099/domains/codesquarry.online/public_html/tms/resources/views/trailer/edit_configuration.blade.php ENDPATH**/ ?>