{% set gpm = admin.gpm() %}
{% set installed = gpm.isPluginInstalled(admin.route) %}
{% set isTestingRelease = gpm.isTestingRelease(plugin.slug) %}
{% set gumroad_loaded = false %}

<div class="grav-update plugin" data-gpm-plugin="{{ admin.route }}">
</div>

<h1>
    {{ plugin.name }}
    {% if admin.isTeamGrav(plugin) %}
        <small><span class="info-reverse"><i class="fa fa-check-circle" title="{{ "PLUGIN_ADMIN.GRAV_OFFICIAL_PLUGIN"|t }}"></i></span></small>
    {% endif %}
    {% if admin.isPremiumProduct(plugin) %}
        <small><span class="badge warning premium"><i class="fa fa-star-o"></i> {{ "PLUGIN_ADMIN.PREMIUM_PRODUCT"|t }}</span></small>
    {% endif %}
    {% if plugin.symlink %}
    <small class="hint--bottom" data-hint="{{ "PLUGIN_ADMIN.PLUGIN_SYMBOLICALLY_LINKED"|t }}">
        <i class="fa fa-fw fa-link"></i>
    </small>
    {% endif %}
    <small>{{ plugin.version ? 'v' ~ plugin.version }}</small>
    {% if isTestingRelease %}<span class="gpm-testing">test release</span>{% endif %}
</h1>
<div class="gpm-item-info">
    <i class="gpm-item-icon fa fa-fw fa-{{ plugin.icon }}"></i>
    {% include 'partials/plugin-data.html.twig' with { plugin: plugin } %}
</div>

{% if (installed) %}
    {% set data = admin.data('plugins/' ~ admin.route) %}
    {% if data.get('enabled') %}
      {% include 'partials/blueprints.html.twig' with { data: data, blueprints: data.blueprints } %}
    {% else %}
      <form>
        <div class="form-field grid">
          <div class="form-label block size-1-3">
            <label>{{ "PLUGIN_ADMIN.PLUGINS_MUST_BE_ENABLED"|t }}</label>
          </div>
          <div class="form-data block size-2-3">
            <a class="button" href="{{ uri.addNonce(base_url_relative ~ '/plugins/' ~ plugin.slug ~ '/task' ~ config.system.param_sep ~ 'enable', 'admin-form', 'admin-nonce') ~ '/redirect:true' }}">
              <i class="fa fa-power-off" aria-hidden="true"></i> {{ "PLUGIN_ADMIN.ENABLE"|t }} <strong>{{ plugin.name }}</strong>
            </a>
          </div>
        </div>
      </form>
    {% endif %}
    {% if (plugin.form.fields.enabled.type != 'hidden' and plugin.form.fields.tabs.fields.login.fields.enabled.type != 'hidden') %}
        <div class="button-bar danger">
            <span class="danger-zone"></span>
            {% if not plugin.symlink %}
                <a class="button button-reinstall-package hidden" href="#" data-remodal-target="reinstall-package"><i class="fa fa-fw fa-repeat"></i> {{ "PLUGIN_ADMIN.REINSTALL_PLUGIN"|t }}</a>
            {% endif %}
            <a class="button" href="#" data-remodal-target="remove-package"><i class="fa fa-fw fa-warning"></i> {{ "PLUGIN_ADMIN.REMOVE_PLUGIN"|t }}</a>
        </div>
    {% endif %}
{% else %}
    <div class="button-bar success">
        {% if (plugin.premium and not admin.license(plugin.slug)) %}
            {% set permalink = plugin.premium.permalink|default(null) %}
            {% if permalink %}
                {% set checkout_url = 'https://licensing.getgrav.org/buy/' ~ permalink %}
                {% set success_url = 'https://licensing.getgrav.org/portal?checkout=success&checkout_id={CHECKOUT_ID}' %}
                {% set final_checkout_url = checkout_url ~ '?success_url=' ~ success_url|url_encode %}
                <a class="button" href="{{ final_checkout_url }}" target="_blank"><i class="fa fa-shopping-cart"></i> {{ plugin.premium.button|default('Purchase') }}</a>
            {% endif %}
        {% else %}
            <a class="button" href="#" data-remodal-target="add-package" data-packages-slugs="{{ plugin.slug }}" data-plugin-action="start-package-installation"><i class="fa fa-plus"></i> {{ "PLUGIN_ADMIN.INSTALL_PLUGIN"|t }}</a>
        {% endif %}
    </div>
{% endif %}

{% include 'partials/modal-changes-detected.html.twig' %}
{% include 'partials/modal-add-package.html.twig' with { type: 'plugin' } %}
{% include 'partials/modal-update-packages.html.twig' with { type: 'plugin' } %}
{% include 'partials/modal-remove-package.html.twig' with { type: 'plugin', package: plugin } %}
{% include 'partials/modal-reinstall-package.html.twig' with { type: 'plugin', package: plugin } %}
{% include 'partials/modal-changelog.html.twig' with { package: plugin} %}
