<?php
/**
 * Wiaas Package Types Editor
 */

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

<div id="wiaas_package_type_editor" class="options_group show_if_bundle hidden">
	<script type="text/javascript">
        jQuery(document).ready(function ($) {
            $("#wiaas_package_type").change(function (event) {
                event.preventDefault();

                handlePackageTypeToolsVisiblity();
            });

            function handlePackageTypeToolsVisiblity() {
                var currentPackageType = $('#wiaas_package_type').val();
                var productType = $('#product-type').val();

                if (currentPackageType === 'standard' && productType === 'bundle') {
                    $('#woocommerce-product-data').find('.linked_product_tab').show();
                } else {
                    $('#woocommerce-product-data').find('.linked_product_tab').hide();
                }
            }

            handlePackageTypeToolsVisiblity();
        });
	</script>

	<p class="form-field">
		<label for="wiaas_package_type"><?php esc_html_e( 'Package type:', 'wiaas' ); ?></label>
		<select id="wiaas_package_type" name="wiaas_package_type">
			<?php
			// Array of available package types
			$package_types = Wiaas_Package_Type::get_available_package_types();

			$current_package_type = Wiaas_Package_Type::get_package_type($package->get_id());
			$current_package_type = isset($current_package_type) ? $current_package_type : 'standard';

			if ( ! empty( $package_types ) ) {
				foreach ( $package_types as $package_type ) {
					$label = '';
					switch($package_type) {
						case 'standard':
							$label = 'Standard';
							break;
						case 'option':
							$label = 'Option';
							break;
						case 'add_on':
							$label = 'Add-on';
							break;
					}

					echo '<option ' .
					     'value="' . esc_attr( $package_type ) . '" ' .
					     selected( $package_type, $current_package_type, false ) .
					     ' >' .
					     esc_html( $label ) .
					     '</option>';
				}
			}
			?>
		</select>
		<?php echo wc_help_tip( __( 'Choose Wiaas package type.', 'wiaas' ) );?>
	</p>
</div>
