<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
?>

<form method="post" action="options.php">
    <?php
    settings_fields( $this->option_group );
    do_settings_sections( $this->option_group );
    ?>
    <table class="form-table">
        <?php foreach ( $this->option_args as $lucidpen_name => $lucidpen_arg ) :
            $lucidpen_value = get_option( $lucidpen_name );
            ?>
            <tr>
                <th scope="row">
                    <label for="<?php echo esc_attr( $lucidpen_name ); ?>">
                        <?php echo esc_html( $lucidpen_arg['label'] ); ?>
                    </label>
                </th>
                <td>
                    <input
                        type="text"
                        id="<?php echo esc_attr( $lucidpen_name ); ?>"
                        name="<?php echo esc_attr( $lucidpen_name ); ?>"
                        value="<?php echo esc_attr( $lucidpen_value ); ?>"
                        size="50"
                    />
                    <?php
                    // Show 🔗 emoji only if label contains "slug" (case-insensitive) and value is not empty.
                    if (
                        ! empty( $lucidpen_value ) &&
                        isset( $lucidpen_arg['label'] ) &&
                        stripos( $lucidpen_arg['label'], 'slug' ) !== false
                    ) :
                        ?>
                        <a href="<?php echo esc_url( home_url( '/' . $lucidpen_value ) ); ?>"
                            target="_blank"
                            title="<?php esc_attr_e( 'Open link in new tab', 'lucidpen' ); ?>">🔗</a>
                    <?php endif; ?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>

    <hr />
    <?php
    // Show Freemius box before options.
    // if ( function_exists( 'lucidpen_fs' ) ) {
    //     lucidpen_fs()->_account_page_render();
    // }
    ?>

    <?php submit_button(); ?>
</form>
