<?php

/**
 * SocialPromoter — Settings page.
 *
 * @package PublisherKits_SocialPromoter
 */
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
$settings = get_option( 'pkits_sp_settings', array() );
$nudge_enabled = ( isset( $settings['nudge_enabled'] ) ? (bool) $settings['nudge_enabled'] : true );
$nudge_banner_enabled = ( isset( $settings['nudge_banner_enabled'] ) ? (bool) $settings['nudge_banner_enabled'] : true );
$nudge_post_types = ( isset( $settings['nudge_post_types'] ) ? (array) $settings['nudge_post_types'] : array('post') );
$nudge_roles = ( isset( $settings['nudge_roles'] ) ? (array) $settings['nudge_roles'] : array('administrator', 'editor') );
$copy_template = ( isset( $settings['copy_template'] ) ? $settings['copy_template'] : '{post_title} {post_url}' );
$auto_cancel = ( isset( $settings['auto_cancel_on_delete'] ) ? (bool) $settings['auto_cancel_on_delete'] : true );
$debug_logging = ( isset( $settings['debug_logging'] ) ? (bool) $settings['debug_logging'] : false );
$site_context = PKITS_SP_Site_Profile::publication_context();
// Shared site profile (Insight Engine compatible). Read for audience/goals framing.
$sp_profile = PKITS_SP_Site_Profile::get();
$sp_profile_set = PKITS_SP_Site_Profile::has_profile();
$sp_goal_labels = PKITS_SP_Site_Profile::goal_labels();
$sp_insight_active = ( function_exists( 'is_plugin_active' ) ? is_plugin_active( 'publisherkits-insight-engine/publisherkits-insight-engine.php' ) : false );
// Compose post type selector.
$all_public_types = get_post_types( array(
    'public' => true,
), 'objects' );
$infrastructure_types = PKITS_SP_Admin::get_infrastructure_post_types();
$enabled_types = PKITS_SP_Admin::get_compose_post_types();
// Branded images settings.
$brand_default_tags = $settings['brand_default_hashtags'] ?? '';
$brand_tags_mode = $settings['brand_tags_mode'] ?? 'off';
// SEO keywords - plugin settings first, then shared option.
$shared_seo = get_option( 'publisherkits_seo_keywords', array() );
$shared_seo = ( is_array( $shared_seo ) ? $shared_seo : array() );
$seo_primary = $settings['seo_primary'] ?? $shared_seo['primary'] ?? array('', '', '');
$seo_secondary = $settings['seo_secondary'] ?? $shared_seo['secondary'] ?? array('', '');
$seo_primary = array_pad( (array) $seo_primary, 3, '' );
$seo_secondary = array_pad( (array) $seo_secondary, 2, '' );
$available_post_types = array(
    'post' => __( 'Posts', 'publisherkits-socialpromoter' ),
);
if ( post_type_exists( 'page' ) ) {
    $available_post_types['page'] = __( 'Pages', 'publisherkits-socialpromoter' );
}
/** Integrations (e.g. the Pro WP Job Manager module) append their types. */
$available_post_types = apply_filters( 'pkits_sp_selectable_post_types', $available_post_types );
// Build summary values for sidebar.
$sum_reminders = array();
if ( $nudge_enabled ) {
    $sum_reminders[] = 'Modal';
}
if ( $nudge_banner_enabled ) {
    $sum_reminders[] = 'unpromoted banner';
}
$sum_reminders = ( $sum_reminders ? implode( ' and ', $sum_reminders ) . ' enabled' : 'Disabled' );
$sum_post_types = array();
foreach ( $nudge_post_types as $pt ) {
    $sum_post_types[] = $available_post_types[$pt] ?? $pt;
}
$sum_post_types_str = ( $sum_post_types ? implode( ', ', $sum_post_types ) : 'None' );
$editable_roles = get_editable_roles();
$relevant_roles = array(
    'administrator',
    'editor',
    'author',
    'contributor'
);
$sum_roles = array();
foreach ( $nudge_roles as $r ) {
    if ( isset( $editable_roles[$r] ) ) {
        $sum_roles[] = translate_user_role( $editable_roles[$r]['name'] );
    }
}
$sum_roles_str = ( $sum_roles ? implode( ', ', $sum_roles ) : 'None' );
$placeholder_count = substr_count( $copy_template, '{' );
$sum_template = ( $placeholder_count ? $placeholder_count . ' placeholder' . (( $placeholder_count > 1 ? 's' : '' )) . ' used' : 'No placeholders' );
$sum_queue = ( $auto_cancel ? 'Auto-cancel enabled' : 'Auto-cancel disabled' );
?>
<div class="wrap pkits-sp-wrap">

	<h1 class="pkits-sp-page-title">
		<span class="pkits-sp-logo-mark">SP</span>
		<?php 
esc_html_e( 'SocialPromoter &mdash; Settings', 'publisherkits-socialpromoter' );
?>
	</h1>

	<div class="pkits-sp-page-layout">

		<!-- ── MAIN COLUMN ──────────────────────────────────────── -->
		<div class="pkits-sp-page-main">

			<form method="post" action="<?php 
echo esc_url( admin_url( 'admin-post.php' ) );
?>">
				<?php 
wp_nonce_field( 'pkits_sp_save_settings' );
?>
				<input type="hidden" name="action" value="pkits_sp_save_settings" />

				<!-- Nudge & reminders -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Nudge &amp; reminders', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Controls when editors are reminded to promote posts to social media.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">

						<span class="pkits-sp-check-group-label"><?php 
esc_html_e( 'Publish modal', 'publisherkits-socialpromoter' );
?></span>
						<div class="pkits-sp-check-row">
							<input type="checkbox" id="nudge_enabled" name="nudge_enabled" value="1" <?php 
checked( $nudge_enabled );
?> />
							<label for="nudge_enabled" class="pkits-sp-check-label">
								<?php 
esc_html_e( 'Show a modal prompt immediately after a post is published', 'publisherkits-socialpromoter' );
?>
							</label>
						</div>

						<span class="pkits-sp-check-group-label"><?php 
esc_html_e( 'Unpromoted banner', 'publisherkits-socialpromoter' );
?></span>
						<div class="pkits-sp-check-row">
							<input type="checkbox" id="nudge_banner_enabled" name="nudge_banner_enabled" value="1" <?php 
checked( $nudge_banner_enabled );
?> />
							<label for="nudge_banner_enabled" class="pkits-sp-check-label">
								<?php 
esc_html_e( 'Show an amber banner when editing a published post that has not been promoted', 'publisherkits-socialpromoter' );
?>
							</label>
						</div>

						<span class="pkits-sp-check-group-label"><?php 
esc_html_e( 'Trigger on post types', 'publisherkits-socialpromoter' );
?></span>
						<?php 
foreach ( $available_post_types as $slug => $label ) {
    ?>
							<div class="pkits-sp-check-row">
								<input type="checkbox" id="pt_<?php 
    echo esc_attr( $slug );
    ?>" name="nudge_post_types[]"
									value="<?php 
    echo esc_attr( $slug );
    ?>"
									<?php 
    checked( in_array( $slug, $nudge_post_types, true ) );
    ?> />
								<label for="pt_<?php 
    echo esc_attr( $slug );
    ?>" class="pkits-sp-check-label">
									<?php 
    echo esc_html( $label );
    ?>
								</label>
							</div>
						<?php 
}
?>

						<span class="pkits-sp-check-group-label"><?php 
esc_html_e( 'Show to user roles', 'publisherkits-socialpromoter' );
?></span>
						<?php 
foreach ( $editable_roles as $role_slug => $role_data ) {
    if ( !in_array( $role_slug, $relevant_roles, true ) ) {
        continue;
    }
    ?>
							<div class="pkits-sp-check-row">
								<input type="checkbox" id="role_<?php 
    echo esc_attr( $role_slug );
    ?>" name="nudge_roles[]"
									value="<?php 
    echo esc_attr( $role_slug );
    ?>"
									<?php 
    checked( in_array( $role_slug, $nudge_roles, true ) );
    ?> />
								<label for="role_<?php 
    echo esc_attr( $role_slug );
    ?>" class="pkits-sp-check-label">
									<?php 
    echo esc_html( translate_user_role( $role_data['name'] ) );
    ?>
								</label>
							</div>
						<?php 
}
?>

					</div>
				</div>

				<!-- Posting defaults -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Posting defaults', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Default values pre-populated when composing social posts.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">
						<div class="pkits-sp-form-group" style="margin-bottom:0;">
							<label for="copy_template"><?php 
esc_html_e( 'Default copy template', 'publisherkits-socialpromoter' );
?></label>
							<textarea id="copy_template" name="copy_template" rows="3"><?php 
echo esc_textarea( $copy_template );
?></textarea>
							<span class="pkits-sp-field-hint">
								<?php 
esc_html_e( 'Available placeholders: {post_title}, {post_url}, {site_name}. Used to pre-fill the copy field in the post editor panel and publish modal.', 'publisherkits-socialpromoter' );
?>
							</span>
							<div class="pkits-sp-template-preview-box" style="margin-top:10px;">
								<strong><?php 
esc_html_e( 'Preview:', 'publisherkits-socialpromoter' );
?></strong>
								<span id="pkits-sp-template-preview-text"></span>
							</div>
						</div>
					</div>
				</div>

				<!-- Queue & scheduling -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Queue &amp; scheduling', 'publisherkits-socialpromoter' );
?></h2>
					</div>
					<div class="pkits-sp-card-body">
						<div class="pkits-sp-check-row">
							<input type="checkbox" id="auto_cancel_on_delete" name="auto_cancel_on_delete" value="1" <?php 
checked( $auto_cancel );
?> />
							<label for="auto_cancel_on_delete" class="pkits-sp-check-label">
								<?php 
esc_html_e( 'Automatically cancel pending scheduled posts when the linked WordPress post is deleted', 'publisherkits-socialpromoter' );
?>
								<small><?php 
esc_html_e( 'Auto-cancel on post delete', 'publisherkits-socialpromoter' );
?></small>
							</label>
						</div>
					</div>
				</div>

				<!-- Advanced -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Advanced', 'publisherkits-socialpromoter' );
?></h2>
					</div>
					<div class="pkits-sp-card-body">
						<div class="pkits-sp-check-row">
							<input type="checkbox" id="debug_logging" name="debug_logging" value="1" <?php 
checked( $debug_logging );
?> />
							<label for="debug_logging" class="pkits-sp-check-label">
								<?php 
esc_html_e( 'Log API calls and queue events to the WordPress debug log (WP_DEBUG_LOG must be enabled)', 'publisherkits-socialpromoter' );
?>
								<small><?php 
esc_html_e( 'Debug logging', 'publisherkits-socialpromoter' );
?></small>
							</label>
						</div>
						<div class="pkits-sp-check-row" style="padding-top:10px;">
							<input type="checkbox" id="delete_data_on_uninstall" name="delete_data_on_uninstall" value="1" <?php 
checked( !empty( $settings['delete_data_on_uninstall'] ) );
?> />
							<label for="delete_data_on_uninstall" class="pkits-sp-check-label">
								<?php 
esc_html_e( 'Delete all SocialPromoter data when the plugin is deleted', 'publisherkits-socialpromoter' );
?>
								<small><?php 
esc_html_e( 'Off by default. Your connected accounts, API keys, queue and settings are preserved if you delete and reinstall the plugin. Tick this only if you want everything removed on deletion.', 'publisherkits-socialpromoter' );
?></small>
							</label>
						</div>
						<div class="pkits-sp-check-row" style="padding-top:10px;">
							<div>
								<span class="pkits-sp-check-group-label" style="margin:0 0 6px;"><?php 
esc_html_e( 'Connected platforms', 'publisherkits-socialpromoter' );
?></span>
								<a href="<?php 
echo esc_url( admin_url( 'admin.php?page=publisherkits-socialpromoter-accounts' ) );
?>" class="pkits-sp-btn-secondary" style="font-size:12px;padding:6px 14px;">
									<?php 
esc_html_e( 'Manage Connected Platforms', 'publisherkits-socialpromoter' );
?>
								</a>
							</div>
						</div>
					</div>
				</div>

				<?php 
?>
				<!-- Site context -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Site context, audience &amp; goals', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Describe your site, audience and goals. PublisherKits tools use this to frame copy and reporting for your readers and what your publication is trying to achieve.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">

						<?php 
if ( $sp_profile_set ) {
    ?>
							<div style="margin-bottom:16px;padding:10px 14px;background:#d1f5e8;border:1px solid #a8e6d0;border-radius:5px;font-size:13px;color:#1d7a55;">
								<strong><?php 
    esc_html_e( 'Using your PublisherKits site profile', 'publisherkits-socialpromoter' );
    ?></strong>
								<?php 
    if ( $sp_insight_active ) {
        ?>
									<?php 
        esc_html_e( 'These goals come from Insight Engine and are applied wherever PublisherKits tools generate copy.', 'publisherkits-socialpromoter' );
        ?>
								<?php 
    } else {
        ?>
									<?php 
        esc_html_e( 'These goals are shared across PublisherKits plugins and applied wherever PublisherKits tools generate copy.', 'publisherkits-socialpromoter' );
        ?>
								<?php 
    }
    ?>
								<div style="margin-top:8px;font-size:12px;color:#155;">
									<?php 
    if ( !empty( $sp_profile['primary_goal'] ) ) {
        ?>
										<div><strong><?php 
        esc_html_e( 'Primary goal:', 'publisherkits-socialpromoter' );
        ?></strong> <?php 
        echo esc_html( $sp_goal_labels[$sp_profile['primary_goal']] ?? $sp_profile['primary_goal'] );
        ?></div>
									<?php 
    }
    ?>
									<?php 
    if ( !empty( $sp_profile['audience_description'] ) ) {
        ?>
										<div><strong><?php 
        esc_html_e( 'Audience:', 'publisherkits-socialpromoter' );
        ?></strong> <?php 
        echo esc_html( wp_trim_words( $sp_profile['audience_description'], 30 ) );
        ?></div>
									<?php 
    }
    ?>
								</div>
								<?php 
    if ( $sp_insight_active ) {
        ?>
									<div style="margin-top:8px;">
										<a href="<?php 
        echo esc_url( admin_url( 'admin.php?page=pkinsight-settings' ) );
        ?>"><?php 
        esc_html_e( 'Edit in Insight Engine', 'publisherkits-socialpromoter' );
        ?> &rarr;</a>
									</div>
								<?php 
    }
    ?>
							</div>
						<?php 
} else {
    ?>
							<!-- Lightweight goal/audience inputs - write to the shared profile -->
							<div class="pkits-sp-form-group">
								<label for="sp_primary_goal"><?php 
    esc_html_e( 'Primary goal of this publication', 'publisherkits-socialpromoter' );
    ?></label>
								<select id="sp_primary_goal" name="sp_primary_goal">
									<option value="">&mdash; <?php 
    esc_html_e( 'Not set', 'publisherkits-socialpromoter' );
    ?> &mdash;</option>
									<?php 
    foreach ( $sp_goal_labels as $goal_key => $goal_label ) {
        ?>
										<option value="<?php 
        echo esc_attr( $goal_key );
        ?>" <?php 
        selected( $sp_profile['primary_goal'], $goal_key );
        ?>><?php 
        echo esc_html( $goal_label );
        ?></option>
									<?php 
    }
    ?>
								</select>
								<span class="pkits-sp-field-hint"><?php 
    esc_html_e( 'What your publication is mainly trying to achieve. PublisherKits tools frame copy and reporting to serve this.', 'publisherkits-socialpromoter' );
    ?></span>
							</div>
							<div class="pkits-sp-form-group" style="margin-top:14px;">
								<label for="sp_audience_description"><?php 
    esc_html_e( 'Audience description', 'publisherkits-socialpromoter' );
    ?></label>
								<textarea id="sp_audience_description" name="sp_audience_description" rows="3"
									placeholder="<?php 
    esc_attr_e( 'e.g. HR directors and people managers in UK organisations, responsible for employment policy and workplace culture.', 'publisherkits-socialpromoter' );
    ?>"><?php 
    echo esc_textarea( $sp_profile['audience_description'] );
    ?></textarea>
								<span class="pkits-sp-field-hint"><?php 
    esc_html_e( 'Who reads your content. Shared with other PublisherKits plugins, including Insight Engine if you install it.', 'publisherkits-socialpromoter' );
    ?></span>
							</div>
							<hr style="border:none;border-top:1px solid #e8f0f8;margin:16px 0;" />
						<?php 
}
?>

						<div class="pkits-sp-form-group">
							<label for="site_context"><?php 
esc_html_e( 'Brand voice / extra context (optional)', 'publisherkits-socialpromoter' );
?></label>
							<textarea id="site_context" name="site_context" rows="4"
								placeholder="<?php 
esc_attr_e( 'e.g. Authoritative but accessible tone. Avoid hype. British spelling. Reference employment law developments where relevant.', 'publisherkits-socialpromoter' );
?>"><?php 
echo esc_textarea( $site_context );
?></textarea>
							<span class="pkits-sp-field-hint">
								<?php 
esc_html_e( 'Free-text brand voice and any context not covered above. This is the shared PublisherKits Site Profile context (PublisherKits → Site Profile) - editing it here or there updates the same value, used by every PublisherKits plugin.', 'publisherkits-socialpromoter' );
?>
							</span>
						</div>
					</div>
				</div>

				<!-- SEO keywords -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'SEO target terms', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Your top keywords and phrases. Used naturally by PublisherKits tools that generate copy - never forced or repeated mechanically.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">
						<div class="pkits-sp-form-grid">
							<?php 
for ($i = 0; $i < 3; $i++) {
    ?>
							<div class="pkits-sp-form-group">
								<label for="seo_primary_<?php 
    echo (int) $i;
    ?>">
									<?php 
    /* translators: %d: keyword number */
    echo esc_html( sprintf( __( 'Primary keyword %d', 'publisherkits-socialpromoter' ), $i + 1 ) );
    ?>
								</label>
								<input type="text" id="seo_primary_<?php 
    echo (int) $i;
    ?>"
									name="seo_primary[]"
									value="<?php 
    echo esc_attr( $seo_primary[$i] ?? '' );
    ?>"
									placeholder="<?php 
    echo esc_attr( array('e.g. HR software UK', 'e.g. employee engagement', 'e.g. workplace wellbeing')[$i] );
    ?>" />
							</div>
							<?php 
}
?>
							<?php 
for ($i = 0; $i < 2; $i++) {
    ?>
							<div class="pkits-sp-form-group">
								<label for="seo_secondary_<?php 
    echo (int) $i;
    ?>">
									<?php 
    /* translators: %d: phrase number */
    echo esc_html( sprintf( __( 'Secondary phrase %d', 'publisherkits-socialpromoter' ), $i + 1 ) );
    ?>
									<span style="font-weight:400;color:#8a9ab0;font-size:11px;"><?php 
    esc_html_e( '(optional)', 'publisherkits-socialpromoter' );
    ?></span>
								</label>
								<input type="text" id="seo_secondary_<?php 
    echo (int) $i;
    ?>"
									name="seo_secondary[]"
									value="<?php 
    echo esc_attr( $seo_secondary[$i] ?? '' );
    ?>"
									placeholder="<?php 
    echo esc_attr( array('e.g. HR trends 2026', 'e.g. people management software')[$i] );
    ?>" />
							</div>
							<?php 
}
?>
						</div>
						<p class="pkits-sp-field-hint" style="margin-top:4px;"><?php 
esc_html_e( 'Shared with other PublisherKits plugins. PublisherKits tools use these where they fit naturally - not in every post.', 'publisherkits-socialpromoter' );
?></p>
					</div>
				</div>

				<?php 
?>
				<!-- Compose post type selector -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Compose - post types', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Choose which content types appear in the Compose post selector. Untick plugin infrastructure types that are never promoted on social.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">
						<div style="display:flex;flex-wrap:wrap;gap:6px 20px;">
							<?php 
foreach ( $all_public_types as $slug => $obj ) {
    // Skip pure internals that should never be shown.
    if ( in_array( $slug, array(
        'attachment',
        'revision',
        'nav_menu_item',
        'custom_css',
        'customize_changeset',
        'oembed_cache',
        'user_request',
        'wp_block',
        'wp_template',
        'wp_template_part',
        'wp_global_styles',
        'wp_navigation',
        'wp_font_face',
        'wp_font_family'
    ), true ) ) {
        continue;
    }
    $is_enabled = in_array( $slug, $enabled_types, true );
    $is_infra = in_array( $slug, $infrastructure_types, true );
    ?>
								<label style="display:flex;align-items:center;gap:6px;font-size:13px;cursor:pointer;min-width:160px;padding:4px 0;">
									<input type="checkbox"
										name="compose_post_types[]"
										value="<?php 
    echo esc_attr( $slug );
    ?>"
										<?php 
    checked( $is_enabled );
    ?> />
									<span style="color:#1a2d4a;font-weight:<?php 
    echo ( $is_infra ? '400' : '600' );
    ?>;">
										<?php 
    echo esc_html( $obj->labels->name );
    ?>
									</span>
									<?php 
    if ( $is_infra ) {
        ?>
										<span style="font-size:10px;color:#8a9ab0;font-style:italic;"><?php 
        esc_html_e( 'plugin', 'publisherkits-socialpromoter' );
        ?></span>
									<?php 
    }
    ?>
								</label>
							<?php 
}
?>
						</div>
						<p class="pkits-sp-field-hint" style="margin-top:10px;"><?php 
esc_html_e( 'Types labelled "plugin" are auto-detected as plugin infrastructure and unticked by default. You can re-enable them if needed.', 'publisherkits-socialpromoter' );
?></p>
					</div>
				</div>

				<!-- Branded images (Pro) -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title">
							<?php 
esc_html_e( 'Branded images', 'publisherkits-socialpromoter' );
?>
							<?php 
// Upgrade information shown in the free plugin.
if ( PKITS_SP_Admin::show_upgrade_notice() ) {
    ?>
								<span style="font-size:10px;background:#4a7fc1;color:#fff;padding:2px 8px;border-radius:3px;font-weight:600;margin-left:6px;vertical-align:middle;">PRO</span>
							<?php 
}
?>
						</h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Automatically resize images to optimal dimensions for each platform and add your logo watermark. Applied at post time.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">

						<?php 
if ( PKITS_SP_Admin::show_upgrade_notice() ) {
    ?>
							<p style="color:#8a9ab0;font-style:italic;font-size:13px;"><?php 
    esc_html_e( 'Branded image processing is part of SocialPromoter Pro, available separately. This free plugin posts your images exactly as they are.', 'publisherkits-socialpromoter' );
    ?></p>
						<?php 
}
?>

						<?php 
?>
					</div>
				</div>


				<!-- Default brand hashtags -->
				<div class="pkits-sp-card">
					<div class="pkits-sp-card-header">
						<h2 class="pkits-sp-card-title"><?php 
esc_html_e( 'Brand hashtags', 'publisherkits-socialpromoter' );
?></h2>
						<p class="pkits-sp-card-desc"><?php 
esc_html_e( 'Standing hashtags for your brand. Use them on their own, blended with the per-story tags, or only as a backup when a story has few tags of its own.', 'publisherkits-socialpromoter' );
?></p>
					</div>
					<div class="pkits-sp-card-body">
						<div class="pkits-sp-form-group">
							<label for="brand_default_hashtags"><?php 
esc_html_e( 'Default brand hashtags', 'publisherkits-socialpromoter' );
?></label>
							<input type="text" name="brand_default_hashtags" id="brand_default_hashtags"
								value="<?php 
echo esc_attr( $brand_default_tags );
?>"
								placeholder="<?php 
echo esc_attr__( 'e.g. Pathfinder, Resettlement, ArmedForces', 'publisherkits-socialpromoter' );
?>" />
							<span class="pkits-sp-field-hint"><?php 
esc_html_e( 'Comma separated, without the # (spaces inside a tag are removed automatically).', 'publisherkits-socialpromoter' );
?></span>
						</div>
						<div class="pkits-sp-form-group">
							<label for="brand_tags_mode"><?php 
esc_html_e( 'How to use brand hashtags', 'publisherkits-socialpromoter' );
?></label>
							<select name="brand_tags_mode" id="brand_tags_mode">
								<option value="off"      <?php 
selected( $brand_tags_mode, 'off' );
?>><?php 
esc_html_e( 'Off - do not add brand hashtags automatically', 'publisherkits-socialpromoter' );
?></option>
								<option value="always"   <?php 
selected( $brand_tags_mode, 'always' );
?>><?php 
esc_html_e( 'Blend - mix brand hashtags with the story hashtags', 'publisherkits-socialpromoter' );
?></option>
								<option value="fallback" <?php 
selected( $brand_tags_mode, 'fallback' );
?>><?php 
esc_html_e( 'Fallback - use brand hashtags only when a story has few of its own', 'publisherkits-socialpromoter' );
?></option>
								<option value="only"     <?php 
selected( $brand_tags_mode, 'only' );
?>><?php 
esc_html_e( 'Only - use brand hashtags exclusively, ignore story hashtags', 'publisherkits-socialpromoter' );
?></option>
							</select>
							<span class="pkits-sp-field-hint"><?php 
esc_html_e( 'The "Story hashtags" chips in Compose reflect this setting. Platform limits still apply (X 3, LinkedIn 5, Facebook 2).', 'publisherkits-socialpromoter' );
?></span>
						</div>
					</div>
				</div>

				<!-- Action bar -->
				<div class="pkits-sp-action-bar">
					<button type="submit" class="pkits-sp-btn-primary">
						<?php 
esc_html_e( 'Save settings', 'publisherkits-socialpromoter' );
?>
					</button>
				</div>

			</form>
		</div>

		<!-- ── SIDEBAR ───────────────────────────────────────────── -->
		<div class="pkits-sp-page-aside">

			<!-- Settings overview -->
			<div class="pkits-sp-widget">
				<div class="pkits-sp-widget-header">
					<div class="pkits-sp-widget-icon">&#9881;</div>
					<h3 class="pkits-sp-widget-title"><?php 
esc_html_e( 'Settings overview', 'publisherkits-socialpromoter' );
?></h3>
				</div>
				<div class="pkits-sp-widget-body">
					<div class="pkits-sp-summary-row">
						<div class="pkits-sp-summary-label"><?php 
esc_html_e( 'Reminders', 'publisherkits-socialpromoter' );
?></div>
						<div class="pkits-sp-summary-value"><?php 
echo esc_html( $sum_reminders );
?></div>
					</div>
					<div class="pkits-sp-summary-row">
						<div class="pkits-sp-summary-label"><?php 
esc_html_e( 'Post types', 'publisherkits-socialpromoter' );
?></div>
						<div class="pkits-sp-summary-value"><?php 
echo esc_html( $sum_post_types_str );
?></div>
					</div>
					<div class="pkits-sp-summary-row">
						<div class="pkits-sp-summary-label"><?php 
esc_html_e( 'Visible to', 'publisherkits-socialpromoter' );
?></div>
						<div class="pkits-sp-summary-value"><?php 
echo esc_html( $sum_roles_str );
?></div>
					</div>
					<div class="pkits-sp-summary-row">
						<div class="pkits-sp-summary-label"><?php 
esc_html_e( 'Template', 'publisherkits-socialpromoter' );
?></div>
						<div class="pkits-sp-summary-value"><?php 
echo esc_html( $sum_template );
?></div>
					</div>
					<div class="pkits-sp-summary-row">
						<div class="pkits-sp-summary-label"><?php 
esc_html_e( 'Queue', 'publisherkits-socialpromoter' );
?></div>
						<div class="pkits-sp-summary-value"><?php 
echo esc_html( $sum_queue );
?></div>
					</div>
				</div>
			</div>

			<!-- Helpful guidance -->
			<div class="pkits-sp-widget pkits-sp-guidance-widget">
				<div class="pkits-sp-widget-header">
					<div class="pkits-sp-widget-icon">&#128161;</div>
					<h3 class="pkits-sp-widget-title"><?php 
esc_html_e( 'Helpful guidance', 'publisherkits-socialpromoter' );
?></h3>
				</div>
				<div class="pkits-sp-widget-body">
					<ul class="pkits-sp-guidance-list">
						<li><?php 
esc_html_e( 'Use nudges sparingly so prompts remain useful.', 'publisherkits-socialpromoter' );
?></li>
						<li><?php 
esc_html_e( 'Keep copy templates short and adaptable.', 'publisherkits-socialpromoter' );
?></li>
						<li><?php 
esc_html_e( 'Review user roles before enabling prompts widely.', 'publisherkits-socialpromoter' );
?></li>
						<li><?php 
esc_html_e( 'Use debug logging only when troubleshooting.', 'publisherkits-socialpromoter' );
?></li>
					</ul>
				</div>
			</div>

			<!-- Connected platforms -->
			<div class="pkits-sp-widget">
				<div class="pkits-sp-widget-header">
					<div class="pkits-sp-widget-icon">&#9728;</div>
					<h3 class="pkits-sp-widget-title"><?php 
esc_html_e( 'Connected platforms', 'publisherkits-socialpromoter' );
?></h3>
				</div>
				<div class="pkits-sp-widget-body">
					<p style="font-size:12px;color:#5a6a7a;margin:0 0 10px;line-height:1.5;">
						<?php 
esc_html_e( 'Manage your connected social accounts from one place.', 'publisherkits-socialpromoter' );
?>
					</p>
					<a href="<?php 
echo esc_url( admin_url( 'admin.php?page=publisherkits-socialpromoter-accounts' ) );
?>" class="pkits-sp-btn-secondary" style="font-size:12px;padding:7px 14px;">
						<?php 
esc_html_e( 'Open platform manager', 'publisherkits-socialpromoter' );
?>
					</a>
				</div>
			</div>

		</div>
	</div>

</div>

<?php 
ob_start();
?>
( function() {
	var t = document.getElementById( 'copy_template' );
	var p = document.getElementById( 'pkits-sp-template-preview-text' );
	if ( ! t || ! p ) { return; }
	function update() {
		p.textContent = t.value
			.replace( /\{post_title\}/g, <?php 
echo wp_json_encode( esc_html__( 'My Example Post Title', 'publisherkits-socialpromoter' ) );
?> )
			.replace( /\{post_url\}/g,   <?php 
echo wp_json_encode( home_url( '/example-post/' ) );
?> )
			.replace( /\{site_name\}/g,  <?php 
echo wp_json_encode( get_bloginfo( 'name' ) );
?> );
	}
	t.addEventListener( 'input', update );
	update();
} )();
<?php 
wp_add_inline_script( 'pkits-sp-admin', ob_get_clean() );
?>



