<?php 
if(empty($cd['system_type'])){$cd['system_type']="Compressed Air (Minor System)";}
if(!empty($_REQUEST['clientnumber'])){$d[0]=$_REQUEST['clientnumber'];}
if(empty($cd['changeScheme'])){$cd['changeScheme']="No";}
if(empty($cd['lease_or_hire'])){$cd['lease_or_hire']="No";}
if(empty($cd['history'])){$cd['history']="Makers test when new.";}
if(empty($cd['lastReport'])){$cd['lastReport']="Yes";}
?>

<div class="col-12 mb-5">
    <div class="card">
        <div class="card-header">PSSR Data</div>
        <div class="card-body">
            <div class="row">
                <div class="col-12">

                    <div class="row mb-3">

                        <div class="col-md-6"><label class="control-label" for="scheme_number">Scheme Number</label><?= getPssrNo($d[2],$d[0])?></div>
                        <?php if(!empty($nb)){?> <div class="col-md-2"><a href="javascript:void(0)" onclick="editWSC('<?= getPssrNumber($d[2])?>')" data-mdb-tooltip-init data-mdb-placement="left" data-mdb-trigger="hover" title="Manage WS"
                               class="btn btn-info"
                               title="This item is part of <?= getPssrEno($d[2])?>"><i class="fad fa-cog"></i>&nbsp;View <?= getPssrEno($d[2])?></a></div>
                        <input type="hidden" name="wsnumber" value="<?= getPssrNumber($d[2])?>" ?>
                        <?php }?>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-2"><label class="control-label" for="scheme_number">Use Existing Scheme & Number</label></div>
                        <div class="col-md-3"><input class="form-control" type="text" name="scheme_number_alt" id="scheme_number_alt" value="<?= $cd['scheme_number_alt']?>" /></div>
                        <div class="col-md-3 form-check form-switch">
                            <input type="checkbox" class="form-check-input" name="select_for_scheme" id="select_for_scheme" <?php if($cd['select_for_scheme']==1){?>checked<?php }?>>
                            <label class="form-check-label" for="select_for_scheme">Use Existing Scheme Number</label>
                        </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-2"><label class="control-label" for="system type">System Type</label></div>
                        <div class="col-md-4"><input class="form-control" type="text" name="system_type" id="system_type" value="<?= $cd['system_type']?>" /></div>
                    </div>

                </div>




            </div>
        </div>
    </div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {

    const selectForScheme = document.getElementById('select_for_scheme');
    const wsidata = document.getElementById('WSIDATA');
    const noneButton = document.getElementById('none');
    const datepickerTriggers = document.querySelectorAll('.ui-datepicker-trigger');
    const hasDatepickerElements = document.querySelectorAll('.hasDatepicker');
    const datepickerElements = document.querySelectorAll('.datepicker');
    const tooltipElements = document.querySelectorAll('[data-toggle="tooltip"]');

    // Initial Check
    toggleWSIDATA();

    // Event Listener for Checkbox Change
    selectForScheme.addEventListener('change', toggleWSIDATA);

    function toggleWSIDATA() {
        wsidata.style.display = selectForScheme.checked ? 'none' : 'block';
    }

    // Event Listener for "None" Button Click
    noneButton.addEventListener('click', function() {
        document.getElementById('lastReport').value = 'Not Seen';
    });

    // Datepicker Styling
    datepickerTriggers.forEach(trigger => {
        trigger.classList.add('btn', 'btn-secondary');
    });

    hasDatepickerElements.forEach(element => {
        element.style.zIndex = "1";
    });

    datepickerElements.forEach(element => {
        element.style.zIndex = "1";
    });

    // Tooltip Activation
    tooltipElements.forEach(element => {
        // Assuming you have a custom tooltip implementation or using a library
        activateTooltip(element); // Replace with your actual tooltip activation code
    });

});
</script>