<?php
if (!function_exists('enrep_itemdetails_lev_from_record')) {
    require_once __DIR__ . '/../../functions/itemdetails_json.php';
}
if (isset($cd) && is_array($cd)) {
    $cd = array_replace($cd, enrep_itemdetails_lev_from_record($cd));
}
$cd = array_replace([
    'process' => '',
    'substance' => '',
    'limits' => '',
    'motor_details' => '',
    'number_of_points' => '',
    'number_in_use' => '',
    'returned_to' => '',
    'pri_filter' => '',
    'sec_filter' => '',
    'fan_detail' => '',
    'fan_volume' => '',
    'fan_direction' => '',
], is_array($cd ?? null) ? $cd : []);
if(empty($cd['limits'])){$limits="Refer to HSE Publication EH40/2005 Workplace Exposure Limits 4th Edition";}else{$limits=$cd['limits'];}
?>


<div class="col-12 mb-5">
    <div class="card">
        <div class="card-header">LEV Information</div>
        <div class="card-body">
            <div class="row">
                <div class="col-12 col-md-6">
                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Process requiring LEV</div>
                        <div class="col-md-8"><input class="form-control" name="lev[process]" id="process" value="<?= $cd['process']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Hazardous substance requiring control</div>
                        <div class="col-md-8"><input class="form-control" name="lev[substance]" id="substance" value="<?= $cd['substance']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Work exposure limits of hazardous substance elements</div>
                        <div class="col-md-8"><input class="form-control" name="lev[limits]" id="limits" value="<?= $limits?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Motor Details</div>
                        <div class="col-md-8"><input class="form-control" name="lev[motor_details]" id="motor_details" value="<?= $cd['motor_details']?>"> </div>
                    </div>
                </div>

                <div class="col-12 col-md-6">
                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Number of points</div>
                        <div class="col-md-2"><input class="form-control" name="lev[number_of_points]" id="number_of_points" value="<?= $cd['number_of_points']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Extraction points in use simultaneously</div>
                        <div class="col-md-2"><input class="form-control" name="lev[number_in_use]" id="number_in_use" value="<?= $cd['number_in_use']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Exhaust air returned to</div>
                        <div class="col-md-8"><input class="form-control" name="lev[returned_to]" id="returned_to" value="<?= $cd['returned_to']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Primary Filter</div>
                        <div class="col-md-8"><input class="form-control" name="lev[pri_filter]" id="pri_filter" value="<?= $cd['pri_filter']?>"> </div>
                    </div>

                    <div class="row mb-3">
                        <div class="col-md-3 control-label">Secondary Filter</div>
                        <div class="col-md-8"><input class="form-control" name="lev[sec_filter]" id="sec_filter" value="<?= $cd['sec_filter']?>"> </div>
                    </div>
                </div>
            </div>

            <div class="clearfix"></div>
            <?php
            $fd = [
                $cd['fan_detail'] ?? '',
                $cd['fan_volume'] ?? '',
                $cd['fan_direction'] ?? '',
            ];
?>
            <div class="col-12 col-md-12">
                <div class="row mb-3">
                    <div class="col-md-1 control-label">Fan Details</div>
                    <div class="col-md-2"><input class="form-control" name="lev[fan_detail]" id="fan_detail" value="<?= $fd[0]?>"> </div>
                    <div class="col-md-1"></div>
                    <div class="col-md-1 control-label">Fan Volume</div>
                    <div class="col-md-2"><input class="form-control" name="lev[fan_volume]" id="fan_volume" value="<?= $fd[1]?>"> </div>
                    <div class="col-md-1"></div>

                    <div class="col-md-1 control-label">Fan Direction</div>
                    <div class="col-md-2"><input class="form-control" name="lev[fan_direction]" id="fan_direction" value="<?= $fd[2]?>"> </div>
                </div>
            </div>

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