<?php

namespace GriffinForms\Admin\Html\FormControls\Form;

class LifetimeSubmissionCount extends \GriffinForms\Admin\Html\FormControls\Form\Format
{
    public function html()
    {
        $count = is_numeric($this->value) ? (int) $this->value : 0;
        $formatted = number_format_i18n($count);
        $form_id = isset($this->data['item_id']) ? absint($this->data['item_id']) : 0;
        $nonce = wp_create_nonce('reset_lifetime_submission_count');

        echo '<div class="row">';
        echo '<div class="col-md-12 mb-3" id="griffinforms-lifetimesubmissioncount-wrap">';
        echo '<div class="d-flex flex-wrap align-items-center gap-2">';
        echo '<span class="fw-medium">' . esc_html($this->lang->getText('lifetime_submission_count_label')) . '</span>';
        echo '<span class="badge text-bg-secondary" data-gf-lifetime-count data-gf-lifetime-count-value="' . esc_attr($count) . '" data-gf-form-id="' . absint($form_id) . '">' . esc_html($formatted) . '</span>';
        echo '<button type="button" class="gf-btn gf-btn-sm gf-reset-lifetime-count" data-gf-form-id="' . absint($form_id) . '" data-gf-nonce="' . esc_attr($nonce) . '" data-gf-confirm="' . esc_attr($this->lang->getText('lifetime_submission_count_reset_confirm')) . '" data-gf-success="' . esc_attr($this->lang->getText('lifetime_submission_count_reset_success')) . '">';
        echo esc_html($this->lang->getText('lifetime_submission_count_reset_label'));
        echo '</button>';
        echo '</div>';
        echo '<div class="text-muted small mt-1">';
        echo esc_html($this->lang->getText('lifetime_submission_count_description'));
        echo '</div>';
        echo '</div>';
        echo '</div>';
    }
}
