<div id="templates-inputs-colheader" style="display: grid; gap: 1rem; grid-template-columns:30px repeat(5,1fr);">
    <div></div>
    <div class="templates-input-inputname">Product Name</div>
    <div class="templates-input-certificate">Certificate</div>
    <div class="templates-input-cost">Per Kg</div>
    <div class="templates-input-qty">Grams or Ea</div>
    <div class="templates-input-inputcost">Cost</div>
</div>

<?php $inputcss = 'templates-inputs-odd'; ?>
<div id="templates-inputs-data" style="display: grid; row-gap: 0.35rem; grid-template-columns:40px repeat(5,1fr);">
    <?php $total = 0.0; ?>
    <?php $subtotalweight = 0; ?>
    <?php $subtotalcost = 0.0; ?>
    <?php $currentinputtypeid = 0; ?>
    <?php foreach ($templateinputs as $templateinput): ?>
        <?php
        if ($templateinput->InputTypeID != $currentinputtypeid) {
            if($currentinputtypeid > 0){
                echo "<div class='templates-inputtypes' style='grid-column: 4;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#808080; border-width:0.5px; text-align:center;'>Sub Totals</div>";
                echo "<div class='templates-inputtypes' style='grid-column: 5;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#808080; border-width:0.5px; text-align:right;'>$subtotalweight</div>";
                echo "<div class='templates-inputtypes' style='grid-column: 6;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#808080; border-width:0.5px; text-align:right;'>£ ".number_format($subtotalcost,2)."</div>";
                $subtotalcost = 0.0;
                $subtotalweight = 0;
            }
            $currentinputtypeid = $templateinput->InputTypeID;
            echo "<div class='templates-inputtypes' style='grid-column: 1 / span 6;
                    background-color:#DCDCDC; border-style:solid; 
                    border-color:#80808; border-width:0.5px;'>$templateinput->InputType</div>";
        }
        ?>
        <div>
            <?php if ($template->showRemove): ?>
                <a class="templates-remove-input" title="DELETE line" href="<?= site_url('/templateinputs/') . $template->TemplateID . '/' . $templateinput->TemplateInputID . '/delete' ?>">X</a>
            <?php else: ?>
                <div></div>
            <?php endif; ?>
        </div>
        <div class="<?= $inputcss ?> templates-input-inputname">
            <?= $templateinput->InputName ?>
        </div>
        <div class="<?= $inputcss ?> templates-input-certification">
            <?= esc($templateinput->Certification) ?>
        </div>
        <div class="<?= $inputcss ?> templates-input-cost">
            £ <?= number_format($templateinput->Cost, 2) ?>
        </div>
        <div class="<?= $inputcss ?> templates-input-qty">
            <?= number_format($templateinput->Qty, 0) ?>
        </div>
        <div class="<?= $inputcss ?> templates-input-inputcost">
            £ <?= number_format($templateinput->InputCost, 2) ?>
            <?php $total += (float)$templateinput->InputCost; ?>
        </div>
        <?php 
            $subtotalcost += (float)$templateinput->InputCost;
            $subtotalweight += (int)$templateinput->Qty;
            $inputcss == 'templates-inputs-odd' ? $inputcss = 'templates-inputs-even' : $inputcss = 'templates-inputs-odd'; 
        ?>
    <?php endforeach; 
    echo "<div class='templates-inputtypes' style='grid-column: 4;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#080808; border-width:0.5px; text-align:center;'>Sub Totals</div>";
                echo "<div class='templates-inputtypes' style='grid-column: 5;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#080808; border-width:0.5px; text-align:right;'>$subtotalweight</div>";
                echo "<div class='templates-inputtypes' style='grid-column: 6;
                background-color:#dcdcdc; border-style:solid; 
                border-color:#080808; border-width:0.5px; text-align:right;'>£ ".number_format($subtotalcost,2)."</div>";
                $subtotalcost = 0.0;
                $subtotalweight = 0;
    ?>
</div>
<div id="templates-summary" style="display: grid; gap: 1rem; grid-template-columns:30px repeat(5,1fr); background-color:#a9a9a9;">
    <div></div>
    <div><b>Total Cost</b></div>
    <div></div>
    <div></div>
    <div></div>
    <div class="templates-input-cost"
        style="background-color:#a9a9a9; border-style:solid; 
                border-color:#a9a9a9; border-width:0.5px;font-weight: bold;">£
        <?= number_format($total, 2) ?></div>
</div>