<?php
if (!isset($placanjeOptions) || !is_array($placanjeOptions)) {
    $placanjeOptions = [];
}

$placanjeValue = $placanjeValue ?? '';
$pdvStopaValue = isset($pdvStopaValue) ? (int)$pdvStopaValue : 10;

$cenaBezPdvValue = $cenaBezPdvValue ?? '';
$cenaSaPdvValue = $cenaSaPdvValue ?? '';
$cenaEurBezPdvValue = $cenaEurBezPdvValue ?? '';
$cenaEurSaPdvValue = $cenaEurSaPdvValue ?? '';
?>

<div class="row">
    <div class="col-md-4 mb-3">
        <label for="placanje" class="form-label">Plaćanje</label>
        <select class="form-select" id="placanje" name="placanje">
            <option value="">Izaberi način plaćanja</option>
            <?php foreach ($placanjeOptions as $nacin): ?>
                <option value="<?php echo htmlspecialchars($nacin); ?>" <?php echo ($nacin === $placanjeValue) ? 'selected' : ''; ?>>
                    <?php echo htmlspecialchars($nacin); ?>
                </option>
            <?php endforeach; ?>
        </select>
    </div>

    <?php if (isAdmin()): ?>
        <div class="col-md-2 mb-3">
            <label for="pdv_stopa" class="form-label">PDV</label>
            <select class="form-select" id="pdv_stopa" name="pdv_stopa">
                <option value="10" <?php echo $pdvStopaValue === 10 ? 'selected' : ''; ?>>10%</option>
                <option value="20" <?php echo $pdvStopaValue === 20 ? 'selected' : ''; ?>>20%</option>
            </select>
        </div>

        <div class="col-md-3 mb-3">
            <label for="cena_bez_pdv" class="form-label">Cena bez PDV-a</label>
            <input type="number" step="0.01" class="form-control" id="cena_bez_pdv" name="cena_bez_pdv" placeholder="0.00" value="<?php echo htmlspecialchars($cenaBezPdvValue); ?>">
            <div class="form-text">Cena u RSD</div>
        </div>

        <div class="col-md-3 mb-3">
            <label for="cena" class="form-label">Cena sa PDV-om (<span class="pdv_percent_text"><?php echo htmlspecialchars((string)$pdvStopaValue); ?>%</span>)</label>
            <input type="number" step="0.01" class="form-control" id="cena" name="cena" placeholder="0.00" value="<?php echo htmlspecialchars($cenaSaPdvValue); ?>">
            <div class="form-text">Cena u RSD</div>
        </div>
    <?php endif; ?>
</div>

<?php if (isAdmin()): ?>
<div class="row">
    <div class="col-md-3 mb-3">
        <label for="cena_eur_bez_pdv" class="form-label">Cena bez PDV-a</label>
        <input type="number" step="0.01" class="form-control" id="cena_eur_bez_pdv" name="cena_eur_bez_pdv" placeholder="0.00" value="<?php echo htmlspecialchars($cenaEurBezPdvValue); ?>">
        <div class="form-text">Cena u EUR</div>
    </div>

    <div class="col-md-3 mb-3">
        <label for="cena_eur" class="form-label">Cena sa PDV-om (<span class="pdv_percent_text"><?php echo htmlspecialchars((string)$pdvStopaValue); ?>%</span>)</label>
        <input type="number" step="0.01" class="form-control" id="cena_eur" name="cena_eur" placeholder="0.00" value="<?php echo htmlspecialchars($cenaEurSaPdvValue); ?>">
        <div class="form-text">Cena u EUR</div>
    </div>
</div>
<?php endif; ?>

