<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php if ( !isset($_GET['user_nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['user_nonce'])), 'DialBunny') ) {} ?>
<div class="dialbunny-admin-wrap">
<?php if (isset($_GET['error1'])) { echo wp_kses_post('<div class="dialbunny-notice dialbunny-notice-error"><p><strong>Error Removing Phone Number!</strong> The phone number that was entered was either invalid or does not exist.</p><button class="dialbunny-notice-dismiss">Dismiss</button></div>'); }  ?>
<?php if (isset($_GET['success'])) { echo wp_kses_post('<div class="dialbunny-notice dialbunny-notice-success"><p><strong>Phone Number Successfully Removed!</strong> You have successfully deleted the phone number.</p><button class="dialbunny-notice-dismiss">Dismiss</button></div>'); }  ?>
    
    <div class="dialbunny-card">
        <h2 class="dialbunny-title">Remove A Managed Number</h2>
        <p class="dialbunny-description">Here you can easily permanently remove a managed number from the DialBunny plugin and a user's account. This works for both released phone numbers and active phone numbers.</p>
    </div>

    <div class="dialbunny-card">
        <h2 class="dialbunny-title">Manually Removing Phone Numbers</h2>
        <p class="dialbunny-description">Follow these steps to manually remove a phone number from a user's account:</p>
        <ol class="dialbunny-list">
            <li>Go to your Twilio account.</li>
            <li>Find the number you want to remove under Active Numbers and remove it from your Twilio account to avoid paying for an unused number.</li>
            <li>Make sure the phone number in the form below is the correct number you want to remove.</li>
        </ol>
    </div>

    <div class="dialbunny-card">
        <h2 class="dialbunny-title">Remove Number</h2>
        <form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post">
            <?php wp_nonce_field('DialBunny', 'user_nonce'); ?>
            <input type="hidden" name="action" value="dialbunny_remove_managed_number">
            <div class="dialbunny-form-group">
                <label for="countrycode" class="dialbunny-label">Country Code</label>
                <div class="dialbunny-input-group">
                    <?php 
                    if (isset($_GET['phonenumbercode'])) { echo dialbunny_country_code(esc_attr(sanitize_text_field(wp_unslash($_GET['phonenumbercode']))), 'countrycode'); } else { echo dialbunny_country_code('none', 'countrycode'); } // phpcs:ignore WordPress.Security.EscapeOutput
                    ?>
                </div>
            </div>
            <div class="dialbunny-form-group">
                <label for="phone" class="dialbunny-label">Phone Number</label>
                <input required type="tel" value="<?php if (isset($_GET['phonenumber'])) { echo esc_attr(sanitize_text_field(wp_unslash($_GET['phonenumber']))); } ?>" name="phone" id="phone" inputmode="numeric" pattern="[0-9]+" placeholder="Enter phone number" class="dialbunny-input">
            </div>
            <div class="dialbunny-form-group">
                <button type="submit" class="dialbunny-button dialbunny-button-danger">Remove Number</button>
                <p class="dialbunny-help-text">
                    <strong>Warning:</strong> This will <strong>permanently remove</strong> the managed phone number from the user's account.
                </p>
            </div>
        </form>
    </div>
</div>