<?php
$this->js_css->parse_js('ciext/translate/js/translate.js');
$this->js_css->parse_css('ciext/translate/css/translate.css');
?>
<a href="<?= base_url($this->config->item('admin_page') . '/translate/keys') ?>" class="btn keys-btn"><i class="fa fa-hand-paper-o" aria-hidden="true"></i> <?= $this->lang->line('Keys') ?></a>
<ul class="nav nav-tabs">
    <?php foreach ($langs as $lang) : ?>
        <li <?= $lang['id_lan'] == $current_lang ? 'class="active"' : '' ?>>
            <a href="<?= $values_link . '/' . $lang['id_lan'] ?>"><?= $lang['name'] ?></a>
        </li>
    <?php endforeach; ?>
</ul>
<div class="container">
    <?php if ($this->session->flashdata('translate_message')) : ?>
        <label class="alert alert-<?= $this->session->flashdata('translate_class') ?>"><?= $this->session->flashdata('translate_message') ?></label>
    <?php endif; ?>
    <div class="progress progress-success active">
        <div class="bar" style="width: <?= (int) (count(array_filter($values)) / count($lines) * 100) ?>%;">
            <?= count(array_filter($values)) . '/' . count($lines) ?>
        </div>
    </div>
    <?= form_open_multipart($import_link, ['id' => 'import_form', 'class' => 'form-top-actions'], ['lan' => $current_lang]) ?>
    <div class="btn-group">
        <a href="<?= $export_link ?>" class="btn" download="download"><i class="fa fa-cloud-download" aria-hidden="true"></i> <?= $this->lang->line('Export') ?></a>
        <button class="btn dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu">
            <?php foreach ($langs as $lang) : ?>
                <li>
                    <a href="<?= $export_link . '?example=' . $lang['id_lan'] ?>" download="download">+ <?= $this->lang->line('Example') . ' (' . $lang['name'] . ')' ?></a>
                </li>
            <?php endforeach; ?>
        </ul>
    </div>
    <div class="btn-group">
        <label class="btn btn-default">
            <i class="fa fa-cloud-upload" aria-hidden="true"></i> <?= $this->lang->line('Import') ?>
            <input style="display:none" type="file" accept=".xlsx" name="import" id="import_file">
        </label>
    </div>
    <?= form_close() ?>
    <?= form_open($save_link, ['class' => 'form-horizontal', 'id' => 'trans_form'], ['lan' => $current_lang]) ?>
    <div class="form-top-actions">
        <input type="submit" class="btn btn-success" name="save" value="<?= $this->lang->line('Save') ?>">
        <a href="<?= $values_link ?>" class="btn"><?= $this->lang->line('Cancel') ?></a>
    </div>
    <?php foreach ($lines as $key => $line) : ?>
        <div class="control-group">
            <label for="item_<?= $key ?>"><?= (in_array($line, $diff) ? '<i class="fa fa-hand-paper-o" aria-hidden="true"></i> ' : '') . $line ?></label>
            <div <?= isset($imported[$line]) ? '' : 'class="ignore_me"' ?>>
                <?= form_hidden('line[' . $key . ']', $line) ?>
                <?= form_hidden('id[' . $key . ']', isset($lines_ids[$line]) ? $lines_ids[$line] : 0) ?>
                <textarea name="value[<?= $key ?>]" class="span10 trans_text" id="item_<?= $key ?>" placeholder="<?= $this->lang->line('For example') . ': ' . $this->lang->line($line) ?>"><?= isset($values[$line]) ? $values[$line] : '' ?></textarea>
                <?php if (!isset($values[$line]) && $line != $this->lang->line('For example')) : ?>
                    <a href="#" class="btn btn-primary set_example" data-text="<?= htmlspecialchars($this->lang->line($line)) ?>">
                        <i class="fa fa-cloud-download" aria-hidden="true"></i>
                        &nbsp;<?= $this->lang->line('Set default text') ?>
                    </a>
                <?php endif; ?>
            </div>
        </div>
    <?php endforeach; ?>
    <div class="form-actions">
        <input type="submit" class="btn btn-success" name="save" value="<?= $this->lang->line('Save') ?>">
        <a href="<?= $values_link ?>" class="btn"><?= $this->lang->line('Cancel') ?></a>
    </div>
    <?= form_close() ?>
</div>