<style>
    .pricing-card .table {
        font-size: 12px;
    }

    .pricing-card .form-control-sm {
        font-size: 12px;
    }

    .pricing-card th {
        white-space: nowrap;
    }
</style>

<script data-cfasync="false" type="text/javascript">
    $(document).ready(function() {
        $('.price').on('keydown', function (e) {
            if ($.inArray(e.keyCode, [46,8,9,27,13,110,190]) !== -1 ||
                ((e.keyCode == 65 || e.keyCode == 67 || e.keyCode == 86) && e.ctrlKey === true) ||
                (e.keyCode >= 35 && e.keyCode <= 39)) {
                return;
            }
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) &&
                (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        });
    });

    function productPricingFilterBy(el, filter) {
        $(el).closest('.nav-pills').find('.nav-link').removeClass('active');
        $(el).addClass('active');

        $('.currencyprice').hide();
        $('.currencyCode' + filter).show();
    }
</script>

<?php
include_once 'modules/billing/models/CurrencyGateway.php';
$gateway = new CurrencyGateway($this->user);
$currencies = $gateway->GetCurrencies();
?>

<div class="container-fluid fieldwrapper pricing-card">

<?php if ($currencies['totalcount'] > 1) { ?>
<ul class="nav nav-pills mb-3">
<?php foreach ($currencies['currencies'] as $currencyValues) { ?>
    <li class="nav-item">
        <a class="nav-link <?php if ($currencyValues['isdefault']) echo 'active default-language-tab'; ?>"
           href="javascript:void(0)"
           onclick="productPricingFilterBy(this,'<?php echo $currencyValues['abrv']; ?>')">
            <?php echo $currencyValues['name']; ?>
        </a>
    </li>
<?php } ?>
</ul>
<?php } ?>

<div class="card shadow-sm">
    <div class="card-header fw-semibold">
        <?php echo $this->user->lang("Pricing"); ?>
    </div>

    <div class="card-body p-0">
        <form id="pricingtab">

            <table class="table table-striped align-middle mb-0">
                <thead class="table-light">
                <tr>
                    <th style="width:150px;"></th>
                    <th class="text-center"><?php echo $this->user->lang("Price");?></th>
                    <th class="text-center"><?php echo $this->user->lang("Setup");?></th>
                    <th class="text-center"><?php echo $this->user->lang("Allow in signup?");?></th>
                    <th></th>
                </tr>
                </thead>

                <tbody>

<?php foreach ($this->priceExtraData as $cycle => $extraDataValues) {
    if ($cycle == 0) continue; ?>

                <tr>
                    <td class="fw-semibold">
                        <?php echo $this->user->lang($extraDataValues['price_name']);?>
                    </td>

                    <!-- PRICE -->
                    <td class="text-center">
<?php if ($currencies['totalcount'] > 1) {
foreach ($currencies['currencies'] as $currencyValues) { ?>
                        <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                              <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                            <input class="form-control form-control-sm price text-end"
                                   style="width:60px"
                                   name="<?php echo $currencyValues['abrv']; ?>_price<?php echo $cycle; ?>"
                                   value="<?php echo $this->priceExtraDataCurrencies[$currencyValues['abrv']][$cycle]['price']; ?>">
                        </span>
<?php }} else { ?>
                        <input class="form-control form-control-sm price text-end"
                               style="width:60px"
                               name="price<?php echo $cycle; ?>"
                               value="<?php echo $extraDataValues['price']; ?>">
<?php } ?>
                    </td>

                    <!-- SETUP -->
                    <td class="text-center">
<?php if ($currencies['totalcount'] > 1) {
foreach ($currencies['currencies'] as $currencyValues) { ?>
                        <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                              <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                            <input class="form-control form-control-sm price text-end"
                                   style="width:60px"
                                   name="<?php echo $currencyValues['abrv']; ?>_setup<?php echo $cycle; ?>"
                                   value="<?php echo $this->priceExtraDataCurrencies[$currencyValues['abrv']][$cycle]['setup']; ?>">
                        </span>
<?php }} else { ?>
                        <input class="form-control form-control-sm price text-end"
                               style="width:60px"
                               name="setup<?php echo $cycle; ?>"
                               value="<?php echo $extraDataValues['setup']; ?>">
<?php } ?>
                    </td>

                   <!-- ALLOW SIGNUP -->
<td class="text-center">
<?php if ($currencies['totalcount'] > 1) {
    foreach ($currencies['currencies'] as $currencyValues) { ?>
        <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
              <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
            <input type="checkbox"
                   class="form-check-input"
                   name="<?php echo $currencyValues['abrv']; ?>_price<?php echo $cycle; ?>_checked"
                   value="1"
                   <?php if ($this->priceExtraDataCurrencies[$currencyValues['abrv']][$cycle]['price_checked']) echo 'checked'; ?>
                   <?php if ($currencyValues['isdefault']) echo 'id="maincurrencyprice'.$cycle.'_checked"'; ?>>
        </span>
<?php }
} else { ?>
        <input type="checkbox"
               class="form-check-input"
               name="price<?php echo $cycle; ?>_checked"
               value="1"
               <?php if ($extraDataValues['price_checked']) echo 'checked'; ?>
               id="maincurrencyprice<?php echo $cycle; ?>_checked">
<?php } ?>
</td>



                    <td></td>
                </tr>

<?php } ?>

    <!-- ONE-TIME FEE -->
    <tr class="table-light">
        <td class="fw-semibold">
            <?php echo $this->user->lang($this->priceExtraData[0]['price_name']);?>
        </td>

        <!-- price0 (per-currency when multi-currency) -->
        <td colspan="2">
    <?php if ($currencies['totalcount'] > 1) {
        foreach ($currencies['currencies'] as $currencyValues) { ?>
            <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                  <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                <input class="form-control form-control-sm price text-end"
                       style="width:60px"
                       name="<?php echo $currencyValues['abrv']; ?>_price0"
                       value="<?php echo $this->priceExtraDataCurrencies[$currencyValues['abrv']][0]['price']; ?>"
                       <?php if ($currencyValues['isdefault']) echo 'id="maincurrencyprice0"'; ?>>
            </span>
    <?php }
    } else { ?>
            <input class="form-control form-control-sm price text-end"
                   style="width:60px"
                   name="price0"
                   value="<?php echo $this->priceExtraData[0]['price']; ?>"
                   id="maincurrencyprice0">
    <?php } ?>
        </td>

        <!-- price0_checked (per-currency when multi-currency) -->
        <td class="text-center">
    <?php if ($currencies['totalcount'] > 1) {
        foreach ($currencies['currencies'] as $currencyValues) { ?>
            <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                  <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                <input type="checkbox"
                       class="form-check-input"
                       name="<?php echo $currencyValues['abrv']; ?>_price0_checked"
                       value="1"
                       <?php if ($this->priceExtraDataCurrencies[$currencyValues['abrv']][0]['price_checked']) echo 'checked'; ?>
                       <?php if ($currencyValues['isdefault']) echo 'id="maincurrencyprice0_checked"'; ?>>
            </span>
    <?php }
    } else { ?>
            <input type="checkbox"
                   class="form-check-input"
                   name="price0_checked"
                   value="1"
                   <?php if ($this->priceExtraData[0]['price_checked']) echo 'checked'; ?>
                   id="maincurrencyprice0_checked">
    <?php } ?>
        </td>

        <td></td>
    </tr>



                <!-- LATE FEE -->
    <tr>
        <td class="fw-semibold"><?php echo $this->user->lang("Late Fee");?></td>
        <td colspan="4">
    <?php if ($currencies['totalcount'] > 1) {
        foreach ($currencies['currencies'] as $currencyValues) { ?>
            <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                  <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                <input class="form-control form-control-sm price text-end"
                       style="width:80px"
                       name="<?php echo $currencyValues['abrv']; ?>_latefee"
                       value="<?php echo $this->priceMoreDataCurrencies[$currencyValues['abrv']]['latefee']; ?>"
                       <?php if ($currencyValues['isdefault']) echo 'id="maincurrencylatefee"'; ?>>
            </span>
    <?php }
    } else { ?>
            <input class="form-control form-control-sm price text-end"
                   style="width:80px"
                   name="latefee"
                   value="<?php echo $this->latefee; ?>"
                   id="maincurrencylatefee">
    <?php } ?>
        </td>
    </tr>


    <!-- TAXABLE -->
    <tr>
        <td colspan="5">
    <?php if ($currencies['totalcount'] > 1) {
        foreach ($currencies['currencies'] as $currencyValues) { ?>
            <span class="currencyprice currencyCode<?php echo $currencyValues['abrv']; ?>"
                  <?php if (!$currencyValues['isdefault']) echo 'style="display:none"'; ?>>
                <div class="form-check">
                    <input class="form-check-input"
                           type="checkbox"
                           name="<?php echo $currencyValues['abrv']; ?>_taxable"
                           value="1"
                           <?php if ($this->priceMoreDataCurrencies[$currencyValues['abrv']]['taxable']) echo 'checked'; ?>
                           <?php if ($currencyValues['isdefault']) echo 'id="maincurrencytaxable"'; ?>>
                    <label class="form-check-label">
                        <?php echo $this->user->lang("Product is Taxable?");?>
                    </label>
                </div>
            </span>
    <?php }
    } else { ?>
            <div class="form-check">
                <input class="form-check-input"
                       type="checkbox"
                       name="taxable"
                       value="1"
                       <?php if ($this->taxable) echo 'checked'; ?>
                       id="maincurrencytaxable">
                <label class="form-check-label">
                    <?php echo $this->user->lang("Product is Taxable?");?>
                </label>
            </div>
    <?php } ?>
        </td>
    </tr>


                </tbody>

                <tfoot>
                <tr>
                    <td colspan="5">
                        <div class="alert alert-info mb-2">
                            <?php echo $this->user->lang(
                                'Addon prices for billing cycles not used in this product will not be available to the client, unless you select the force show option in the addon setup screen.'
                            ); ?>
                        </div>

                        <div class="d-flex justify-content-end">
                            <button type="submit" class="submit-pricing cm-btns orange">
                                <?php echo $this->user->lang("Save Changes");?>
                            </button>
                        </div>
                    </td>
                </tr>
                </tfoot>

            </table>
        </form>
    </div>
</div>

</div>
