refactor(Core): refactor and optimize code

This commit is contained in:
2026-05-06 00:54:24 +03:30
parent 32c065e4b6
commit dec4e67b9e
20 changed files with 1787 additions and 361 deletions

View File

@@ -4,60 +4,196 @@ if (!defined('ABSPATH')) {
exit;
}
use Sodino\Controllers\RuleController;
use Sodino\Controllers\DashboardController;
use Sodino\Controllers\SettingsController;
use Sodino\Controllers\AdminController;
use Sodino\Repositories\BannerRepository;
use Sodino\Repositories\RuleRepository;
use Sodino\Repositories\UpsellRepository;
use Sodino\Repositories\EventRepository;
// Initialize admin
// Initialize repositories
$ruleRepository = new RuleRepository();
$upsellRepository = new UpsellRepository();
$bannerRepository = new BannerRepository();
$eventRepository = new EventRepository();
// Initialize controllers
$ruleController = new RuleController($ruleRepository);
$dashboardController = new DashboardController($eventRepository, $ruleRepository);
$settingsController = new SettingsController();
$adminController = new AdminController($ruleRepository, $upsellRepository, $bannerRepository);
// Add menu
add_action('admin_menu', [$adminController, 'addMenu']);
/**
* Add admin menu
*/
add_action('admin_menu', function() use ($adminController) {
add_menu_page(
__('سودینو', 'sodino'),
__('سودینو', 'sodino'),
'manage_options',
'sodino-dashboard',
[$adminController, 'dashboardPage'],
'dashicons-money-alt',
56
);
// Admin AJAX handlers
add_submenu_page(
'sodino-dashboard',
__('داشبورد', 'sodino'),
__('داشبورد', 'sodino'),
'manage_options',
'sodino-dashboard',
[$adminController, 'dashboardPage']
);
add_submenu_page(
'sodino-dashboard',
__('قوانین قیمت‌گذاری', 'sodino'),
__('قوانین قیمت‌گذاری', 'sodino'),
'manage_options',
'sodino-rules',
[$adminController, 'rulesPage']
);
add_submenu_page(
'sodino-dashboard',
__('افزودن قانون', 'sodino'),
__('افزودن قانون', 'sodino'),
'manage_options',
'sodino-add-rule',
[$adminController, 'addRulePage']
);
add_submenu_page(
'sodino-dashboard',
__('آپسل (پیشنهاد فروش)', 'sodino'),
__('آپسل (پیشنهاد فروش)', 'sodino'),
'manage_options',
'sodino-upsells',
[$adminController, 'upsellsPage']
);
add_submenu_page(
'sodino-dashboard',
__('افزودن آپسل', 'sodino'),
__('افزودن آپسل', 'sodino'),
'manage_options',
'sodino-add-upsell',
[$adminController, 'addUpsellPage']
);
add_submenu_page(
'sodino-dashboard',
__('بنرهای هوشمند', 'sodino'),
__('بنرهای هوشمند', 'sodino'),
'manage_options',
'sodino-banners',
[$adminController, 'bannersPage']
);
add_submenu_page(
'sodino-dashboard',
__('افزودن بنر', 'sodino'),
__('افزودن بنر', 'sodino'),
'manage_options',
'sodino-add-banner',
[$adminController, 'addBannerPage']
);
add_submenu_page(
'sodino-dashboard',
__('تنظیمات', 'sodino'),
__('تنظیمات', 'sodino'),
'manage_options',
'sodino-settings',
[$adminController, 'settingsPage']
);
});
/**
* Admin AJAX handlers
*/
add_action('wp_ajax_sodino_search_products', [$adminController, 'searchProductsAjax']);
// Enqueue admin assets
add_action('admin_enqueue_scripts', function($hook) use ($adminController) {
/**
* Enqueue admin assets
*/
add_action('admin_enqueue_scripts', function($hook) {
if (strpos($hook, 'sodino') === false) {
return;
}
// Enqueue Tailwind via CDN script
wp_enqueue_script('sodino-tailwind', 'https://cdn.tailwindcss.com', [], null);
// Enqueue Tailwind via CDN
wp_enqueue_script('sodino-tailwind', 'https://cdn.tailwindcss.com', [], SODINO_VERSION);
// Admin CSS
wp_enqueue_style('sodino-admin', plugin_dir_url(__FILE__) . 'css/admin.css', [], SODINO_VERSION);
if (strpos($hook, 'sodino_page_sodino-dashboard') !== false) {
// Dashboard specific scripts
if (strpos($hook, 'sodino-dashboard') !== false || strpos($hook, 'sodino_page_sodino-dashboard') !== false) {
wp_enqueue_script('sodino-chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', [], null, true);
wp_enqueue_script('sodino-dashboard-js', plugin_dir_url(__FILE__) . 'js/dashboard.js', ['sodino-chart-js'], null, true);
wp_enqueue_script('sodino-dashboard-js', plugin_dir_url(__FILE__) . 'js/dashboard.js', ['sodino-chart-js'], SODINO_VERSION, true);
}
if (strpos($hook, 'sodino_page_sodino-add-upsell') !== false) {
wp_enqueue_script('sodino-upsell-admin', plugin_dir_url(__FILE__) . 'js/upsell-admin.js', [], SODINO_VERSION, true);
// Upsell specific scripts
if (strpos($hook, 'sodino-add-upsell') !== false || strpos($hook, 'sodino_page_sodino-add-upsell') !== false) {
wp_enqueue_script('sodino-upsell-admin', plugin_dir_url(__FILE__) . 'js/upsell-admin.js', ['jquery'], SODINO_VERSION, true);
wp_localize_script('sodino-upsell-admin', 'sodinoUpsellAdmin', [
'nonce' => wp_create_nonce('sodino_search_products'),
'ajaxUrl' => admin_url('admin-ajax.php')
]);
}
if (strpos($hook, 'sodino_page_sodino-add-banner') !== false) {
// Banner specific scripts
if (strpos($hook, 'sodino-add-banner') !== false || strpos($hook, 'sodino_page_sodino-add-banner') !== false) {
wp_enqueue_media();
wp_enqueue_script('sodino-banner-admin', plugin_dir_url(__FILE__) . 'js/banner-admin.js', ['jquery'], SODINO_VERSION, true);
}
});
// Handle delete for any Sodino admin page
if (isset($_GET['page']) && strpos($_GET['page'], 'sodino') === 0 && isset($_GET['action']) && $_GET['action'] === 'delete') {
add_action('admin_init', [$adminController, 'handleDelete']);
}
if (isset($_GET['page']) && strpos($_GET['page'], 'sodino') === 0 && isset($_GET['action']) && in_array($_GET['action'], ['delete_banner', 'toggle_banner_status'], true)) {
add_action('admin_init', [$adminController, 'handleBannerActions']);
}
// Handle upsell actions
if (isset($_GET['page']) && strpos($_GET['page'], 'sodino') === 0 && isset($_GET['action']) && in_array($_GET['action'], ['delete_upsell', 'toggle_upsell_status'], true)) {
add_action('admin_init', [$adminController, 'handleUpsellActions']);
}
/**
* Handle admin actions
*/
add_action('admin_init', function() use ($ruleController, $settingsController, $adminController) {
$page = $_GET['page'] ?? '';
$action = $_GET['action'] ?? '';
// Rule actions
if ($page === 'sodino-rules' && $action === 'delete') {
$ruleController->delete();
}
// Settings actions
if ($page === 'sodino-settings' && $action === 'clear_cache') {
$settingsController->clearCache();
}
// Banner actions
if (strpos($page, 'sodino') === 0 && in_array($action, ['delete_banner', 'toggle_banner_status'], true)) {
$adminController->handleBannerActions();
}
// Upsell actions
if (strpos($page, 'sodino') === 0 && in_array($action, ['delete_upsell', 'toggle_upsell_status'], true)) {
$adminController->handleUpsellActions();
}
});
/**
* Show admin notices
*/
add_action('admin_notices', function() {
$notice = get_transient('sodino_admin_notice');
if ($notice) {
$class = $notice['type'] === 'error' ? 'notice-error' : 'notice-success';
printf(
'<div class="notice %s is-dismissible"><p>%s</p></div>',
esc_attr($class),
esc_html($notice['message'])
);
delete_transient('sodino_admin_notice');
}
});

View File

@@ -0,0 +1,18 @@
<?php
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
?>
<div class="bg-white border-b border-gray-200">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="py-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-gray-900"><?php _e('سودینو', 'sodino'); ?></h1>
<p class="mt-1 text-sm text-gray-500"><?php _e('بهینه‌سازی هوشمند فروش', 'sodino'); ?></p>
</div>
</div>
</div>
</div>
</div>

181
admin/components/layout.php Normal file
View File

@@ -0,0 +1,181 @@
<?php
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
/**
* Admin Layout Component
* Usage: sodino_admin_layout($current_page, $content_callback)
*/
function sodino_admin_layout($current_page, $content_callback) {
?>
<div id="sodino-app" class="min-h-screen bg-gray-50" dir="rtl">
<?php include SODINO_PLUGIN_DIR . 'admin/components/header.php'; ?>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="flex gap-8">
<?php include SODINO_PLUGIN_DIR . 'admin/components/sidebar.php'; ?>
<main class="flex-1 min-w-0">
<?php call_user_func($content_callback); ?>
</main>
</div>
</div>
</div>
<?php
}
/**
* Card Component
*/
function sodino_card($title = '', $description = '', $content_callback = null, $classes = '') {
?>
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 <?php echo esc_attr($classes); ?>">
<?php if ($title): ?>
<h2 class="text-xl font-semibold text-gray-900 mb-2"><?php echo esc_html($title); ?></h2>
<?php endif; ?>
<?php if ($description): ?>
<p class="text-gray-600 mb-4"><?php echo esc_html($description); ?></p>
<?php endif; ?>
<?php if ($content_callback): ?>
<?php call_user_func($content_callback); ?>
<?php endif; ?>
</div>
<?php
}
/**
* Stats Card Component
*/
function sodino_stat_card($title, $value, $type = 'default') {
$classes = [
'primary' => 'bg-gradient-to-br from-blue-600 to-blue-700 text-white',
'default' => 'bg-white border border-gray-200'
];
$class = $classes[$type] ?? $classes['default'];
$text_class = $type === 'primary' ? 'text-white opacity-90' : 'text-gray-600';
$value_class = $type === 'primary' ? 'text-white' : 'text-gray-900';
?>
<div class="<?php echo esc_attr($class); ?> rounded-lg p-6">
<h3 class="text-sm font-medium <?php echo esc_attr($text_class); ?>"><?php echo esc_html($title); ?></h3>
<div class="text-2xl font-bold <?php echo esc_attr($value_class); ?> mt-2"><?php echo $value; ?></div>
</div>
<?php
}
/**
* Button Component
*/
function sodino_button($text, $url = '#', $type = 'primary', $icon = '') {
$classes = [
'primary' => 'bg-blue-600 text-white hover:bg-blue-700',
'secondary' => 'bg-white text-gray-700 border border-gray-300 hover:bg-gray-50',
'danger' => 'bg-red-600 text-white hover:bg-red-700'
];
$class = $classes[$type] ?? $classes['primary'];
?>
<a href="<?php echo esc_url($url); ?>"
class="inline-flex items-center px-4 py-2 text-sm font-medium rounded-lg <?php echo esc_attr($class); ?> focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors duration-200">
<?php if ($icon): ?>
<svg class="-ml-1 mr-2 h-5 w-5" fill="currentColor" viewBox="0 0 20 20">
<?php echo $icon; ?>
</svg>
<?php endif; ?>
<?php echo esc_html($text); ?>
</a>
<?php
}
/**
* Form Field Component
*/
function sodino_form_field($args) {
$defaults = [
'type' => 'text',
'name' => '',
'label' => '',
'value' => '',
'placeholder' => '',
'required' => false,
'description' => '',
'options' => [],
'class' => ''
];
$args = wp_parse_args($args, $defaults);
extract($args);
$required_attr = $required ? 'required' : '';
$field_id = 'sodino_' . $name;
?>
<div class="<?php echo esc_attr($class); ?>">
<?php if ($label): ?>
<label for="<?php echo esc_attr($field_id); ?>" class="block text-sm font-medium text-gray-700 mb-2">
<?php echo esc_html($label); ?>
<?php if ($required): ?>
<span class="text-red-500">*</span>
<?php endif; ?>
</label>
<?php endif; ?>
<?php if ($type === 'textarea'): ?>
<textarea
id="<?php echo esc_attr($field_id); ?>"
name="<?php echo esc_attr($name); ?>"
rows="4"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="<?php echo esc_attr($placeholder); ?>"
<?php echo $required_attr; ?>
><?php echo esc_textarea($value); ?></textarea>
<?php elseif ($type === 'select'): ?>
<select
id="<?php echo esc_attr($field_id); ?>"
name="<?php echo esc_attr($name); ?>"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
<?php echo $required_attr; ?>
>
<?php foreach ($options as $opt_value => $opt_label): ?>
<option value="<?php echo esc_attr($opt_value); ?>" <?php selected($value, $opt_value); ?>>
<?php echo esc_html($opt_label); ?>
</option>
<?php endforeach; ?>
</select>
<?php elseif ($type === 'checkbox'): ?>
<label class="flex items-center">
<input
type="checkbox"
id="<?php echo esc_attr($field_id); ?>"
name="<?php echo esc_attr($name); ?>"
value="1"
class="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded"
<?php checked($value, 1); ?>
<?php echo $required_attr; ?>
/>
<span class="mr-2 text-sm text-gray-700"><?php echo esc_html($label); ?></span>
</label>
<?php else: ?>
<input
type="<?php echo esc_attr($type); ?>"
id="<?php echo esc_attr($field_id); ?>"
name="<?php echo esc_attr($name); ?>"
value="<?php echo esc_attr($value); ?>"
placeholder="<?php echo esc_attr($placeholder); ?>"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
<?php echo $required_attr; ?>
/>
<?php endif; ?>
<?php if ($description): ?>
<p class="mt-1 text-sm text-gray-500"><?php echo esc_html($description); ?></p>
<?php endif; ?>
</div>
<?php
}

View File

@@ -0,0 +1,31 @@
<?php
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
$current_page = $current_page ?? '';
$menu_items = [
'sodino-dashboard' => __('داشبورد', 'sodino'),
'sodino-rules' => __('قوانین', 'sodino'),
'sodino-add-rule' => __('افزودن قانون', 'sodino'),
'sodino-upsells' => __('آپسل (پیشنهاد فروش)', 'sodino'),
'sodino-add-upsell' => __('افزودن آپسل', 'sodino'),
'sodino-banners' => __('بنرهای هوشمند', 'sodino'),
'sodino-add-banner' => __('افزودن بنر', 'sodino'),
'sodino-settings' => __('تنظیمات', 'sodino'),
];
?>
<aside class="w-64 flex-shrink-0">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h2 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('منوی سودینو', 'sodino'); ?></h2>
<nav class="space-y-2">
<?php foreach ($menu_items as $page => $label): ?>
<a href="<?php echo admin_url('admin.php?page=' . $page); ?>"
class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === $page ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php echo esc_html($label); ?>
</a>
<?php endforeach; ?>
</nav>
</div>
</aside>

View File

@@ -4,197 +4,185 @@ if (!defined('ABSPATH')) {
exit;
}
$current_page = sanitize_text_field($_GET['page'] ?? 'sodino-settings');
?>
<div id="sodino-app" class="min-h-screen bg-gray-50" dir="rtl">
<!-- Header -->
<div class="bg-white border-b border-gray-200">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="py-6">
<div class="flex items-center justify-between">
<div>
<h1 class="text-3xl font-bold text-gray-900"><?php _e('سودینو', 'sodino'); ?></h1>
<p class="mt-1 text-sm text-gray-500"><?php _e('بهینه‌سازی هوشمند فروش', 'sodino'); ?></p>
// Load components
require_once SODINO_PLUGIN_DIR . 'admin/components/layout.php';
sodino_admin_layout($current_page ?? 'sodino-settings', function() use ($settings) {
?>
<!-- Page Header -->
<?php sodino_card(
__('تنظیمات سودینو', 'sodino'),
__('تنظیمات عمومی پلاگین را مدیریت کنید.', 'sodino'),
null,
'mb-8'
); ?>
<!-- Settings Form -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<form method="post" class="space-y-8">
<?php wp_nonce_field('sodino_save_settings', 'sodino_settings_nonce'); ?>
<!-- General Settings -->
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('تنظیمات عمومی', 'sodino'); ?></h3>
<div class="space-y-4">
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'plugin_enabled',
'label' => __('فعال‌سازی پلاگین', 'sodino'),
'value' => $settings['plugin_enabled'] ?? 1,
'description' => __('پلاگین سودینو را فعال یا غیرفعال کنید.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'pricing_enabled',
'label' => __('فعال‌سازی قیمت‌گذاری پویا', 'sodino'),
'value' => $settings['pricing_enabled'] ?? 1,
'description' => __('قیمت‌گذاری پویا بر اساس قوانین تعریف‌شده.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'upsell_enabled',
'label' => __('فعال‌سازی آپسل', 'sodino'),
'value' => $settings['upsell_enabled'] ?? 1,
'description' => __('نمایش پیشنهادات فروش به مشتریان.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'banner_enabled',
'label' => __('فعال‌سازی بنرهای هوشمند', 'sodino'),
'value' => $settings['banner_enabled'] ?? 1,
'description' => __('نمایش بنرهای هدفمند به کاربران.', 'sodino')
]); ?>
</div>
</div>
<!-- Pricing Strategy -->
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('استراتژی قیمت‌گذاری', 'sodino'); ?></h3>
<div class="space-y-4">
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'allow_multiple_rules',
'label' => __('اجازه اعمال چند قانون همزمان', 'sodino'),
'value' => $settings['allow_multiple_rules'] ?? 0,
'description' => __('اگر فعال باشد، چند قانون می‌تواند روی یک محصول اعمال شود.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'select',
'name' => 'strategy',
'label' => __('استراتژی انتخاب قانون', 'sodino'),
'value' => $settings['strategy'] ?? 'priority',
'options' => [
'priority' => __('بر اساس اولویت', 'sodino'),
'highest_discount' => __('بیشترین تخفیف', 'sodino'),
'first_valid' => __('اولین قانون معتبر', 'sodino')
],
'description' => __('نحوه انتخاب قانون زمانی که چند قانون معتبر وجود دارد.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'number',
'name' => 'max_discount_percent',
'label' => __('حداکثر درصد تخفیف', 'sodino'),
'value' => $settings['max_discount_percent'] ?? 100,
'placeholder' => '100',
'description' => __('حداکثر درصد تخفیفی که می‌تواند اعمال شود (0-100).', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'number',
'name' => 'min_product_price',
'label' => __('حداقل قیمت محصول', 'sodino'),
'value' => $settings['min_product_price'] ?? 0,
'placeholder' => '0',
'description' => __('حداقل قیمتی که یک محصول می‌تواند داشته باشد.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'cart_pricing_enabled',
'label' => __('قیمت‌گذاری در سبد خرید', 'sodino'),
'value' => $settings['cart_pricing_enabled'] ?? 1,
'description' => __('اعمال قیمت‌گذاری پویا در صفحه سبد خرید.', 'sodino')
]); ?>
</div>
</div>
<!-- Performance Settings -->
<div class="border-b border-gray-200 pb-6">
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('تنظیمات عملکرد', 'sodino'); ?></h3>
<div class="space-y-4">
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'cache_enabled',
'label' => __('فعال‌سازی کش', 'sodino'),
'value' => $settings['cache_enabled'] ?? 1,
'description' => __('استفاده از کش برای بهبود عملکرد.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'number',
'name' => 'cache_duration',
'label' => __('مدت زمان کش (ثانیه)', 'sodino'),
'value' => $settings['cache_duration'] ?? 3600,
'placeholder' => '3600',
'description' => __('مدت زمان نگهداری داده‌ها در کش (پیش‌فرض: 3600 ثانیه = 1 ساعت).', 'sodino')
]); ?>
<div class="flex items-center gap-4">
<?php sodino_button(
__('پاک کردن کش', 'sodino'),
wp_nonce_url(admin_url('admin.php?page=sodino-settings&action=clear_cache'), 'clear_cache'),
'secondary'
); ?>
<span class="text-sm text-gray-500"><?php _e('تمام کش‌های سودینو را پاک می‌کند.', 'sodino'); ?></span>
</div>
</div>
</div>
</div>
</div>
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="flex gap-8">
<!-- Sidebar -->
<aside class="w-64 flex-shrink-0">
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<h2 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('منوی سودینو', 'sodino'); ?></h2>
<nav class="space-y-2">
<a href="<?php echo admin_url('admin.php?page=sodino-dashboard'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-dashboard' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('داشبورد', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-rules'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-rules' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('قوانین', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-add-rule'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-add-rule' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('افزودن قانون', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-upsells'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-upsells' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('آپسل (پیشنهاد فروش)', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-add-upsell'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-add-upsell' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('افزودن آپسل', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-competitor-price'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-competitor-price' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('قیمت رقبا (به‌زودی)', 'sodino'); ?>
</a>
<a href="<?php echo admin_url('admin.php?page=sodino-settings'); ?>" class="block px-3 py-2 rounded-md text-sm font-medium <?php echo $current_page === 'sodino-settings' ? 'bg-blue-50 text-blue-700 border-r-2 border-blue-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'; ?>">
<?php _e('تنظیمات', 'sodino'); ?>
</a>
</nav>
<!-- Advanced Settings -->
<div>
<h3 class="text-lg font-semibold text-gray-900 mb-4"><?php _e('تنظیمات پیشرفته', 'sodino'); ?></h3>
<div class="space-y-4">
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'ab_testing_enabled',
'label' => __('فعال‌سازی A/B Testing', 'sodino'),
'value' => $settings['ab_testing_enabled'] ?? 0,
'description' => __('تست A/B برای قوانین قیمت‌گذاری (قابلیت آزمایشی).', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'scheduled_campaigns_enabled',
'label' => __('فعال‌سازی کمپین‌های زمان‌بندی شده', 'sodino'),
'value' => $settings['scheduled_campaigns_enabled'] ?? 1,
'description' => __('اجرای خودکار قوانین بر اساس تاریخ شروع و پایان.', 'sodino')
]); ?>
<?php sodino_form_field([
'type' => 'checkbox',
'name' => 'debug_mode',
'label' => __('حالت دیباگ', 'sodino'),
'value' => $settings['debug_mode'] ?? 0,
'description' => __('فعال‌سازی لاگ‌های دیباگ (فقط برای توسعه‌دهندگان).', 'sodino')
]); ?>
</div>
</aside>
</div>
<!-- Main Content -->
<main class="flex-1 min-w-0">
<!-- Page Header -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 mb-8">
<h2 class="text-2xl font-semibold text-gray-900"><?php _e('تنظیمات سودینو', 'sodino'); ?></h2>
<p class="mt-2 text-gray-600"><?php _e('کنترل کامل تجربه قیمت‌گذاری و بهینه‌سازی درآمد را از اینجا انجام دهید.', 'sodino'); ?></p>
</div>
<?php if (isset($_GET['updated']) && $_GET['updated'] === 'true') : ?>
<div class="mb-6 bg-green-50 border border-green-200 rounded-lg p-4">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
</div>
<div class="mr-3">
<p class="text-sm font-medium text-green-800"><?php _e('تنظیمات با موفقیت ذخیره شد.', 'sodino'); ?></p>
</div>
</div>
</div>
<?php endif; ?>
<form method="post" class="space-y-6">
<?php wp_nonce_field('sodino_save_settings', 'sodino_settings_nonce'); ?>
<!-- General Section -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="mb-6">
<h3 class="text-lg font-semibold text-gray-900"><?php _e('عمومی', 'sodino'); ?></h3>
<p class="mt-1 text-sm text-gray-500"><?php _e('تنظیمات کلی فعال‌سازی پلاگین و ویژگی‌های اصلی.', 'sodino'); ?></p>
</div>
<div class="grid gap-6 md:grid-cols-2">
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="plugin_enabled" value="1" <?php checked($settings['plugin_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('فعال‌سازی کل پلاگین', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('اگر غیرفعال باشد، هیچ قاعده‌ای اعمال نخواهد شد.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="pricing_enabled" value="1" <?php checked($settings['pricing_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('فعال‌سازی قیمت‌گذاری پویا', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('این گزینه، اعمال قوانین قیمت‌گذاری را کنترل می‌کند.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="upsell_enabled" value="1" <?php checked($settings['upsell_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('فعال‌سازی سیستم آپسل', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('پیشنهادهای درآمدی اضافه را نمایش می‌دهد.', 'sodino'); ?></p>
</div>
</div>
</div>
<!-- Pricing Behavior Section -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="mb-6">
<h3 class="text-lg font-semibold text-gray-900"><?php _e('رفتار قیمت‌گذاری', 'sodino'); ?></h3>
<p class="mt-1 text-sm text-gray-500"><?php _e('چگونگی اجرای قوانین در فرآیند قیمت‌گذاری.', 'sodino'); ?></p>
</div>
<div class="grid gap-6 md:grid-cols-2">
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="allow_multiple_rules" value="1" <?php checked($settings['allow_multiple_rules'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('اجازه اعمال چند قانون همزمان', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('قوانین معتبر به صورت متوالی اعمال می‌شوند.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="block text-sm font-medium text-gray-700 mb-3"><?php _e('استراتژی اعمال', 'sodino'); ?></label>
<select name="strategy" class="w-full rounded-lg border border-gray-300 bg-white px-4 py-3 text-gray-700 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-100">
<option value="highest_discount" <?php selected($settings['strategy'], 'highest_discount'); ?>><?php _e('بالاترین تخفیف', 'sodino'); ?></option>
<option value="first_valid" <?php selected($settings['strategy'], 'first_valid'); ?>><?php _e('اولین قانون معتبر', 'sodino'); ?></option>
<option value="priority" <?php selected($settings['strategy'], 'priority'); ?>><?php _e('بر اساس اولویت', 'sodino'); ?></option>
</select>
<p class="mt-3 text-sm text-gray-500"><?php _e('استراتژی انتخاب قانون زمانی که بیش از یک قانون معتبر وجود داشته باشد.', 'sodino'); ?></p>
</div>
</div>
</div>
<!-- Limits Section -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="mb-6">
<h3 class="text-lg font-semibold text-gray-900"><?php _e('محدودیت‌ها', 'sodino'); ?></h3>
<p class="mt-1 text-sm text-gray-500"><?php _e('پارامترهای محدودسازی برای حفظ حاشیه سود.', 'sodino'); ?></p>
</div>
<div class="grid gap-6 md:grid-cols-2">
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="block text-sm font-medium text-gray-700 mb-3"><?php _e('حداکثر درصد تخفیف', 'sodino'); ?></label>
<input type="number" name="max_discount_percent" value="<?php echo esc_attr($settings['max_discount_percent']); ?>" min="0" max="100" class="w-full rounded-lg border border-gray-300 bg-white px-4 py-3 text-gray-700 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-100">
<p class="mt-3 text-sm text-gray-500"><?php _e('حداکثر تخفیف مجاز برای هر محصول را تعیین می‌کند.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="block text-sm font-medium text-gray-700 mb-3"><?php _e('حداقل قیمت محصول', 'sodino'); ?></label>
<input type="number" name="min_product_price" value="<?php echo esc_attr($settings['min_product_price']); ?>" min="0" step="0.01" class="w-full rounded-lg border border-gray-300 bg-white px-4 py-3 text-gray-700 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-100">
<p class="mt-3 text-sm text-gray-500"><?php _e('از کاهش قیمت زیر این مقدار جلوگیری می‌کند.', 'sodino'); ?></p>
</div>
</div>
</div>
<!-- Features Section -->
<div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6">
<div class="mb-6">
<h3 class="text-lg font-semibold text-gray-900"><?php _e('ویژگی‌ها', 'sodino'); ?></h3>
<p class="mt-1 text-sm text-gray-500"><?php _e('گزینه‌های پیشرفته برای شخصی‌سازی رفتار درآمدی.', 'sodino'); ?></p>
</div>
<div class="grid gap-6 md:grid-cols-2">
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="ab_testing_enabled" value="1" <?php checked($settings['ab_testing_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('فعال‌سازی تست A/B', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('امکان فعال‌سازی سناریوهای آزمایشی را اضافه می‌کند.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="cart_pricing_enabled" value="1" <?php checked($settings['cart_pricing_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('اعمال قیمت‌گذاری در سبد خرید', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('در صورت خاموش بودن، قیمت‌گذاری پویا فقط در نمایش محصول انجام می‌شود.', 'sodino'); ?></p>
</div>
<div class="bg-gray-50 rounded-lg p-5 border border-gray-200">
<label class="flex items-center gap-3 text-gray-700">
<input type="checkbox" name="scheduled_campaigns_enabled" value="1" <?php checked($settings['scheduled_campaigns_enabled'], 1); ?> class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500">
<span><?php _e('فعال‌سازی کمپین‌های زمان‌بندی شده', 'sodino'); ?></span>
</label>
<p class="mt-3 text-sm text-gray-500"><?php _e('با فعال کردن، می‌توانید قوانین را به صورت زمان‌بندی‌شده اجرا کنید.', 'sodino'); ?></p>
</div>
</div>
</div>
<!-- Submit Button -->
<div class="flex justify-end">
<button type="submit" class="inline-flex items-center px-6 py-3 border border-transparent text-sm font-medium rounded-lg text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors duration-200">
<?php _e('ذخیره تنظیمات', 'sodino'); ?>
</button>
</div>
</form>
</main>
</div>
<!-- Submit Button -->
<div class="flex items-center justify-end gap-4 pt-6 border-t border-gray-200">
<button type="submit" class="inline-flex items-center px-6 py-3 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors duration-200">
<?php _e('ذخیره تنظیمات', 'sodino'); ?>
</button>
</div>
</form>
</div>
</div>
<?php
});
?>