<?php

/**

 * Staff Contact Information Form

 */

?>

<div id="staff-contact-container">

    <!-- This will be populated by JavaScript based on the current row -->

</div>



<div class="row-counter mt-3">

    <span><i class="fas fa-address-book me-2"></i>Contact Information</span>

</div>



<div class="row">

    <div class="col-md-12" id="staff-contact-fields-container">

        <!-- Fields will be loaded here -->

    </div>

</div>



<script>

function loadStaffContactFields(rowIndex) {

    const container = document.getElementById('staff-contact-fields-container');

    

    let html = `

        <div class="row">

            <div class="col-md-4 mb-3">

                <label class="form-label">Phone <span class="text-danger">*</span></label>

                <input type="tel" class="form-control" name="staff[${rowIndex}][phone]" value="${getFieldValue(rowIndex, 'phone')}" placeholder="024XXXXXXX" required>

            </div>

            <div class="col-md-4 mb-3">

                <label class="form-label">Alternative Phone</label>

                <input type="tel" class="form-control" name="staff[${rowIndex}][tel_no]" value="${getFieldValue(rowIndex, 'tel_no')}" placeholder="024XXXXXXX">

            </div>

            <div class="col-md-4 mb-3">

                <label class="form-label">Email</label>

                <input type="email" class="form-control" name="staff[${rowIndex}][email]" value="${getFieldValue(rowIndex, 'email')}" placeholder="name@example.com">

            </div>

        </div>

        

        <div class="row">

            <div class="col-md-6 mb-3">

                <label class="form-label">Residential Address</label>

                <textarea class="form-control" name="staff[${rowIndex}][residential_address]" rows="2">${getFieldValue(rowIndex, 'residential_address')}</textarea>

            </div>

            <div class="col-md-6 mb-3">

                <label class="form-label">Digital Address</label>

                <input type="text" class="form-control" name="staff[${rowIndex}][digital_address]" value="${getFieldValue(rowIndex, 'digital_address')}">

            </div>

        </div>

    `;

    

    container.innerHTML = html;

}



document.addEventListener('DOMContentLoaded', function() {

    const contactTab = document.getElementById('staff-contact-tab');

    if (contactTab) {

        contactTab.addEventListener('shown.bs.tab', function() {

            const rows = document.querySelectorAll('.data-row');

            rows.forEach((row, index) => {

                loadStaffContactFields(index);

            });

        });

    }

});

</script>