<?php

use WP_PowerSuite\Core\OptionStoreModuleSettingsRepository;

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

if ( ! function_exists( 'wp_powersuite_is_license_valid' ) || ! wp_powersuite_is_license_valid() ) {
	$license_page_url = admin_url( 'admin.php?page=powersuite-license' );
	?>
	<div class="wp-powersuite-module-settings wpps-settings-panel" data-module-id="<?php echo esc_attr( $module_id ?? 'social-share' ); ?>">
		<div class="notice notice-warning inline" style="margin:0;">
			<p>
				<?php esc_html_e( 'Floating Social Share requires an active license. Activate your license to configure share buttons on the frontend.', 'wppowersuite-lite' ); ?>
				<a href="<?php echo esc_url( $license_page_url ); ?>"><?php esc_html_e( 'Activate license', 'wppowersuite-lite' ); ?></a>
			</p>
		</div>
	</div>
	<?php
	return;
}

if ( ! \WP_PowerSuite\Core\NetworkScope::canManagePlugin() ) {
	return;
}

$module_id = $module_id ?? 'social-share';

$raw          = OptionStoreModuleSettingsRepository::forModule( $module_id )->all( [] );
if ( ! is_array( $raw ) ) {
	$raw = [];
}

$defaults = [
	'platforms'              => [ 'facebook', 'x', 'linkedin', 'email' ],
	'post_types'             => [ 'post' ],
	'position'               => 'after_content',
	'auto_display'           => true,
	'web_share_api'          => true,
	'copy_link'              => true,
	'show_heading'           => true,
	'heading_text'           => '',
	'inline_icons_only'      => false,
	'button_preset_inline'   => 'flow',
	'button_preset_floating' => 'solid',
];
$settings = array_merge( $defaults, $raw );

if ( isset( $raw['button_preset'] ) && is_string( $raw['button_preset'] ) ) {
	$legacy = sanitize_key( $raw['button_preset'] );
	if ( ! isset( $raw['button_preset_inline'] ) ) {
		$settings['button_preset_inline'] = $legacy;
	}
	if ( ! isset( $raw['button_preset_floating'] ) ) {
		$settings['button_preset_floating'] = $legacy;
	}
}

$button_presets = \SocialShare\Module::getButtonPresets();
$bpi_default    = 'flow';
$bpf_default    = 'solid';

$button_preset_inline = isset( $settings['button_preset_inline'] ) ? sanitize_key( (string) $settings['button_preset_inline'] ) : $bpi_default;
if ( ! array_key_exists( $button_preset_inline, $button_presets ) ) {
	$button_preset_inline = $bpi_default;
}

$button_preset_floating = isset( $settings['button_preset_floating'] ) ? sanitize_key( (string) $settings['button_preset_floating'] ) : $bpf_default;
if ( $button_preset_floating === 'flow' ) {
	$button_preset_floating = 'minimal';
}
if ( ! array_key_exists( $button_preset_floating, $button_presets ) ) {
	$button_preset_floating = $bpf_default;
}

$platforms     = $settings['platforms'] ?? [ 'facebook', 'x', 'linkedin', 'email' ];
$post_types    = $settings['post_types'] ?? [ 'post' ];
$position      = $settings['position'] ?? 'after_content';
$auto_display  = ! empty( $settings['auto_display'] );
$is_float_pos  = in_array( $position, [ 'float_bottom_center', 'float_left_center', 'float_right_center' ], true );
$preset_inline_row_display  = ( $auto_display && ! $is_float_pos ) ? 'table-row' : 'none';
$preset_floating_row_display = ( $auto_display && $is_float_pos ) ? 'table-row' : 'none';
$web_share_api = ! empty( $settings['web_share_api'] );
$copy_link     = ! empty( $settings['copy_link'] );
$show_heading       = ! empty( $settings['show_heading'] );
$heading_text       = (string) ( $settings['heading_text'] ?? '' );
$inline_icons_only  = ! empty( $settings['inline_icons_only'] );

$available_platforms  = \SocialShare\Module::getPlatforms();
$available_post_types = [];
$excluded_types       = [ 'attachment', 'revision', 'nav_menu_item', 'wp_block', 'wp_template', 'wp_template_part', 'wp_navigation' ];
foreach ( get_post_types( [ 'public' => true ], 'objects' ) as $pt_name => $pt_obj ) {
	if ( ! in_array( $pt_name, $excluded_types, true ) ) {
		$available_post_types[ $pt_name ] = $pt_obj->labels->name ?? $pt_name;
	}
}
?>

<div class="wp-powersuite-module-settings wpps-social-share-admin" data-module-id="<?php echo esc_attr( $module_id ); ?>">
	<p class="description">
		<?php esc_html_e( 'Add social media sharing buttons to your posts and pages. Share links use simple URL schemes — no third-party JavaScript or tracking. Privacy-friendly and works with ad blockers.', 'wppowersuite-lite' ); ?>
	</p>

	<form class="wp-powersuite-module-settings-form" data-module-id="<?php echo esc_attr( $module_id ); ?>">
		<?php wp_nonce_field( 'wp_powersuite_save_module_settings_' . $module_id, 'wp_powersuite_nonce' ); ?>

		<table class="form-table" role="presentation">
			<tbody>
				<tr>
					<th scope="row"><?php esc_html_e( 'Platforms', 'wppowersuite-lite' ); ?></th>
					<td>
						<div class="wpps-ct-multiselect wpps-ss-platforms" id="<?php echo esc_attr( $module_id ); ?>_platforms_ms"
							data-label-none="<?php echo esc_attr( __( 'Select platforms...', 'wppowersuite-lite' ) ); ?>"
							data-label-single="<?php echo esc_attr( __( '1 selected', 'wppowersuite-lite' ) ); ?>"
							<?php /* translators: %d: number value. */ ?>
							data-label-multi="<?php echo esc_attr( __( '%d selected', 'wppowersuite-lite' ) ); ?>">
							<button type="button" class="wpps-ct-multiselect__trigger" aria-expanded="false" aria-haspopup="listbox">
								<span class="wpps-ct-multiselect__trigger-text"><?php esc_html_e( 'Select platforms...', 'wppowersuite-lite' ); ?></span>
								<span class="dashicons dashicons-arrow-down-alt2 wpps-ct-multiselect__chevron"></span>
							</button>
							<div class="wpps-ct-multiselect__dropdown" role="listbox" hidden>
								<input type="text" class="wpps-ct-multiselect__search" placeholder="<?php esc_attr_e( 'Search platforms...', 'wppowersuite-lite' ); ?>" autocomplete="off" />
								<div class="wpps-ct-multiselect__actions">
									<button type="button" class="wpps-ct-multiselect__action" data-action="select-all"><?php esc_html_e( 'Select all', 'wppowersuite-lite' ); ?></button>
									<button type="button" class="wpps-ct-multiselect__action" data-action="clear"><?php esc_html_e( 'Clear', 'wppowersuite-lite' ); ?></button>
								</div>
								<div class="wpps-ct-multiselect__options">
									<?php foreach ( $available_platforms as $key => $info ) : ?>
										<?php
										$checked = in_array( $key, (array) $platforms, true );
										$icon_svg = \SocialShare\Module::getPlatformIconSvg( $key );
										?>
										<label class="wpps-ct-multiselect__option wpps-ct-multiselect__option--with-icon" data-slug="<?php echo esc_attr( $key ); ?>" data-label="<?php echo esc_attr( $info['label'] ); ?>">
											<input type="checkbox"
												name="platforms[]"
												class="wp-powersuite-advanced-setting"
												data-setting-key="platforms"
												value="<?php echo esc_attr( $key ); ?>"
												<?php checked( $checked ); ?>
											/>
											<span class="wpps-ct-multiselect__option-icon"><?php echo $icon_svg; ?></span>
											<span class="wpps-ct-multiselect__option-label"><?php echo esc_html( $info['label'] ); ?></span>
										</label>
									<?php endforeach; ?>
								</div>
							</div>
						</div>
						<p class="description"><?php esc_html_e( 'Which sharing buttons to display.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Post Types', 'wppowersuite-lite' ); ?></th>
					<td>
						<?php if ( empty( $available_post_types ) ) : ?>
							<p class="description"><?php esc_html_e( 'No public post types found.', 'wppowersuite-lite' ); ?></p>
						<?php else : ?>
							<div class="wpps-ct-multiselect wpps-ss-post-types" id="<?php echo esc_attr( $module_id ); ?>_post_types_ms"
								data-label-none="<?php echo esc_attr( __( 'Select post types...', 'wppowersuite-lite' ) ); ?>"
								data-label-single="<?php echo esc_attr( __( '1 selected', 'wppowersuite-lite' ) ); ?>"
								<?php /* translators: %d: number value. */ ?>
								data-label-multi="<?php echo esc_attr( __( '%d selected', 'wppowersuite-lite' ) ); ?>">
								<button type="button" class="wpps-ct-multiselect__trigger" aria-expanded="false" aria-haspopup="listbox">
									<span class="wpps-ct-multiselect__trigger-text"><?php esc_html_e( 'Select post types...', 'wppowersuite-lite' ); ?></span>
									<span class="dashicons dashicons-arrow-down-alt2 wpps-ct-multiselect__chevron"></span>
								</button>
								<div class="wpps-ct-multiselect__dropdown" role="listbox" hidden>
									<input type="text" class="wpps-ct-multiselect__search" placeholder="<?php esc_attr_e( 'Search post types...', 'wppowersuite-lite' ); ?>" autocomplete="off" />
									<div class="wpps-ct-multiselect__actions">
										<button type="button" class="wpps-ct-multiselect__action" data-action="select-all"><?php esc_html_e( 'Select all', 'wppowersuite-lite' ); ?></button>
										<button type="button" class="wpps-ct-multiselect__action" data-action="clear"><?php esc_html_e( 'Clear', 'wppowersuite-lite' ); ?></button>
									</div>
									<div class="wpps-ct-multiselect__options">
										<?php foreach ( $available_post_types as $pt_key => $pt_label ) : ?>
											<?php $checked = in_array( $pt_key, (array) $post_types, true ); ?>
											<label class="wpps-ct-multiselect__option" data-slug="<?php echo esc_attr( $pt_key ); ?>" data-label="<?php echo esc_attr( $pt_label ); ?>">
												<input type="checkbox"
													name="post_types[]"
													class="wp-powersuite-advanced-setting"
													data-setting-key="post_types"
													value="<?php echo esc_attr( $pt_key ); ?>"
													<?php checked( $checked ); ?>
												/>
												<span class="wpps-ct-multiselect__option-label"><?php echo esc_html( $pt_label ); ?></span>
												<span class="wpps-ct-multiselect__option-slug">(<?php echo esc_html( $pt_key ); ?>)</span>
											</label>
										<?php endforeach; ?>
									</div>
								</div>
							</div>
						<?php endif; ?>
						<p class="description"><?php esc_html_e( 'Show buttons on these post types.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Auto Display', 'wppowersuite-lite' ); ?></th>
					<td>
						<label class="wp-powersuite-toggle-wrap">
							<input
								type="checkbox"
								id="<?php echo esc_attr( $module_id ); ?>_auto_display"
								name="auto_display"
								value="1"
								<?php checked( $auto_display ); ?>
								class="wp-powersuite-advanced-setting wpps-ss-auto-display"
								data-setting-key="auto_display"
							/>
							<span class="description"><?php esc_html_e( 'Automatically add share buttons to content based on position setting', 'wppowersuite-lite' ); ?></span>
						</label>
					</td>
				</tr>
				<tr id="<?php echo esc_attr( $module_id ); ?>_position_row" class="wpps-ss-position-row" style="display: <?php echo $auto_display ? 'table-row' : 'none'; ?>;">
					<th scope="row">
						<label for="<?php echo esc_attr( $module_id ); ?>_position"><?php esc_html_e( 'Position', 'wppowersuite-lite' ); ?></label>
					</th>
					<td>
						<select
							id="<?php echo esc_attr( $module_id ); ?>_position"
							name="position"
							class="wp-powersuite-advanced-setting"
							data-setting-key="position"
						>
							<option value="before_content" <?php selected( $position, 'before_content' ); ?>><?php esc_html_e( 'Before Content', 'wppowersuite-lite' ); ?></option>
							<option value="after_content" <?php selected( $position, 'after_content' ); ?>><?php esc_html_e( 'After Content', 'wppowersuite-lite' ); ?></option>
							<option value="both" <?php selected( $position, 'both' ); ?>><?php esc_html_e( 'Both', 'wppowersuite-lite' ); ?></option>
							<option value="float_bottom_center" <?php selected( $position, 'float_bottom_center' ); ?>><?php esc_html_e( 'Floating: Bottom Center', 'wppowersuite-lite' ); ?></option>
							<option value="float_left_center" <?php selected( $position, 'float_left_center' ); ?>><?php esc_html_e( 'Floating: Left Center', 'wppowersuite-lite' ); ?></option>
							<option value="float_right_center" <?php selected( $position, 'float_right_center' ); ?>><?php esc_html_e( 'Floating: Right Center', 'wppowersuite-lite' ); ?></option>
						</select>
						<p class="description"><?php esc_html_e( 'Where to display the share buttons.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr class="wpps-ss-preset-inline-row" style="display: <?php echo esc_attr( $preset_inline_row_display ); ?>;">
					<th scope="row">
						<label for="<?php echo esc_attr( $module_id ); ?>_button_preset_inline"><?php esc_html_e( 'In-content style', 'wppowersuite-lite' ); ?></label>
					</th>
					<td>
						<select
							id="<?php echo esc_attr( $module_id ); ?>_button_preset_inline"
							name="button_preset_inline"
							class="wp-powersuite-advanced-setting"
							data-setting-key="button_preset_inline"
						>
							<?php foreach ( $button_presets as $preset_key => $preset_info ) : ?>
								<option value="<?php echo esc_attr( $preset_key ); ?>" <?php selected( $button_preset_inline, $preset_key ); ?>><?php echo esc_html( $preset_info['label'] ); ?></option>
							<?php endforeach; ?>
						</select>
						<p class="description"><?php esc_html_e( 'Look for automatically inserted blocks and shortcodes in the main content (before, after, or both). Use “Inline strip” for a minimal, prose-friendly row.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr class="wpps-ss-preset-inline-row" style="display: <?php echo esc_attr( $preset_inline_row_display ); ?>;">
					<th scope="row"><?php esc_html_e( 'In-content: icons only', 'wppowersuite-lite' ); ?></th>
					<td>
						<label class="wp-powersuite-toggle-wrap">
							<input
								type="checkbox"
								id="<?php echo esc_attr( $module_id ); ?>_inline_icons_only"
								name="inline_icons_only"
								value="1"
								<?php checked( $inline_icons_only ); ?>
								class="wp-powersuite-advanced-setting"
								data-setting-key="inline_icons_only"
							/>
							<span class="description"><?php esc_html_e( 'Hide platform names on in-content buttons; show icons only (accessibility: titles and aria-labels stay on links).', 'wppowersuite-lite' ); ?></span>
						</label>
					</td>
				</tr>
				<tr class="wpps-ss-preset-floating-row" style="display: <?php echo esc_attr( $preset_floating_row_display ); ?>;">
					<th scope="row">
						<label for="<?php echo esc_attr( $module_id ); ?>_button_preset_floating"><?php esc_html_e( 'Floating bar style', 'wppowersuite-lite' ); ?></label>
					</th>
					<td>
						<select
							id="<?php echo esc_attr( $module_id ); ?>_button_preset_floating"
							name="button_preset_floating"
							class="wp-powersuite-advanced-setting"
							data-setting-key="button_preset_floating"
						>
							<?php foreach ( $button_presets as $preset_key => $preset_info ) : ?>
								<?php if ( $preset_key === 'flow' ) : continue; endif; ?>
								<option value="<?php echo esc_attr( $preset_key ); ?>" <?php selected( $button_preset_floating, $preset_key ); ?>><?php echo esc_html( $preset_info['label'] ); ?></option>
							<?php endforeach; ?>
						</select>
						<p class="description"><?php esc_html_e( 'Look for fixed bottom or side bars. “Inline strip” is not used here; icon-only bars work best with solid, minimal, pill, outline, or glass.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Heading', 'wppowersuite-lite' ); ?></th>
					<td>
						<label class="wp-powersuite-toggle-wrap" style="display: block; margin-bottom: 8px;">
							<input
								type="checkbox"
								id="<?php echo esc_attr( $module_id ); ?>_show_heading"
								name="show_heading"
								value="1"
								<?php checked( $show_heading ); ?>
								class="wp-powersuite-advanced-setting"
								data-setting-key="show_heading"
							/>
							<span class="description"><?php esc_html_e( 'Show section heading above desktop buttons (floating bars stay icon-only)', 'wppowersuite-lite' ); ?></span>
						</label>
						<input
							type="text"
							id="<?php echo esc_attr( $module_id ); ?>_heading_text"
							name="heading_text"
							class="regular-text wp-powersuite-advanced-setting"
							data-setting-key="heading_text"
							value="<?php echo esc_attr( $heading_text ); ?>"
							placeholder="<?php esc_attr_e( 'Share', 'wppowersuite-lite' ); ?>"
						/>
						<p class="description"><?php esc_html_e( 'Custom heading text, or leave blank to use “Share”.', 'wppowersuite-lite' ); ?></p>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Copy link', 'wppowersuite-lite' ); ?></th>
					<td>
						<label class="wp-powersuite-toggle-wrap">
							<input
								type="checkbox"
								id="<?php echo esc_attr( $module_id ); ?>_copy_link"
								name="copy_link"
								value="1"
								<?php checked( $copy_link ); ?>
								class="wp-powersuite-advanced-setting"
								data-setting-key="copy_link"
							/>
							<span class="description"><?php esc_html_e( 'Add a button to copy the page URL (uses clipboard; works in all modern browsers)', 'wppowersuite-lite' ); ?></span>
						</label>
					</td>
				</tr>
				<tr>
					<th scope="row"><?php esc_html_e( 'Web Share API', 'wppowersuite-lite' ); ?></th>
					<td>
						<label class="wp-powersuite-toggle-wrap">
							<input
								type="checkbox"
								id="<?php echo esc_attr( $module_id ); ?>_web_share_api"
								name="web_share_api"
								value="1"
								<?php checked( $web_share_api ); ?>
								class="wp-powersuite-advanced-setting"
								data-setting-key="web_share_api"
							/>
							<span class="description"><?php esc_html_e( 'Show native share button on mobile (opens device share sheet)', 'wppowersuite-lite' ); ?></span>
						</label>
					</td>
				</tr>
			</tbody>
		</table>

		<div class="wp-powersuite-info-box wpps-module-callout">
			<p style="margin: 0 0 8px 0;"><strong><?php esc_html_e( 'Shortcode', 'wppowersuite-lite' ); ?></strong></p>
			<p style="margin: 0 0 8px 0;"><code>[social_share]</code> — <?php esc_html_e( 'Display with default platforms.', 'wppowersuite-lite' ); ?></p>
			<p style="margin: 0 0 8px 0;"><code>[social_share platforms="facebook,x,linkedin"]</code> — <?php esc_html_e( 'Specific platforms only.', 'wppowersuite-lite' ); ?></p>
			<p style="margin: 0 0 8px 0;"><code>[social_share heading="no"]</code> — <?php esc_html_e( 'Hide heading.', 'wppowersuite-lite' ); ?> <code>[social_share copy="no"]</code> — <?php esc_html_e( 'Hide copy button.', 'wppowersuite-lite' ); ?> <code>[social_share icons="yes"]</code> — <?php esc_html_e( 'Icons only (no labels).', 'wppowersuite-lite' ); ?> <code>[social_share labels="no"]</code> — <?php esc_html_e( 'Same as icons only.', 'wppowersuite-lite' ); ?> <code>[social_share title="Spread the word"]</code> — <?php esc_html_e( 'Custom heading.', 'wppowersuite-lite' ); ?> <code>[social_share preset="outline"]</code> — <?php esc_html_e( 'Override style: flow, solid, minimal, pill, outline, glass.', 'wppowersuite-lite' ); ?></p>
			<p style="margin: 0;"><strong><?php esc_html_e( 'Theme template', 'wppowersuite-lite' ); ?></strong> — <code>&lt;?php echo do_shortcode('[social_share]'); ?&gt;</code></p>
		</div>
	</form>
</div>


<?php ob_start(); ?>
(function() {
	var container = document.querySelector('.wp-powersuite-module-settings[data-module-id="<?php echo esc_js( $module_id ); ?>"]');
	if (!container) return;

	container.querySelectorAll('.wpps-ct-multiselect').forEach(function(root) {
		var trigger = root.querySelector('.wpps-ct-multiselect__trigger');
		var triggerText = root.querySelector('.wpps-ct-multiselect__trigger-text');
		var dropdown = root.querySelector('.wpps-ct-multiselect__dropdown');
		var search = root.querySelector('.wpps-ct-multiselect__search');
		var options = root.querySelectorAll('.wpps-ct-multiselect__option');
		if (!trigger || !dropdown || !triggerText) return;

		function countChecked() {
			var n = 0;
			options.forEach(function(o) {
				var cb = o.querySelector('input[type="checkbox"]');
				if (cb && cb.checked) n++;
			});
			return n;
		}
		function updateTriggerText() {
			var n = countChecked();
			var none = root.dataset.labelNone || '';
			var single = root.dataset.labelSingle || '';
			var multi = (root.dataset.labelMulti || '').replace('%d', n);
			triggerText.textContent = n === 0 ? none : (n === 1 ? single : multi);
		}
		function filterOptions(q) {
			q = (q || '').toLowerCase().trim();
			options.forEach(function(o) {
				var label = (o.dataset.label || '').toLowerCase();
				var slug = (o.dataset.slug || '').toLowerCase();
				o.classList.toggle('wpps-ct-multiselect__option--hidden', !!(q && label.indexOf(q) === -1 && slug.indexOf(q) === -1));
			});
		}
		function toggleDropdown(open) {
			var openNow = open === undefined ? dropdown.hasAttribute('hidden') : !!open;
			if (openNow) {
				dropdown.removeAttribute('hidden');
				trigger.setAttribute('aria-expanded', 'true');
				if (search) { search.value = ''; filterOptions(''); search.focus(); }
			} else {
				dropdown.setAttribute('hidden', '');
				trigger.setAttribute('aria-expanded', 'false');
			}
		}

		trigger.addEventListener('click', function() { toggleDropdown(); });
		if (search) {
			search.addEventListener('input', function() { filterOptions(this.value); });
			search.addEventListener('keydown', function(e) { if (e.key === 'Escape') toggleDropdown(false); });
		}
		root.querySelectorAll('.wpps-ct-multiselect__action').forEach(function(btn) {
			btn.addEventListener('click', function() {
				var action = btn.dataset.action;
				var visible = Array.prototype.filter.call(options, function(o) { return !o.classList.contains('wpps-ct-multiselect__option--hidden'); });
				if (action === 'select-all') {
					visible.forEach(function(o) { var cb = o.querySelector('input[type="checkbox"]'); if (cb) cb.checked = true; });
				} else if (action === 'clear') {
					options.forEach(function(o) { var cb = o.querySelector('input[type="checkbox"]'); if (cb) cb.checked = false; });
				}
				updateTriggerText();
			});
		});
		options.forEach(function(o) {
			var cb = o.querySelector('input[type="checkbox"]');
			if (cb) cb.addEventListener('change', updateTriggerText);
		});
		document.addEventListener('click', function(e) {
			if (!root.contains(e.target)) toggleDropdown(false);
		});
		updateTriggerText();
	});

	var autoDisplay = container.querySelector('.wpps-ss-auto-display');
	var positionRow = container.querySelector('.wpps-ss-position-row');
	var positionSelect = container.querySelector('[data-setting-key="position"]');
	var inlinePresetRows = container.querySelectorAll('.wpps-ss-preset-inline-row');
	var floatingPresetRow = container.querySelector('.wpps-ss-preset-floating-row');
	var floatPositions = ['float_bottom_center', 'float_left_center', 'float_right_center'];
	function isFloatPosition(val) {
		return floatPositions.indexOf(val) !== -1;
	}
	function setInlineRowsDisplay(display) {
		inlinePresetRows.forEach(function (row) {
			row.style.display = display;
		});
	}
	function updatePresetStyleRows() {
		if (!floatingPresetRow) return;
		if (!autoDisplay || !autoDisplay.checked) {
			setInlineRowsDisplay('none');
			floatingPresetRow.style.display = 'none';
			return;
		}
		if (positionSelect && isFloatPosition(positionSelect.value)) {
			setInlineRowsDisplay('none');
			floatingPresetRow.style.display = 'table-row';
		} else {
			setInlineRowsDisplay('table-row');
			floatingPresetRow.style.display = 'none';
		}
	}
	if (autoDisplay && positionRow) {
		autoDisplay.addEventListener('change', function() {
			positionRow.style.display = autoDisplay.checked ? 'table-row' : 'none';
			updatePresetStyleRows();
		});
	}
	if (positionSelect) {
		positionSelect.addEventListener('change', updatePresetStyleRows);
	}
	updatePresetStyleRows();
})();
<?php \WP_PowerSuite\Core\InlineAssets::script( 'wpps-ia-modules-social-share-admin-php-script-1', (string) ob_get_clean() ); ?>

