<?php 
 use App\Http\Controllers\TreatmentController;
 if(file_exists('json_files/json-file.json')){ 
    $json = file_get_contents('json_files/json-file.json');
    //Decode JSON
    $json_data = json_decode($json,true);
    $results = array();
    }
    $i=1;
    if($rncnt > 0){
    foreach($data as $result2){    
        $treatdur = $result2->TreatDur1;
        $treatdate = (new TreatmentController)->getTreatDate2($treatdur);
?>

<tr>
    <td align="center" valign="top"><input class="form-check-input" type="checkbox" value="1" id="TreatChk{{$i}}"
            name="TreatChk{{$i}}" onclick="treatcheck('TreatChk{{$i}}')" checked>
    </td>
    <td>
        <select class="form-control" name="TreatType{{$i}}" id="TreatType{{$i}}" style="height:35px;"  onchange="getDrugByType(this.value,{{$i}})">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatType'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>" <?php if($result2->TreatType1 == $result['Values']){?>
                selected <?php } ?>>
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>

        <input class="form-control" type="text" name="TreatName{{$i}}" list="Treat_Name1" id="TreatName{{$i}}"
            value="{{$result2['TreatName1']}}" onClick="this.select();" style="height:35px;"
            oninput="getTreatNameDetails('TreatName{{$i}}','TreatDose{{$i}}','TreatFreq{{$i}}')" style="height:35px;">
        <datalist id="Treat_Name{{$i}}" class="treatments">
            @foreach($TreatName as $result)
            <option value="{{$result->TreatName}}">
                @endforeach
        </datalist>
    </td>
    <td>
        <select class="form-control" name="TreatDose{{$i}}" id="TreatDose{{$i}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatDose'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>" <?php if($result2->TreatDose1 == $result['Values']){?>
                selected <?php } ?>>
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>
        <select class="form-control" name="TreatFreq{{$i}}" id="TreatFreq{{$i}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatFreq'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>" <?php if($result2->TreatFreq1 == $result['Values']){?>
                selected <?php } ?>>
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>
        <select class="form-control" name="TreatDur{{$i}}" id="TreatDur{{$i}}" style="height:35px;"
            onchange="getTreatDate({{$i}},this.value)">

            <option value="" selected>...</option>
            @foreach($durationList as $result)
            <option value="{{$result->Duration}}" <?php if($result2->TreatDur1 == $result->Duration){?> selected
                <?php } ?>>
                {{$result->Duration}}</option>
            @endforeach
        </select>


    </td>
    <!-- <td>
        <input class="form-control" type="date" name="TreatDate{{$i}}" id="TreatDate{{$i}}" value="{{$treatdate}}"
            style="height:31px;"></td> -->
    <td>
        <select class="form-control" name="TreatEye{{$i}}" id="TreatEye{{$i}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatEye'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>" <?php if($result2->TreatEye1 == $result['Values']){?>
                selected <?php } ?>>
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <!-- <td> -->
    @if($i > 1)           
    <!-- <input type="checkbox" value="1" id="Tapchk{{$i}}" name="Tapchk{{$i}}" onclick="checkTap({{$i-1}},{{$i}})" >&nbsp;<label for="Tapchk{{$i}}">Tap</label> -->
@endif
<!-- </td> -->
</tr>
<?php $i++;}} 
for($i2=$rncnt+1;$i2<=10;$i2++){
?>
<tr>
    <td align="center" valign="top"><input class="form-check-input" type="checkbox" value="1" id="TreatChk{{$i2}}"
            name="TreatChk{{$i2}}" onclick="treatcheck('TreatChk{{$i2}}')">
    </td>
    <td>
        <select class="form-control" name="TreatType{{$i2}}" id="TreatType{{$i2}}" style="height:35px;"  onchange="getDrugByType(this.value,{{$i2}})">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatType'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>">
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>
        <input class="form-control" onClick="this.select();" type="text"
            oninput="getTreatNameDetails('TreatName{{$i2}}','TreatDose{{$i2}}','TreatFreq{{$i2}}')"
            name="TreatName{{$i2}}" list="Treat_Name3" id="TreatName{{$i2}}" value="" style="height: 35px;">
        <datalist id="Treat_Name{{$i2}}" class="treatments">
            @foreach($TreatName as $result)
            <option value="{{$result->TreatName}}">
                @endforeach
        </datalist>

    </td>
    <td>
        <select class="form-control" name="TreatDose{{$i2}}" id="TreatDose{{$i2}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatDose'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>">
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>
        <select class="form-control" name="TreatFreq{{$i2}}" id="TreatFreq{{$i2}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatFreq'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>">
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <td>
        <select class="form-control" name="TreatDur{{$i}}" id="TreatDur{{$i}}" style="height:35px;"
            onchange="getTreatDate({{$i2}},this.value)">

            <option value="" selected>...</option>
            @foreach($durationList as $result)
            <option value="{{$result->Duration}}">
                {{$result->Duration}}</option>
            @endforeach
        </select>


    </td>
    <!-- <td><input class="form-control" type="date" name="TreatDate{{$i2}}" id="TreatDate{{$i2}}" value=""
            style="height:31px;"></td> -->
    <td>
        <select class="form-control" name="TreatEye{{$i2}}" id="TreatEye{{$i2}}" style="height:35px;">

            <option value="" selected>...</option>
            <?php
foreach($json_data['JsonData']['TreatEye'] as $result) {?>
            <option value="<?php echo $result['Values']; ?>">
                {{$result['Values']}}</option>
            <?php } ?>
        </select>

    </td>
    <!-- <td> -->
    @if($i2 > 1)          
        <!-- <input type="checkbox" value="1" id="Tapchk{{$i2}}" name="Tapchk{{$i2}}" onclick="checkTap({{$i2}})">&nbsp;<label for="Tapchk{{$i2}}">Tap</label> -->
        @endif
    <!-- </td> -->
</tr>
<?php }  ?>