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

?>

<style>
	#tabs-navigation {
		height: 30px;
	}
	#tabs-navigation > li {
		float: left;
		line-height: 30px;
		font-weight: bold;
	}

	#tabs-navigation > li.ui-state-active > a {
		color: #000;
	}

	#tabs-navigation > li.ui-state-disabled > a {
		color: #ccc;
		cursor: default;
	}

	#tabs-navigation > li > a {
		text-decoration: none;
		padding: .5em;
	}

	.wiaas-configured-prices > thead {
		background: #f2f2f2;
	}

    .wiaas-configured-prices > thead td {
        vertical-align: middle;
        position: relative;
    }

    .wiaas-configured-prices > thead i {
        position: absolute;
        vertical-align: top;
        right: -8px;
        top: -8px;
        cursor: pointer;
    }


	.wiaas-configured-prices > tbody > tr > td {
		vertical-align: middle;
	}

	.wiaas-configured-prices > tbody > tr > td:first-child {
		max-width: 100px;
		vertical-align: middle;
	}

	.wiaas-configured-prices > tbody > tr > td:nth-child(2) label {
		float: left;;
		width: 70px;
	}

	.wiaas-configured-prices input[type='text'] {
		width: 100px;
	}

	#managed_36 > td:nth-child(2) > div:last-child {
		position: relative;
		padding-bottom: 20px;
	}

	#managed_36 > td:nth-child(2) > div:last-child > span {
		position: absolute;
		bottom: 0;
		left: 70px;
	}
</style>

<script>

</script>

<div class="wrap">
	<div id="poststuff">
		<div id="post-body" class="metabox-holder columns-2">
			<div id="postbox-container-1" class="postbox-container">
				<div class="postbox">
					<div class="inside">
						<div class="panel-wrap">
							<div class="panel">
								<div>
									<?php
									foreach ($bundled_items_per_category as $category => $category_bundled_items) {
										echo  sprintf(
											'<strong style="text-transform: uppercase;" class="text-uppercase">%s (%s)</strong>',
											esc_attr( $category ),
											esc_attr(count($category_bundled_items)) );
										foreach ($category_bundled_items as $bundled_item) {
											$title      = $bundled_item->product->get_title();
											echo  sprintf( '<p>%s x %s</p>', esc_attr($bundled_item->get_quantity('max')), esc_attr( $title ) );
										}
									}
									?>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div id="postbox-container-2" class="postbox-container">

				<div class="postbox">
					<div class="inside">
						<div class="panel-wrap">
							<div class="panel">
								<h1 style="padding: 0;"><?php echo $package->get_name(); ?></h1>
							</div>
						</div>
					</div>
				</div>

                <?php
                    if (! empty($package->get_short_description())) {
                        ?>
                        <div class="postbox">
		                    <?php wp_editor( $package->get_short_description(), 'content', array(
			                    '_content_editor_dfw' => $_content_editor_dfw,
			                    'drag_drop_upload' => false,
			                    'media_buttons' => false,
			                    'quicktags' => false,
			                    'tabfocus_elements' => 'content-html',
			                    'tinymce' => array(
				                    'resize' => false,
				                    'wp_autoresize_on' => true,
				                    'add_unload_trigger' => false,
				                    'wp_keep_scroll_position' => ! $is_IE,
				                    'readonly'=> true,
				                    'toolbar' => false,
			                    ),
		                    ) ); ?>
                        </div>
                        <?php
                    }
                ?>

				<div class="postbox">
					<div class="inside">
						<div class="panel-wrap">
							<div class="panel">

								<div class="wrap">
									<div>
										<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
										<strong><?php esc_html_e('EPR', 'wiaas') ?></strong>
										<span><?php esc_html_e('= Extra package recurrent commission', 'wiaas') ?></span>
									</div>
									<div>
										<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
										<strong><?php esc_html_e('ESR') ?></strong>
										<span><?php esc_html_e('= Extra services and support recurrent commission', 'wiaas') ?></span>
									</div>
									<div>
										<i style="vertical-align: middle;" class="dashicons dashicons-info"></i>
										<strong><?php esc_html_e('Extra commission', 'wiaas') ?></strong>
										<span><?php esc_html_e('= EPR + ESR', 'wiaas') ?></span>
									</div>
								</div>

								<div id="tabs" data-disabled="<?php echo $has_default_cl_extras ? '' : '1' ; ?>">
									<ul id="tabs-navigation">
										<li><a href="#tabs-1"><?php esc_html_e('Default prices', 'wiaas') ?></a> | </li>
										<li><a href="#tabs-2"><?php esc_html_e('Customer specific prices', 'wiaas') ?></a></li>
									</ul>

									<form id="wiaas_package_extras" action="" method="post">
										<input type="hidden" name="page" value="wiaas-cl-package"/>
										<input type="hidden" id="wiaas_cl_package_id" name="cl_package_id" value="<?php echo esc_attr($package->get_id()) ?>"/>

										<div id="tabs-1">

											<?php require 'html-cl-package-prices.php'; ?>

										</div>
										<div id="tabs-2">

											<div class="form-group">
												<select id="wiaas_cl_customers" class="form-control">
                                                    <option selected value="0" disabled> Select customer ...</option>
													<?php
													$customers = wiaas_get_customers();
													foreach ($customers as $id => $name) {
													    // shik current organization if it has role of customer
													    if ($id === $cl_id) {
														    continue;
                                                        }

													    ?>
                                                            <option
                                                                    <?php disabled(in_array($id, $customer_ids_with_extras), true, true) ?>
                                                                    id="wiaas_cl_customer_<?php esc_attr_e($id, 'wiaas') ?>"
                                                                    value="<?php esc_attr_e($id, 'wiaas') ?>"
                                                            >
                                                                <?php esc_html_e($name, 'wiaas') ?>
                                                            </option>
                                                        <?php
													}
													?>
												</select>
												<?php wp_nonce_field( 'wiaas_create_cl_customer_extras', 'wiaas_create_cl_customer_extras_nonce' ); ?>
												<button id="wiaas_add_cl_customer_extras" class="button">Add</button>
											</div>

                                            <?php
                                                // Render customer specific prices if any
                                                foreach ($customer_ids_with_extras as $customer_id) {
                                                    require 'html-cl-package-prices.php';
                                                }
                                            ?>
										</div>

										<?php wp_nonce_field( 'wiaas_save_cl_extras', 'wiaas_save_cl_extras_nonce' ); ?>
										<?php submit_button( __( 'Save', 'wiaas' ), 'primary', 'submit' ); ?>

									</form>
								</div>

							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<br class="clear" />
	</div>
</div>