<?php if (count($this->servers) == 0) { ?>
    <div class="alert alert-danger">
        <?php echo $this->user->lang('No cPanel / WHM servers are setup.'); ?>
    </div>
<?php } else { ?>

<script src="../plugins/import/whmaccounts/PluginWhmaccounts.js?version=<?php echo $this->gVersion; ?>"></script>

<div class="card mb-3">
    <div class="card-body">
            <div class="col-auto d-flex align-items-center">
                <label for="server-select" class="form-label mb-0">
                    <?php echo $this->user->lang('Select Server:'); ?>
                </label>
            </div>

            <div class="col-auto">
                <select name="server" id="server-select" class="form-select select2">
                    <option value="--">----</option>
                    <?php foreach ($this->servers as $server) { ?>
                        <option
                            value="<?php echo $server['id']; ?>"
                            <?php if ($this->serverId == $server['id']) echo 'selected'; ?>
                        >
                            <?php echo $server['name']; ?>
                        </option>
                    <?php } ?>
                </select>
            </div>
    </div>
</div>

<?php if ($this->serverId > 0) { ?>

    <table class="table table-striped align-middle">
        <thead class="table-light">
            <tr>
                <th></th>
                <th><?php echo $this->user->lang('Username'); ?></th>
                <th><?php echo $this->user->lang('Domain'); ?></th>
                <th><?php echo $this->user->lang('Plan'); ?></th>
                <th><?php echo $this->user->lang('Clientexec Product'); ?></th>
            </tr>
        </thead>

        <tbody>
        <?php foreach ($this->accounts as $account) { ?>
            <tr>
                <input type="hidden" name="<?php echo $account['user']; ?>_user" value="<?php echo $account['user']; ?>">
                <input type="hidden" name="<?php echo $account['user']; ?>_domain" value="<?php echo $account['domain']; ?>">
                <input type="hidden" name="<?php echo $account['user']; ?>_email" value="<?php echo $account['email']; ?>">

                <td>
                    <input type="checkbox"
                           class="form-check-input"
                           name="<?php echo $account['user']; ?>_selected">
                </td>

                <td><?php echo $account['user']; ?></td>
                <td><?php echo $account['domain']; ?></td>
                <td><?php echo $account['plan']; ?></td>

                <td>
                    <label class="form-label mb-1">Product:</label>
                    <select name="<?php echo $account['user']; ?>_product"
                            class="form-select select2">
                        <?php
                        foreach ($this->packages as $key => $cat) {
                            echo "<optgroup label='Groups of type: ".$this->packageGroups[$key]['name']."'>";
                            foreach ($cat as $value => $productgroup) {
                                echo "<option value='".$value."'>".$productgroup."</option>";
                            }
                            echo "</optgroup>";
                        }
                        ?>
                    </select>
                </td>
            </tr>
        <?php } ?>

            <tr>
                <td colspan="5">
                    <button id="importButton" class="cm-btns orange">
                        <?php echo $this->user->lang('Import Accounts'); ?>
                    </button>
                </td>
            </tr>
        </tbody>
    </table>

<?php } ?>
<?php } ?>
