<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

use Gigneo\Modules;

$p_id         = $args['p_id'] ?? '';
$current_step = $args['current_step'] ?? '';
$redirect_url = $args['redirect_url'] ?? '';

$pricing_title_type = gigneo_option( '_gigneo_ts_service_pricing_title', 'custom' );
$custom_offers      = gigneo_option( '_gigneo_ts_service_custom_offers', true );
$time_list          = gigneo_delivery_time_types( '', false );
$service_url        = gigneo_dashboard_url( 'service', 'list' );

$price_multi_tier = gigneo_post_meta( $p_id, '_gigneo_pm_price_multi_tier' );
$price_multi_tier = ! empty( $pricing_title_type ) ? $price_multi_tier : 'yes';

//Plan 1
$plan_one_title         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_title' );
$plan_one_title         = ! empty( $plan_one_title ) ? $plan_one_title : '';
$plan_one_description   = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_description' );
$plan_one_description   = ! empty( $plan_one_description ) ? $plan_one_description : '';
$plan_one_time_type     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_delivery_time_type' );
$plan_one_time_type     = ! empty( $plan_one_time_type ) ? $plan_one_time_type : '';
$plan_one_delivery_time = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_delivery_time' );
$plan_one_delivery_time = ! empty( $plan_one_delivery_time ) ? $plan_one_delivery_time : '';
$plan_one_revisions     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_revisions' );
$plan_one_revisions     = ! empty( $plan_one_revisions ) ? $plan_one_revisions : '';
$plan_one_price         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_one_price' );
$plan_one_price         = ! empty( $plan_one_price ) ? $plan_one_price : '';

//Plan 2
$plan_two_title         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_title' );
$plan_two_title         = ! empty( $plan_two_title ) ? $plan_two_title : '';
$plan_two_description   = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_description' );
$plan_two_description   = ! empty( $plan_two_description ) ? $plan_two_description : '';
$plan_two_time_type     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_delivery_time_type' );
$plan_two_time_type     = ! empty( $plan_two_time_type ) ? $plan_two_time_type : '';
$plan_two_revisions     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_revisions' );
$plan_two_revisions     = ! empty( $plan_two_revisions ) ? $plan_two_revisions : '';
$plan_two_delivery_time = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_delivery_time' );
$plan_two_delivery_time = ! empty( $plan_two_delivery_time ) ? $plan_two_delivery_time : '';
$plan_two_price         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_two_price' );
$plan_two_price         = ! empty( $plan_two_price ) ? $plan_two_price : '';

//Plan 3
$plan_three_title         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_title' );
$plan_three_title         = ! empty( $plan_three_title ) ? $plan_three_title : '';
$plan_three_description   = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_description' );
$plan_three_description   = ! empty( $plan_three_description ) ? $plan_three_description : '';
$plan_three_time_type     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_delivery_time_type' );
$plan_three_time_type     = ! empty( $plan_three_time_type ) ? $plan_three_time_type : '';
$plan_three_delivery_time = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_delivery_time' );
$plan_three_delivery_time = ! empty( $plan_three_delivery_time ) ? $plan_three_delivery_time : '';
$plan_three_revisions     = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_revisions' );
$plan_three_revisions     = ! empty( $plan_three_revisions ) ? $plan_three_revisions : '';
$plan_three_price         = gigneo_post_meta( $p_id, '_gigneo_pm_price_plan_three_price' );
$plan_three_price         = ! empty( $plan_three_price ) ? $plan_three_price : '';
?>
<div id="gn-service-edit-pricing" class="gn-service-edit-step gn-service-edit-pricing<?php echo esc_attr( 'yes' === $price_multi_tier ? ' gn-show-plan-tiers' : '' ); ?> <?php echo esc_attr( 'pricing' !== $current_step ? ' d-none' : '' ); ?>">
	<div class="row gy-4">
		<div class="col-lg-8 col-xl-9 order-2 order-lg-1">
			<form id="gn-service-form-pricing" class="gn-main gn-service-edit-form">
				<!--Pricing-->
				<div class="gn-edit-service-section">
					<div class="gn-head">
						<div class="gn-heading-area">
							<h3 class="gn-title"><?php echo esc_html__( 'Pricing tiers', 'gigneo' ); ?></h3>
							<p class="gn-description"><?php echo esc_html__( 'Offer your service with 1 or 3 pricing tiers.', 'gigneo' ); ?></p>
						</div>
						<div class="gn-actions">
							<span class="gn-switch">
								<?php echo esc_html__( '3 Tiers', 'gigneo' ); ?>
								<label class="gn-checkbox" for="gn-pricing-tier-switch">
									<input type="checkbox"<?php echo esc_attr( 'yes' === $price_multi_tier ? ' checked="checked"' : '' ); ?> name="price_multi_tier" id="gn-pricing-tier-switch">
								</label>
							</span>
						</div>
					</div>
					<div class="gn-plan-tiers">
						<ul class="gn-plan-tier-tabs">
							<li class="gn-tab gn-tab-plan-basic gn-active" data-gn-tab-content="plan-basic">
								<?php echo esc_html__( 'Basic', 'gigneo' ); ?>
							</li>
							<li class="gn-tab gn-tab-plan-standard" data-gn-tab-content="plan-standard">
								<?php echo esc_html__( 'Standard', 'gigneo' ); ?>
							</li>
							<li class="gn-tab gn-tab-plan-premium" data-gn-tab-content="plan-premium">
								<?php echo esc_html__( 'Premium', 'gigneo' ); ?>
							</li>
						</ul>
						<div class="gn-plan-tiers-content">
							<div class="gn-plan-tier-tabs-info">
								<?php if ( 'custom' === $pricing_title_type ) { ?>
								<h6 class="gn-plan-field-label gn-plan-field-title gn-required-field-label">
									<?php echo esc_html__( 'Title', 'gigneo' ); ?>
								</h6>
								<?php } ?>
								<h6 class="gn-plan-field-label gn-plan-field-description gn-required-field-label">
									<?php echo esc_html__( 'Description', 'gigneo' ); ?>
								</h6>
								<h6 class="gn-plan-field-label gn-plan-field-delivery-time gn-required-field-label">
									<?php echo esc_html__( 'Delivery time', 'gigneo' ); ?>
								</h6>
								<h6 class="gn-plan-field-label gn-plan-field-revisions gn-required-field-label">
									<?php echo esc_html__( 'Revisions', 'gigneo' ); ?>
								</h6>
								<h6 class="gn-plan-field-label gn-plan-field-price gn-required-field-label">
									<?php echo esc_html__( 'Price', 'gigneo' ); ?>
								</h6>
							</div>
							<div class="gn-plan-tier-tabs-content">
								<div class="gn-tab-content gn-tab-content-plan-basic gn-active">
									<h4 class="gn-plan-title"><?php echo esc_html__( 'Basic', 'gigneo' ); ?></h4>
									<div class="gn-form-fields">
										<?php if ( 'custom' === $pricing_title_type ) { ?>
											<div class="gn-form-field gn-plan-field gn-plan-field-title">
												<label><input class="gn-required-field" type="text" name="plan_one_title" autocomplete="off" value="<?php echo esc_attr( $plan_one_title ); ?>"></label>
											</div>
										<?php } ?>
										<div class="gn-form-field gn-plan-field gn-plan-field-description">
											<label><textarea name="plan_one_description" autocomplete="off" class="gn-required-field gn-textarea-counter" rows="5" maxlength="100" placeholder=""><?php echo esc_textarea( $plan_one_description ); ?></textarea></label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-delivery gn-select2">
											<label>
												<input class="gn-required-field" type="number" name="plan_one_delivery_time" autocomplete="off" value="<?php echo esc_attr( $plan_one_delivery_time ); ?>" min="1" step="1">
											</label>
											<label>
												<select class="form-select" name="plan_one_delivery_time_type">
													<?php foreach ( $time_list as $option_value => $option_label ) : ?>
														<option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $plan_one_time_type, $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
													<?php endforeach; ?>
												</select>
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-revision">
											<label>
												<input type="number" name="plan_one_revisions" autocomplete="off" value="<?php echo esc_attr( $plan_one_revisions ); ?>" placeholder="<?php echo esc_html__( 'Unlimited', 'gigneo' ); ?>" min="1" step="1">
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-price">
											<label>
												<input type="number" class="gn-required-field" name="plan_one_price" autocomplete="off" value="<?php echo esc_attr( $plan_one_price ); ?>" placeholder="" min="1" step="1">
											</label>
										</div>
									</div>
								</div>
								<div class="gn-tab-content gn-tab-content-plan-standard">
									<h4 class="gn-plan-title"><?php echo esc_html__( 'Standard', 'gigneo' ); ?></h4>
									<div class="gn-form-fields">
									<?php if ( 'custom' === $pricing_title_type ) { ?>
										<div class="gn-form-field gn-plan-field gn-plan-field-title">
											<label><input class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" type="text" name="plan_two_title" autocomplete="off" value="<?php echo esc_attr( $plan_two_title ); ?>"></label>
										</div>
									<?php } ?>
										<div class="gn-form-field gn-plan-field gn-plan-field-description">
											<label><textarea name="plan_two_description" autocomplete="off" class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field gn-textarea-counter" rows="5" placeholder="" maxlength="100"><?php echo esc_textarea( $plan_two_description ); ?></textarea></label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-delivery gn-select2">
											<label>
												<input class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" type="number" name="plan_two_delivery_time" autocomplete="off" value="<?php echo esc_attr( $plan_two_delivery_time ); ?>" min="1" step="1">
											</label>
											<label>
												<select class="form-select" name="plan_two_delivery_time_type">
													<?php foreach ( $time_list as $option_value => $option_label ) : ?>
														<option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $plan_two_time_type, $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
													<?php endforeach; ?>
												</select>
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-revision">
											<label>
												<input type="number" name="plan_two_revisions" autocomplete="off" value="<?php echo esc_attr( $plan_two_revisions ); ?>" placeholder="<?php echo esc_html__( 'Unlimited', 'gigneo' ); ?>" min="1" step="1">
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-price">
											<label>
												<input type="number" class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" name="plan_two_price" autocomplete="off" value="<?php echo esc_attr( $plan_two_price ); ?>" placeholder="" min="1" step="1">
											</label>
										</div>
									</div>
								</div>
								<div class="gn-tab-content gn-tab-content-plan-premium">
									<h4 class="gn-plan-title"><?php echo esc_html__( 'Premium', 'gigneo' ); ?></h4>
									<div class="gn-form-fields">
										<?php if ( 'custom' === $pricing_title_type ) { ?>
										<div class="gn-plan-field gn-plan-field-title gn-form-field">
											<label><input class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" type="text" name="plan_three_title" autocomplete="off" value="<?php echo esc_attr( $plan_three_title ); ?>"></label>
										</div>
									<?php } ?>
										<div class="gn-form-field gn-plan-field gn-plan-field-description">
											<label><textarea name="plan_three_description" autocomplete="off" class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field gn-textarea-counter" rows="5" placeholder="" maxlength="100"><?php echo esc_textarea( $plan_three_description ); ?></textarea></label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-delivery gn-select2">
											<label>
												<input class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" type="number" name="plan_three_delivery_time" autocomplete="off" value="<?php echo esc_attr( $plan_three_delivery_time ); ?>" min="1" step="1">
											</label>
											<label>
												<select class="form-select" name="plan_three_delivery_time_type">
													<?php foreach ( $time_list as $option_value => $option_label ) : ?>
														<option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $plan_three_time_type, $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
													<?php endforeach; ?>
												</select>
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-revision">
											<label>
												<input type="number" name="plan_three_revisions" autocomplete="off" value="<?php echo esc_attr( $plan_three_revisions ); ?>" placeholder="<?php echo esc_html__( 'Unlimited', 'gigneo' ); ?>" min="1" step="1">
											</label>
										</div>
										<div class="gn-form-field gn-plan-field gn-plan-field-price">
											<label>
												<input type="number" class="gn-<?php echo esc_attr( 'yes' !== $price_multi_tier ? 'not-' : '' ); ?>required-field" name="plan_three_price" autocomplete="off" value="<?php echo esc_attr( $plan_three_price ); ?>" placeholder="" min="1" step="1">
											</label>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<?php
				//Category features
				gigneo_load_template( 'dashboard/service/parts/edit/features', false, array( 'p_id' => $p_id ) );

				if ( true === $custom_offers ) {
					//Custom offers
					gigneo_load_template( 'dashboard/service/parts/edit/offers', false, array( 'p_id' => $p_id ) );
				}
				//Custom Addons
				if ( in_array( 'addons', gigneo_active_modules(), true ) ) {
					gigneo_load_template( 'dashboard/service/parts/edit/addons', false, array( 'p_id' => $p_id ) );
				}
				?>
				<div class="gn-edit-service-footer gn-actions">
					<button type="button" data-gn-step="pricing" data-gn-type="draft" data-gn-redirect-url="<?php echo esc_url( $redirect_url ); ?>" class="gn-btn gn-btn-outline-grey gn-service-save"><?php echo esc_html__( 'Save as draft', 'gigneo' ); ?></button>
					<button type="button" data-gn-step="pricing" data-gn-prev-step="basic" class="gn-btn gn-btn-outline-grey gn-service-back">
						<?php echo esc_html__( 'Back', 'gigneo' ); ?>
					</button>
					<button type="button" data-gn-step="pricing" data-gn-type="continue" data-gn-next-step="details" class="gn-btn gn-btn-primary gn-service-save">
						<?php echo esc_html__( 'Save & continue', 'gigneo' ); ?>
					</button>
				</div>
			</form>
		</div>
		<div class="col-lg-4 col-xl-3 order-1 order-lg-2">
			<div class="gn-aside">
				<div class="gn-aside-content">
					<h4 class="gn-title"><?php echo esc_html__( 'Pricing setup:', 'gigneo' ); ?></h4>
					<div class="gn-aside-body">
						<p class="gn-description"><?php echo esc_html__( 'Define your pricing to clearly indicate how clients will be charged for your service.', 'gigneo' ); ?></p>
						<p class="gn-description"><?php echo esc_html__( 'Choose between 1 to 3 pricing tiers, based on your service offering.', 'gigneo' ); ?></p>
						<p class="gn-description"><?php echo esc_html__( 'Tiers provide multiple pricing options for different service packages.', 'gigneo' ); ?></p>
						<p class="gn-description"><?php echo esc_html__( 'Add custom features to showcase additional benefits or premium options for your service.', 'gigneo' ); ?></p>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>