<?php
/**
 * Wiaas Package Option Group Editor
 */

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

<div id="wiaas_option_group_<?php echo esc_attr( $id ); ?>" class="wiaas_option_group wc-metabox closed">
    <h3>
        <a
                href="#"
                data-id="<?php echo esc_attr( $id ); ?>"
                class="delete delete_wiaas_option_group">
            <?php esc_html_e( 'Remove', 'wiaas' ); ?>
        </a>
        <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'wiaas' ); ?>"></div>
        <strong id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_title">
            <?php echo $group['name']; ?>
        </strong>
    </h3>
    <div class="wc-metabox-content">
        <table cellpadding="0" cellspacing="0">
            <tbody>
            <tr>
                <td>
                    <label><?php esc_html_e( 'Name', 'wiaas' ); ?>:</label>
                    <input
                            type="text"
                            data-id="<?php echo esc_attr( $id ); ?>"
                            class="wiaas_option_group_name"
                            name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][name]"
                            value="<?php echo esc_attr( $group['name'] ); ?>" />
                    <input
                            type="hidden"
                            name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][id]"
                            value="<?php echo esc_attr( $id ); ?>" />
                </td>
                <td rowspan="3">
                    <label><?php esc_html_e( 'Options:', 'wiaas' ); ?></label>
                    <select
                            class="wc-product-search wiaas_option_group_options"
                            multiple="multiple"
                            style="width: 50%;"
                            name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][options][]"
                            data-id="<?php echo esc_attr( $id ); ?>"
                            data-sortable="true"
                            data-placeholder="<?php esc_attr_e( 'Search for options ...', 'wiaas' ); ?>"
                            data-action="wiaas_json_search_options"
                            data-selected="<?php echo implode( ',', array_map(function($option) { return $option->get_id(); }, $group_options)) ?>"
                            data-exclude="">
                        <?php
		                            foreach ( $group_options as $option ) {
			                            echo '<option value="' . esc_attr( $option->get_id() ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $option->get_formatted_name() ) . '</option>';
                        }
                        ?>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <?php esc_html_e( 'Default option:', 'wiaas' ); ?>
                    </label>
                    <select
                            id="wiaas_option_group_<?php echo esc_attr( $id ); ?>_default"
                            name="wiaas_option_groups[<?php echo esc_attr( $id ); ?>][default]"
                    >
	                    <?php
	                    foreach ( $group_options as $option ) {
		                    echo '<option value="' . esc_attr( $option->get_id() ) . '"' .
                                 selected( $option->get_id(), $group['default'], false ) .
                                 '>' .
                                 wp_kses_post( $option->get_formatted_name() ) .
                                 '</option>';
	                    }
	                    ?>
                    </select>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>