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

if(!$Woo->hasActiveWoocommerce()) { ?>
<p class="alert alert-danger text-center">
    <?php esc_html_e( 'There is no activated WooCommerce plugin found. Please make sure that WooCommerce is installed and activated.', 'kirilkirkov-pdf-invoice-manager' ); ?>
</p>
<?php } else { ?>
<table class="form-table">
    <tr valign="top">
        <th scope="row" class="align-middle">
            <div class="th-div">
                <span class="mr-5"><?php esc_html_e( 'General settings', 'kirilkirkov-pdf-invoice-manager' ); ?></span>
                <a class="show-info" data-info="<?php esc_attr_e( 'Create invoices automatically when an order is placed or reaches a chosen status.', 'kirilkirkov-pdf-invoice-manager' ) ?>" href="javascript:;"></a>
            </div>
        </th>

        <td>
            <div class="mb-10">
                <?php 
                    $kirilkirkovwipdf_auto_create_inv = get_option($Config::INPUTS_PREFIX.'auto_create_inv');
                ?>
                <input type="hidden" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'auto_create_inv'; ?>" value="0" />
                <label>
                    <input type="checkbox" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'auto_create_inv'; ?>" value="1" <?php echo $kirilkirkovwipdf_auto_create_inv && (int)$kirilkirkovwipdf_auto_create_inv === 1 ? 'checked' : ''; ?>>
                    <?php esc_html_e( 'Automatically generate invoice for WooCommerce orders', 'kirilkirkov-pdf-invoice-manager' ); ?>
                </label>
            </div>

            <div class="premium-feature-box-mini flex items-center flex-col justify-center mt-4 mb-2 gap-1">
                <img class="w-6 h-6" src="<?php echo esc_url(plugins_url('../../Assets/Img/crown.svg', __FILE__ )); ?>" alt="<?php echo esc_attr( 'WP Invoices' ) ?>" />
                <span><?php esc_html_e( 'Only in the Premium version can you choose to generate the invoice for an order status other than Completed.', 'kirilkirkov-pdf-invoice-manager' ); ?></span>
                <a href="<?php echo esc_url($Config::PREMIUM_LINK); ?>" class="kkinv-btn-primary" target="_blank"><?php esc_html_e( 'Get Premium Now', 'kirilkirkov-pdf-invoice-manager' ); ?></a>
            </div>

            </div>
            <div class="mb-4 premium-feature-container">
                <?php
                    $kirilkirkovwipdf_create_inv_when = get_option($Config::INPUTS_PREFIX.'create_inv_when');
                ?>
                <div><label><?php esc_html_e( 'Generate invoice when order is', 'kirilkirkov-pdf-invoice-manager' ); ?></label></div>
                <select name="<?php echo esc_attr($Config::INPUTS_PREFIX); ?>create_inv_when">
                    <option selected="selected" value="completed">
                        <?php echo esc_html('Completed', 'kirilkirkov-pdf-invoice-manager'); ?>
                    </option>
                </select>
            </div>
        </td>

    </tr>

    <tr valign="top">
        <th scope="row" class="align-middle">
            <div class="th-div">
                <span class="mr-5"><?php esc_html_e( 'Email template', 'kirilkirkov-pdf-invoice-manager' ); ?></span>
                <a class="show-info" data-info="<?php esc_attr_e( 'Enter subject and body for automatically sended emails with invoice attached.', 'kirilkirkov-pdf-invoice-manager' ) ?>" href="javascript:;"></a>
            </div>
        </th>

        <td>
            <div class="premium-feature-box-mini flex items-center flex-col justify-center mt-4 mb-2 gap-1">
                <img class="w-6 h-6" src="<?php echo esc_url(plugins_url('../../Assets/Img/crown.svg', __FILE__ )); ?>" alt="<?php echo esc_attr( 'WP Invoices' ) ?>" />
                <span><?php esc_html_e( 'Only in the Premium version can you enable automatic invoice sending.', 'kirilkirkov-pdf-invoice-manager' ); ?></span>
                <a href="<?php echo esc_url($Config::PREMIUM_LINK); ?>" class="kkinv-btn-primary" target="_blank"><?php esc_html_e( 'Get Premium Now', 'kirilkirkov-pdf-invoice-manager' ); ?></a>
            </div>

            <div class="premium-feature-container">
                <div class="mb-4">
                    <label>
                        <input type="checkbox" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'premium_feature_disabled'; ?>" value="1">
                        <?php esc_html_e( 'Automatically send generated invoice to client email', 'kirilkirkov-pdf-invoice-manager' ); ?>
                    </label>
                </div>
                <div class="mb-4">
                    <label><?php esc_html_e( 'Subject (required)', 'kirilkirkov-pdf-invoice-manager' ); ?></label>
                    <input type="text" name="<?php echo esc_attr($Config::INPUTS_PREFIX); ?>premium_feature_disabled" value="" />
                </div>
                <div class="mb-4">
                    <label><?php esc_html_e( 'Body (required)', 'kirilkirkov-pdf-invoice-manager' ); ?></label>
                    <?php 
                        wp_editor( '', 'kkinv-send-email-msg-textarea', array('textarea_name' => $Config::INPUTS_PREFIX.'premium_feature_disabled') ); 
                    ?>
                </div>
            </div>
        </td>
    </tr>

</table>
<?php } ?>
<input type="hidden" name="page_options" value="<?php echo esc_attr(sanitize_text_field($Config::WOOCOMMERCE_INPUT_GROUP)); ?>" />
<?php settings_fields($Config::WOOCOMMERCE_INPUT_GROUP); ?>