<?php

namespace GriffinForms\Admin\Html\Elements\Submission;

class InputEmail extends \GriffinForms\Admin\Html\Elements\Submission\Format
{
    public function getHtml()
    {
        $raw = is_array($this->field_value) ? '' : (string) $this->field_value;
        $value = wp_strip_all_tags(trim($raw));
        $is_email = is_email($value);
        echo '<div class="' . esc_attr($this->input_class) . '">';

        if (!$is_email || $value === '') {
            echo '<span class="text-muted">' . esc_html__('No email provided', 'griffinforms-form-builder') . '</span>';
        } else {
            echo '<a class="gf-submission-email-link" href="mailto:' . esc_attr($value) . '">';
            echo wp_kses_post($value);
            echo '<span class="gf-submission-email-link-icon" aria-hidden="true"></span>';
            echo '</a>';
        }

        echo '</div>';
    }
}
