<?php

/**
 * Publish the newsletter form
 *
 * @link       https://www.triboomedia.it
 * @since      1.0.0
 *
 * @package    Tbm_Tagmailer
 * @subpackage Tbm_Tagmailer/public/partials
 */
$common = new Tbm_Tagmailer_Common();
$out   = array();

$out['gender']         = $common->get_gender();
$out['birth_date']     = $common->get_birth_date();
$out['qualifications'] = $common->get_qualifications();
$out['states']         = $common->get_states();
$out['jobs']           = $common->get_jobs();
$cta_text              = 'Se vuoi aggiornamenti su <em>%%TITLE%%</em> inserisci la tua email nel box qui sotto:';

/**
 * Filter the CTA text and the container id
 */
$cta                   = apply_filters( 'newsletter_form_cta', $cta_text );
$container_id          = apply_filters( 'newsletter_container_id', 0 );
?>

<div id="tagmailerContainer">
    <p><?php echo $cta; ?></p>
    <form id="tmForm">
        <div id="subscriptionForm">
            <fieldset class="form-group">
                <input type="email" class="form-control" id="drpEmail"
                       aria-label="Indirizzo email" name="tbm_email"
                       placeholder="Inserisci l'email" value="" required>
            </fieldset>
        </div>
		<?php if ( true !== get_field( 'tbl_nl_disable_profilation', 'option' ) ) : ?>
            <div id="profilingForm">
                <div class="alert alert-info" id="alertProfiling"></div>
                <fieldset class="form-group">
                    <label for="drpNome">Nome</label>
                    <input id="drpNome" type="text" name="tbm_name" autocomplete="given-name"
                           class="form-control"/>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpCognome">Cognome</label>
                    <input id="drpCognome" type="text" name="tbm_surname" value="" autocomplete="family-name"
                           class="form-control"/>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpAnni">Anno di nascita</label>
                    <select id="drpAnni" name="tbm_birth_date" class="form-control" data-required></select>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpSesso">Sesso</label>
                    <select id="drpSesso" name="tbm_gender" class="form-control" data-required></select>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpProvince">Provincia</label>
                    <select id="drpProvince" name="tbm_state" class="form-control" data-required></select>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpProfessioni">Professione</label>
                    <select id="drpProfessioni" name="tbm_job" class="form-control" data-required></select>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpTitoli">Titolo di studio</label>
                    <select id="drpTitoli" name="tbm_qualification" class="form-control" data-required></select>
                </fieldset>

                <fieldset class="form-group">
                    <label for="drpTelefono">Telefono</label>
                    <input id="drpTelefono" type="number" name="tbm_phone" value="" autocomplete="phone"
                           placeholder="Numero di telefono" minlength="7" maxlength="15" class="form-control"/>
                </fieldset>
            </div>
		<?php endif; ?>

        <p>Compilando il presente form acconsento a ricevere le informazioni
            relative ai servizi di cui alla presente pagina ai sensi
            dell'<a href="%%PRIVACY_URL%%" target="_blank">informativa sulla privacy</a>.</p>

            <fieldset class="form-group tbm-form-consent" id="mktgConsent">
                <legend class="form-text text-muted">Acconsento al trattamento dei dati per attività di marketing.
                </legend>
                <br/>
                <div class="form-check form-check-inline">
                    <input id="radP2aYes" type="radio" value="true" name="tbm_dem"
                           required="required"/>
                    <label class="form-check-label" for="radP2aYes">Sì</label>
                </div>
                <div class="form-check form-check-inline">
                    <input id="radP2aNo" type="radio" value="false" name="tbm_dem"
                           required="required"/>
                    <label class="form-check-label" for="radP2aNo">No</label>
                </div>
            </fieldset>
	    <?php if ( true !== get_field( 'tbl_nl_disable_profilation', 'option' ) ) : ?>
            <fieldset class="form-group tbm-form-consent" id="profilingConsent">
                <legend class="form-text text-muted">Acconsento alla ricezione di comunicazioni promozionali da parte del Titolare, relative a prodotti e servizi di terzi.
                </legend>
                <br/>
                <div class="form-check form-check-inline">
                    <input id="radM2aYes" type="radio" value="true" name="tbm_mktg"
                           data-validation=""/>
                    <label class="form-check-label" for="radM2aYes">Sì</label>
                </div>
                <div class="form-check form-check-inline">
                    <input id="radM2aNo" type="radio" value="false" name="tbm_mktg"
                           data-validation=""/>
                    <label class="form-check-label" for="radM2aNo">No</label>
                </div>
            </fieldset>
		<?php endif; ?>

        <fieldset class="form-group">
            <button type="submit" class="btn btn-primary">
                <span id="tbmSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                Registrati
            </button>
        </fieldset>

        <div class="alert" id="alertNewsletter" role="alert"></div>

        <input type="hidden" name="action" value="tbm_newsletter_subscribe">
        <input type="hidden" name="tbm_privacy" value="true">
        <input type="hidden" name="tbm_container" value="<?php echo $container_id; ?>">
    </form>
</div>
<?php
echo '<script>const nl_json =' . json_encode( $out ) . '</script>';
?>
