<?php

use common\helpers\GlobalParam;
use domain\Producer\Producer\ProducerModule;
use yii\helpers\Html;

$producerModule = ProducerModule::getInstance();
$producer = GlobalParam::getCurrentProducer();

$countBlockInfos = 0;
if($producer->order_infos && strlen($producer->order_infos)) {
    $countBlockInfos ++;
}
if($producer->option_payment_info && strlen($producer->option_payment_info)) {
    $countBlockInfos ++;
}
if($producerModule->hasSpecificDelays($producer)) {
    $countBlockInfos ++;
}

$classColumn = $countBlockInfos ? 'col-lg-'.(12 / $countBlockInfos) : 'col-lg-12';
?>

<?php if($countBlockInfos): ?>
    <div class="row" id="block-infos">
        <?php if($producer->order_infos && strlen($producer->order_infos)): ?>
            <div class="<?= $classColumn ?> col-md-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">
                            <i class="bi bi-info-circle"></i>
                            Infos
                        </h5>
                        <div class="card-text">
                            <?= nl2br(Html::encode($producer->order_infos)); ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <?php if($producer->option_payment_info && strlen($producer->option_payment_info)): ?>
            <div class="<?= $classColumn ?> col-md-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">
                            <i class="bi bi-wallet2"></i>
                            Paiement
                        </h5>
                        <div class="card-text">
                            <?= nl2br(Html::encode($producer->option_payment_info)); ?>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>
        <?php
        if ($producerModule->hasSpecificDelays($producer)): ?>
            <div class="<?= $classColumn ?> col-md-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">
                            <i class="bi bi-clock"></i>
                            Délais de commande
                        </h5>
                        <table class="table table-bordered">
                            <?php foreach ($producerModule->getSpecificDelays($producer) as $day => $delay): ?>
                                <?php if ($delay['order_delay'] && $delay['order_deadline']): ?>
                                    <tr>
                                        <td>
                                            <?php
                                            switch ($day) {
                                                case 'monday':
                                                    echo 'Lundi';
                                                    break;
                                                case 'tuesday':
                                                    echo 'Mardi';
                                                    break;
                                                case 'wednesday':
                                                    echo 'Mercredi';
                                                    break;
                                                case 'thursday':
                                                    echo 'Jeudi';
                                                    break;
                                                case 'friday':
                                                    echo 'Vendredi';
                                                    break;
                                                case 'saturday':
                                                    echo 'Samedi';
                                                    break;
                                                case 'sunday':
                                                    echo 'Dimanche';
                                                    break;
                                            }
                                            ?>
                                        </td>
                                        <td>
                                            <span><?= $delay['order_delay'] ?> jour<?= ($delay['order_delay'] > 1) ? 's' : '' ?></span>
                                            à l'avance,
                                            avant
                                            <span><?= ($delay['order_deadline'] == 24) ? 'minuit' : $delay['order_deadline'] . 'h'; ?></span>
                                        </td>
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </table>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>