{% import 'macro_functions.html.twig' as mf %}

<div class="card-body">
    <form method="post" action="{{ 'product/update_config'|api_url }}" {{ fb_api_form({message: 'License Settings Updated'|trans}) }}>
        <div class="mb-5">
            <div class="mb-3">
                <h3 class="card-title mb-1">{{ 'License Settings'|trans }}</h3>
                <p class="text-secondary mb-0">{{ 'Configure how license keys are generated for this product and which validation rules should apply to issued licenses.'|trans }} <a href="https://docs.fossbilling.org/admin-guide/product-types/license/" target="_blank" rel="noopener noreferrer">{{ 'Learn more'|trans }}</a></p>
            </div>
            <div class="row g-3">
                <div class="col-lg-4">
                    <label class="form-label">{{ 'Prefix'|trans }}</label>
                    <input type="text" class="form-control" name="config[prefix]" value="{{ product.config.prefix }}">
                </div>
                <div class="col-lg-4">
                    <label class="form-label">{{ 'Length'|trans }}</label>
                    <input type="number" class="form-control" name="config[length]" value="{{ product.config.length }}">
                </div>
                <div class="col-lg-4">
                    <label class="form-label">{{ 'Plugin'|trans }}</label>
                    {{ mf.selectbox('config[plugin]', admin.servicelicense_plugin_get_pairs, product.config.plugin, 1) }}
                </div>
            </div>
        </div>

        <hr class="my-4" />

        <div class="mb-4">
            <div class="mb-3">
                <h3 class="card-title mb-1">{{ 'Validation Rules'|trans }}</h3>
                <p class="text-secondary mb-0">{{ 'Choose which environment checks clients must satisfy when validating a license.'|trans }}</p>
            </div>
            <div class="row g-3">
                <div class="col-lg-3">
                    <label class="form-label">{{ 'Validate IP'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1">
                        <label class="form-check">
                            <input class="form-check-input" id="validateIPYes" type="radio" name="config[validate_ip]" value="1"{% if product.config.validate_ip %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check">
                            <input class="form-check-input" id="validateIPNo" type="radio" name="config[validate_ip]" value="0"{% if not product.config.validate_ip %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                </div>
                <div class="col-lg-3">
                    <label class="form-label">{{ 'Validate Hostname'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1">
                        <label class="form-check">
                            <input class="form-check-input" id="validateHostnameYes" type="radio" name="config[validate_host]" value="1"{% if product.config.validate_host %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check">
                            <input class="form-check-input" id="validateHostnameNo" type="radio" name="config[validate_host]" value="0"{% if not product.config.validate_host %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                </div>
                <div class="col-lg-3">
                    <label class="form-label">{{ 'Validate Version'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1">
                        <label class="form-check">
                            <input class="form-check-input" id="validateVersionYes" type="radio" name="config[validate_version]" value="1"{% if product.config.validate_version %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check">
                            <input class="form-check-input" id="validateVersionNo" type="radio" name="config[validate_version]" value="0"{% if not product.config.validate_version %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                </div>
                <div class="col-lg-3">
                    <label class="form-label">{{ 'Validate Path'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1">
                        <label class="form-check">
                            <input class="form-check-input" id="validatePathYes" type="radio" name="config[validate_path]" value="1"{% if product.config.validate_path %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check">
                            <input class="form-check-input" id="validatePathNo" type="radio" name="config[validate_path]" value="0"{% if not product.config.validate_path %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                </div>
            </div>
        </div>

        <input type="hidden" name="id" value="{{ product.id }}">
        <div class="d-flex justify-content-end">
            <button class="btn btn-primary" type="submit">{{ 'Update'|trans }}</button>
        </div>
    </form>

    <hr class="my-4" />

    <div>
        <h3 class="card-title mb-2">{{ 'License Plugins'|trans }}</h3>
        <p>{{ 'You can create your own license generation plugins for FOSSBilling. Follow these steps to add a new one:'|trans }}</p>
        <ul>
            <li>{{ 'A license plugin is a PHP class named'|trans }} <strong>License_PluginName</strong> {{ 'that must include a'|trans }} <code>generate</code> {{ 'method.'|trans }}</li>
            <li>{{ 'See the default example plugin at'|trans }} <strong>/modules/Servicelicense/Plugin/Simple.php</strong></li>
            <li>{{ 'Save your custom plugin in'|trans }} <strong>/modules/Servicelicense/Plugin/PluginName.php</strong></li>
            <li>{{ 'FOSSBilling will automatically detect your new plugin.'|trans }}</li>
            <li><a href="https://docs.fossbilling.org/admin-guide/product-types/license/#custom-license-plugins" target="_blank" rel="noopener noreferrer">{{ 'Read the documentation'|trans }}</a> {{ 'for more details.'|trans }}</li>
        </ul>
    </div>
</div>
