<?php
defined('ABSPATH') || exit('No Access!');

$compare_attr = $options->get_option('compare-attr');
$compare_attr = $compare_attr ? $compare_attr : [];
$attrs = irk_get_product_attrs();
?>
<div class="irk-settings-area irk-settings-compare">
    <h2 class="irk-settings-title">
        <span class="irk-title-icon"><span uk-icon="list"></span></span>
        <strong><?php _e('Compare', 'irk'); ?></strong>
    </h2>
    <div class="uk-margin">
        <label class="uk-form-label"><?php _e('Active', 'irk'); ?></label>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare" value="1" <?php echo checked($options->get_option('compare'), 1); ?>>
                <?php _e('Yes', 'irk'); ?>
            </label>
        </div>
    </div>
    <div class="uk-margin">
        <label class="uk-form-label">
            <?php _e('Compare page', 'irk'); ?>
            <?php echo '<a href="' . get_permalink($options->get_option('compare-page')) . '" class="irk-view-page uk-text-primary" target="_blank"> (' . __('View page', 'irk') . ')</a>'; ?>
        </label>
        <div uk-form-custom="target: > * > span:first-child">
            <?php
            wp_dropdown_pages([
                'post_type' => 'page',
                'selected' => $options->get_option('compare-page'),
                'name' => 'compare-page',
                'show_option_none' => __('None', 'irk'),
                'echo' => 1,
            ]);
            ?>
            <button class="irk-confirm uk-button uk-button-default" type="button" tabindex="-1">
                <span></span>
                <span uk-icon="icon: chevron-down"></span>
            </button>
        </div>
        <div class="irk-description">
            <span uk-icon="info"></span>
            <?php _e('Put this shortcode in page:', 'irk'); ?>
            <code class="irk-clipboard" uk-tooltip="<?php _e('Click to copy in clipboard.', 'irk'); ?>">[irk-compare-table]</code>
        </div>
    </div>
    <div class="uk-margin attributes">
        <label class="uk-form-label"><?php _e('Attributes', 'irk'); ?></label>
        <div class="uk-margin-small">
            <label style="color: #1e87f0; font-weight: bold;">
                <input class="uk-checkbox" type="checkbox" id="check-all-attr">
                <?php _e('Select all', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="image" <?php echo in_array('image', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Image', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="title" <?php echo in_array('title', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Title', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="price" <?php echo in_array('price', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Price', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="add-to-cart" <?php echo in_array('add-to-cart', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Add to cart button', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="stock" <?php echo in_array('stock', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Inventory stock', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="weight" <?php echo in_array('weight', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Weight', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="dimensions" <?php echo in_array('dimensions', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Dimensions', 'irk'); ?>
            </label>
        </div>
        <div class="uk-margin-small">
            <label>
                <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="short-description" <?php echo in_array('short-description', $compare_attr) ? 'checked' : null; ?>>
                <?php _e('Short description', 'irk'); ?>
            </label>
        </div>
        <?php if (is_array($attrs) && count($attrs)): ?>
            <?php foreach ($attrs as $attr): ?>
                <div class="uk-margin-small">
                    <label>
                        <input class="uk-checkbox" type="checkbox" name="compare-attr[]" value="<?php echo esc_attr($attr->attribute_id); ?>" <?php echo in_array($attr->attribute_id, $compare_attr) ? 'checked' : null; ?>>
                        <?php echo esc_html($attr->attribute_label); ?>
                    </label>
                </div>
            <?php endforeach; ?>
        <?php endif; ?>
    </div>
</div>