<?php

/**
 * Copyright © Resurs Bank AB. All rights reserved.
 * See LICENSE for license details.
 */

declare(strict_types=1);

/** @var Costs $this */

use Resursbank\Ecom\Lib\Model\PaymentMethod;
use Resursbank\Ecom\Module\PaymentMethod\Widget\Costs;

$paymentMethods = $this->paymentMethods;
?>

<style>
  .rb-payment-methods {
    border-collapse: collapse;
    font-family: Arial, Helvetica, sans-serif;
    display: flex;
    flex-direction: column;
    row-gap: 30px;
  }

  .rb-payment-methods,
  .rb-payment-methods * {
    box-sizing: border-box;
  }

  .rb-payment-methods th {
    text-align: left;
    padding: 15px 10px;
    font-weight: 600;
  }

  .rb-payment-methods td {
    padding: 15px 10px !important;
  }

  .rb-payment-methods table {
    border-collapse: collapse;
  }

  .rb-payment-methods thead {
    background-color: #dddddd;
    color: rgb(46, 46, 46);
    border: 1px solid rgb(192, 192, 192);
  }

  .rb-payment-methods tbody {
    color: white;
    border: 1px solid #006464;
  }

  .rb-payment-methods tbody tr:last-child {
    border-bottom: 1px solid #009b91;
  }

  .rb-payment-methods tbody tr:nth-child(even) {
    background-color: #006464;
  }

  .rb-payment-methods tbody tr:nth-child(odd) {
    background-color: #009b91;
  }

  .rb-payment-methods-warning {
    font-family: Arial, Helvetica, sans-serif;
    border: 1px solid #9c7d05;
    background: #f5dd7f;
    color: #242424;
    padding: 15px;
  }
</style>

<?php

if (count($paymentMethods) !== 0) : ?>
  <div class="rb-payment-methods">
    <table>
      <thead>
      <tr>
        <th><?= htmlspecialchars(string: $this->nameLabel) ?></th>
        <th><?= htmlspecialchars(string: $this->minTotalLabel) ?></th>
        <th><?= htmlspecialchars(string: $this->maxTotalLabel) ?></th>
        <th><?= htmlspecialchars(string: $this->sortOrderLabel) ?></th>
      </tr>
      </thead>
      <tbody>
      <?php /** @var PaymentMethod $method */ ?>
      <?php

foreach ($paymentMethods as $method) : ?>
        <tr id="rb-pm-<?= $method->getId() ?>">
          <td><?= htmlspecialchars(string: $method->getName()) ?></td>
          <td><?= number_format(
	num: $method->getMinLimit(),
	decimals: 2
) ?></td>
          <td><?= number_format(
	num: $method->getMaxLimit(),
	decimals: 2
) ?></td>
          <td><?= $method->getSortOrder() ?></td>
        </tr>
      <?php endforeach;

 ?>
      </tbody>
    </table>
  </div>
<?php else : ?>
  <p class="rb-payment-methods-warning">
      <?= $this->missingWarning ?>
  </p>
<?php endif; ?>
