<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       https://profiles.wordpress.org/gohelkunjan
 * @since      1.0.0
 *
 * @package    KG_Digital_Catalog_For_WooCommerce
 * @subpackage KG_Digital_Catalog_For_WooCommerce/admin/partials
 */
?>
<div class="kgdc-settings-wrap wp-core-ui">
    <?php if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ){ ?>
        
        <div class="kgdc-card">
            <div class="kgdc-card-header">
                <h3><span class="dashicons dashicons-pdf" style="margin-top: 2px;"></span> <?php esc_html_e( 'WooCommerce Products Catalog Settings', 'kg-digital-catalog-for-woocommerce' ); ?></h3>
            </div>
            
            <div class="kgdc-card-body">
                <form method="post" action="options.php">
                    <?php settings_fields( 'kgdc_pdfexport_options_group' ); ?>
                    
                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_compnay_name"><?php esc_html_e( 'Company Name', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <input name="kgdc_compnay_name" id="kgdc_compnay_name" type="text" class="kgdc-input" value="<?php echo esc_attr(get_option('kgdc_compnay_name')); ?>" placeholder="<?php echo esc_attr__( 'e.g. My Awesome Shop Catalog', 'kg-digital-catalog-for-woocommerce' ); ?>">
                            <p class="kgdc-note"><b><?php esc_html_e( 'Note:', 'kg-digital-catalog-for-woocommerce' ); ?></b> <?php esc_html_e( 'This label will be displayed in the PDF header.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label><?php esc_html_e( 'Company Logo', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <div class="kgdc-logo-preview">
                                <?php $kgdc_logo_url = get_option('kgdc_compnay_logo'); ?>
                                <img id="image-preview" src="<?php echo $kgdc_logo_url ? esc_url($kgdc_logo_url) : esc_url( plugins_url('../images/logo.png', __FILE__) ); ?>" data-default-src="<?php echo esc_url( plugins_url('../images/logo.png', __FILE__) ); ?>">
                            </div>
                            <div class="kgdc-upload-actions">
                                <input type="text" name="kgdc_compnay_logo" id="image_url" class="kgdc-input" value="<?php echo esc_attr($kgdc_logo_url); ?>" placeholder="<?php echo esc_attr__( 'URL to your logo', 'kg-digital-catalog-for-woocommerce' ); ?>">
                                <button type="button" id="upload-btn" class="button button-secondary"><?php esc_html_e( 'Change Image', 'kg-digital-catalog-for-woocommerce' ); ?></button>
                                <button type="button" id="remove-btn" class="button button-secondary"><?php esc_html_e( 'Remove Image', 'kg-digital-catalog-for-woocommerce' ); ?></button>
                            </div>
                            <p class="kgdc-note"><b><?php esc_html_e( 'Note:', 'kg-digital-catalog-for-woocommerce' ); ?></b> <?php esc_html_e( 'Best format is PNG (approx. 200px × 80px).', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                            <div style="margin-top: 10px;">
                                <label>
                                    <input type="checkbox" name="kgdc_disable_logo" value="1" <?php checked(get_option('kgdc_disable_logo'), 1); ?>> <?php esc_html_e( 'Hide Company Logo in PDF', 'kg-digital-catalog-for-woocommerce' ); ?>
                                </label>
                            </div>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_compnay_link"><?php esc_html_e( 'Company Website Link', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <input name="kgdc_compnay_link" id="kgdc_compnay_link" type="text" class="kgdc-input" value="<?php echo esc_attr(get_option('kgdc_compnay_link')); ?>" placeholder="https://www.example.com">
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_compnay_address"><?php esc_html_e( 'Company Address', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <textarea name="kgdc_compnay_address" id="kgdc_compnay_address" class="kgdc-textarea"><?php echo esc_textarea(get_option('kgdc_compnay_address')); ?></textarea>
                            <p class="kgdc-note"><b><?php esc_html_e( 'Note:', 'kg-digital-catalog-for-woocommerce' ); ?></b> <?php esc_html_e( 'This address will be displayed in the PDF footer.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_email_id"><?php esc_html_e( 'Email ID', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <input name="kgdc_email_id" id="kgdc_email_id" type="email" class="kgdc-input" value="<?php echo esc_attr(get_option('kgdc_email_id')); ?>" placeholder="info@example.com">
                            <p class="kgdc-note"><b><?php esc_html_e( 'Note:', 'kg-digital-catalog-for-woocommerce' ); ?></b> <?php esc_html_e( 'Displayed in the header/footer of the PDF next to your phone number.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_phone_number"><?php esc_html_e( 'Phone Number', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <input name="kgdc_phone_number" id="kgdc_phone_number" type="text" class="kgdc-input" value="<?php echo esc_attr(get_option('kgdc_phone_number')); ?>">
                            <p class="kgdc-note"><b><?php esc_html_e( 'Note:', 'kg-digital-catalog-for-woocommerce' ); ?></b> <?php esc_html_e( 'Added to PDF header and footer.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="choose"><?php esc_html_e( 'PDF Layout Style', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <div class="kgdc-layout-selector">
                                <div>
                                    <select id="choose" name="kgdc_pdf_layout_type" class="kgdc-select">
                                        <option value="0"><?php esc_html_e( 'Select type', 'kg-digital-catalog-for-woocommerce' ); ?></option>
                                        <?php 
                                        $kgdc_current_layout = get_option('kgdc_pdf_layout_type', '1');
                                        $kgdc_layouts = [
                                            '1' => ['label' => __( 'List View', 'kg-digital-catalog-for-woocommerce' ), 'icon' => 'icon1.png'],
                                            '2' => ['label' => __( 'Grid View', 'kg-digital-catalog-for-woocommerce' ), 'icon' => 'icon2.png'],
                                            '3' => ['label' => __( 'Left-Right Block', 'kg-digital-catalog-for-woocommerce' ), 'icon' => 'icon3.png'],
                                        ];
                                        foreach ($kgdc_layouts as $kgdc_val => $kgdc_data) {
                                            $kgdc_icon_url = plugins_url( '../images/' . $kgdc_data['icon'], __FILE__);
                                            ?>
                                            <option value="<?php echo esc_attr( $kgdc_val ); ?>" data-id="<?php echo esc_url( $kgdc_icon_url ); ?>" <?php selected( $kgdc_current_layout, $kgdc_val ); ?>>
                                                <?php echo esc_html( $kgdc_data['label'] ); ?>
                                            </option>
                                            <?php
                                        }
                                        ?>
                                    </select>
                                    <p class="kgdc-note"><?php esc_html_e( 'Choose the design for your exported PDF.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                                </div>
                                <div class="kgdc-layout-preview">
                                    <img id="my_changing_image" src="<?php echo esc_url( plugins_url( '../images/icon' . ($kgdc_current_layout ?: '1') . '.png', __FILE__) ); ?>" />
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="coupan_code"><?php esc_html_e( 'Default Coupon Code', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <?php
                            $kgdc_args = array(
                                'posts_per_page' => -1,
                                'orderby' => 'title',
                                'order' => 'asc',
                                'post_type' => 'shop_coupon',
                                'post_status' => 'publish',
                            );
                            $kgdc_coupons = get_posts( $kgdc_args );
                            $kgdc_current_coupon = get_option('kgdc_coupan_code');
                            ?>
                            <select name="kgdc_coupan_code" id="coupan_code" class="kgdc-select">
                                <option value=""><?php esc_html_e( 'Choose a coupon...', 'kg-digital-catalog-for-woocommerce' ); ?></option>
                                <?php foreach($kgdc_coupons as $kgdc_coupon) : ?>
                                    <option value="<?php echo esc_attr($kgdc_coupon->post_title); ?>" <?php selected($kgdc_current_coupon, $kgdc_coupon->post_title); ?>>
                                        <?php echo esc_html($kgdc_coupon->post_title); ?>
                                    </option>
                                <?php endforeach; ?>
                            </select>
                            <p class="kgdc-note"><?php esc_html_e( 'This coupon will be automatically applied when customers click "Buy Now" in the PDF.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>
                    <div class="kgdc-form-group">
                        <div class="kgdc-label">
                            <label for="kgdc_button_text"><?php esc_html_e( 'Button Text', 'kg-digital-catalog-for-woocommerce' ); ?></label>
                        </div>
                        <div class="kgdc-control">
                            <?php $kgdc_current_btn_text = get_option('kgdc_button_text', 'BUY NOW'); ?>
                            <input name="kgdc_button_text" id="kgdc_button_text" type="text" class="kgdc-input" value="<?php echo esc_attr($kgdc_current_btn_text); ?>" placeholder="<?php echo esc_attr__( 'e.g. BUY NOW', 'kg-digital-catalog-for-woocommerce' ); ?>">
                            <p class="kgdc-note"><?php esc_html_e( 'Custom text mapped to buttons in all PDF layouts.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
                        </div>
                    </div>
                    <div class="kgdc-submit-wrap">
                        <button type="submit" name="submit" id="submit" class="button kgdc-button-primary"><?php esc_html_e( 'Save Changes', 'kg-digital-catalog-for-woocommerce' ); ?></button>
                    </div>
                </form>
            </div>
        </div>

    <?php } else { ?>
        <div class="kgdc-error-bar">
            <h1><span class="dashicons dashicons-warning"></span> <?php esc_html_e( 'WooCommerce Required', 'kg-digital-catalog-for-woocommerce' ); ?></h1>
            <p><?php esc_html_e( 'This plugin is dependent on WooCommerce. Please install and activate WooCommerce to use these features.', 'kg-digital-catalog-for-woocommerce' ); ?></p>
        </div>
    <?php } ?> 
</div>
