PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.78
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.78
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / admin / layouts / woo-builder-page.php

woo-builder-page.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.78, at includes/admin/layouts/woo-builder-page.php

2,084 lines 69.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WooCommerce Builder Admin Page
4 * Clean, Premium style inspired design
5 *
6 * @package King_Addons
7 */
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 // Include shared dark theme support
14 include KING_ADDONS_PATH . 'includes/admin/shared/dark-theme.php';
15
16 $can_use_pro = king_addons_can_use_pro();
17
18 // Get WooCommerce categories and tags for conditions
19 $product_categories = get_terms([
20 'taxonomy' => 'product_cat',
21 'hide_empty' => false,
22 ]);
23 if (is_wp_error($product_categories)) {
24 $product_categories = [];
25 }
26
27 $product_tags = get_terms([
28 'taxonomy' => 'product_tag',
29 'hide_empty' => false,
30 ]);
31 if (is_wp_error($product_tags)) {
32 $product_tags = [];
33 }
34
35 // Get all products for specific product conditions
36 $products = get_posts([
37 'post_type' => 'product',
38 'posts_per_page' => 100,
39 'post_status' => 'publish',
40 'orderby' => 'title',
41 'order' => 'ASC',
42 ]);
43
44 /**
45 * Helper function to deactivate conflicting templates.
46 * Only deactivates templates with EXACTLY the same condition.
47 *
48 * @param int $current_template_id The template being activated.
49 * @param string $template_type The template type.
50 * @param array $new_conditions The new conditions being set.
51 */
52 function ka_woo_deactivate_conflicting_templates(int $current_template_id, string $template_type, array $new_conditions): void {
53 $new_condition_type = $new_conditions['rules'][0]['type'] ?? 'all';
54 $new_condition_values = $new_conditions['rules'][0]['values'] ?? [];
55
56 // Get all templates of the same type
57 $query = new WP_Query([
58 'post_type' => 'elementor_library',
59 'posts_per_page' => -1,
60 'post_status' => ['publish', 'draft'],
61 'post__not_in' => [$current_template_id],
62 'meta_query' => [
63 [
64 'key' => 'ka_woo_template_type',
65 'value' => $template_type,
66 ],
67 ],
68 ]);
69
70 foreach ($query->posts as $post) {
71 $conditions = get_post_meta($post->ID, 'ka_woo_conditions', true);
72 if (empty($conditions['enabled'])) {
73 continue;
74 }
75
76 $existing_type = $conditions['rules'][0]['type'] ?? 'all';
77 $existing_values = $conditions['rules'][0]['values'] ?? [];
78
79 // Check if conditions conflict (same type and overlapping values)
80 $should_deactivate = false;
81
82 $new_is_global = in_array($new_condition_type, ['all', 'always'], true);
83 $existing_is_global = in_array($existing_type, ['all', 'always'], true);
84
85 if ($new_is_global && $existing_is_global) {
86 // Both are "all" - conflict
87 $should_deactivate = true;
88 } elseif ($new_condition_type === $existing_type && !empty($new_condition_values) && !empty($existing_values)) {
89 // Same type with specific values - check for overlap
90 $overlap = array_intersect($new_condition_values, $existing_values);
91 if (!empty($overlap)) {
92 $should_deactivate = true;
93 }
94 }
95
96 if ($should_deactivate) {
97 $conditions['enabled'] = false;
98 update_post_meta($post->ID, 'ka_woo_conditions', $conditions);
99 }
100 }
101 }
102
103 // Handle create template action - create post and redirect to Elementor editor
104 if (!empty($_GET['ka_woo_create']) && !empty($_GET['ka_woo_template_type'])) {
105 $template_type = sanitize_key($_GET['ka_woo_template_type']);
106 $valid_types = ['single_product', 'product_archive', 'cart', 'checkout', 'my_account'];
107
108 if (in_array($template_type, $valid_types, true) && current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'ka_woo_create_' . $template_type)) {
109
110 // Check Pro restriction
111 if (!$can_use_pro && in_array($template_type, ['cart', 'checkout', 'my_account'], true)) {
112 wp_safe_redirect(remove_query_arg(['ka_woo_create', 'ka_woo_template_type', '_wpnonce']));
113 exit;
114 }
115
116 // Get type label for title
117 $type_labels = [
118 'single_product' => __('Single Product', 'king-addons'),
119 'product_archive' => __('Shop & Category', 'king-addons'),
120 'cart' => __('Cart', 'king-addons'),
121 'checkout' => __('Checkout', 'king-addons'),
122 'my_account' => __('My Account', 'king-addons'),
123 ];
124
125 // Create new post
126 $post_id = wp_insert_post([
127 'post_title' => $type_labels[$template_type] ?? __('WooCommerce Template', 'king-addons'),
128 'post_type' => 'elementor_library',
129 'post_status' => 'draft',
130 ]);
131
132 if ($post_id && !is_wp_error($post_id)) {
133 // Set template type meta
134 update_post_meta($post_id, 'ka_woo_template_type', $template_type);
135
136 // Use 'page' as Elementor template type - this ensures Elementor editor works
137 // Our custom document type may not be properly supported
138 update_post_meta($post_id, '_elementor_template_type', 'page');
139
140 // Set default conditions (enabled by default)
141 $default_rule_type = in_array($template_type, ['cart', 'checkout', 'my_account'], true) ? 'always' : 'all';
142 $default_conditions = [
143 'enabled' => true,
144 'priority' => 10,
145 'rules' => [
146 [
147 'type' => $default_rule_type,
148 'values' => [],
149 ],
150 ],
151 ];
152 update_post_meta($post_id, 'ka_woo_conditions', $default_conditions);
153
154 // Set _elementor_edit_mode so Elementor knows to use builder
155 update_post_meta($post_id, '_elementor_edit_mode', 'builder');
156
157 // Initialize empty Elementor data
158 update_post_meta($post_id, '_elementor_data', '[]');
159
160 // Redirect to Elementor editor
161 $elementor_url = add_query_arg([
162 'post' => $post_id,
163 'action' => 'elementor',
164 ], admin_url('post.php'));
165
166 wp_safe_redirect($elementor_url);
167 exit;
168 }
169 }
170 wp_safe_redirect(remove_query_arg(['ka_woo_create', 'ka_woo_template_type', '_wpnonce']));
171 exit;
172 }
173
174 // Handle toggle action
175 if (!empty($_GET['ka_woo_toggle']) && !empty($_GET['template_id'])) {
176 $template_id = (int) $_GET['template_id'];
177 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'ka_woo_toggle_' . $template_id)) {
178 $conditions = get_post_meta($template_id, 'ka_woo_conditions', true);
179 if (!is_array($conditions)) {
180 $conditions = ['enabled' => false, 'rules' => [['type' => 'all', 'values' => []]]];
181 }
182
183 $will_enable = empty($conditions['enabled']);
184 $conditions['enabled'] = $will_enable;
185 update_post_meta($template_id, 'ka_woo_conditions', $conditions);
186
187 // If enabling, deactivate conflicting templates
188 if ($will_enable) {
189 $template_type = get_post_meta($template_id, 'ka_woo_template_type', true);
190 ka_woo_deactivate_conflicting_templates($template_id, $template_type, $conditions);
191 }
192 }
193 wp_safe_redirect(remove_query_arg(['ka_woo_toggle', 'template_id', '_wpnonce']));
194 exit;
195 }
196
197 // Handle conditions update action (Pro only)
198 if (!empty($_POST['ka_woo_update_conditions']) && !empty($_POST['template_id'])) {
199 $template_id = (int) $_POST['template_id'];
200 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'] ?? '')), 'ka_woo_conditions')) {
201
202 // Only allow in Pro
203 if ($can_use_pro) {
204 $condition_type = sanitize_key($_POST['condition_type'] ?? 'all');
205 $condition_values = [];
206
207 if (!empty($_POST['condition_values']) && is_array($_POST['condition_values'])) {
208 $condition_values = array_map('intval', $_POST['condition_values']);
209 }
210
211 $template_type = (string) get_post_meta($template_id, 'ka_woo_template_type', true);
212 $allowed_types = [];
213 if ('single_product' === $template_type) {
214 $allowed_types = ['all', 'product_cat', 'product_tag', 'specific_product'];
215 } elseif ('product_archive' === $template_type) {
216 $allowed_types = ['all', 'shop', 'product_cat', 'product_tag'];
217 } elseif (in_array($template_type, ['cart', 'checkout', 'my_account'], true)) {
218 $allowed_types = ['always'];
219 }
220
221 if (!in_array($condition_type, $allowed_types, true)) {
222 $condition_type = $allowed_types[0] ?? 'all';
223 }
224
225 // If a "specific" selector is chosen but nothing selected, treat it as global.
226 if (in_array($condition_type, ['product_cat', 'product_tag', 'specific_product'], true) && empty($condition_values)) {
227 $condition_type = 'all';
228 }
229
230 $conditions = get_post_meta($template_id, 'ka_woo_conditions', true);
231 if (!is_array($conditions)) {
232 $conditions = ['enabled' => false];
233 }
234
235 $conditions['rules'] = [
236 [
237 'type' => $condition_type,
238 'values' => $condition_values,
239 ],
240 ];
241
242 update_post_meta($template_id, 'ka_woo_conditions', $conditions);
243
244 // If enabled, deactivate conflicting templates
245 if (!empty($conditions['enabled'])) {
246 $template_type = get_post_meta($template_id, 'ka_woo_template_type', true);
247 ka_woo_deactivate_conflicting_templates($template_id, $template_type, $conditions);
248 }
249 }
250 }
251 wp_safe_redirect(add_query_arg('page', 'king-addons-woo-builder', admin_url('admin.php')));
252 exit;
253 }
254
255 // Handle duplicate action
256 if (!empty($_GET['ka_woo_duplicate']) && !empty($_GET['template_id'])) {
257 $template_id = (int) $_GET['template_id'];
258 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'ka_woo_duplicate_' . $template_id)) {
259 $original_post = get_post($template_id);
260 if ($original_post && 'elementor_library' === $original_post->post_type) {
261 // Create duplicate
262 $new_post_id = wp_insert_post([
263 'post_title' => $original_post->post_title . ' ' . __('(Copy)', 'king-addons'),
264 'post_type' => 'elementor_library',
265 'post_status' => 'draft',
266 'post_content' => $original_post->post_content,
267 ]);
268
269 if ($new_post_id && !is_wp_error($new_post_id)) {
270 // Copy all meta
271 $meta = get_post_meta($template_id);
272 foreach ($meta as $key => $values) {
273 foreach ($values as $value) {
274 add_post_meta($new_post_id, $key, maybe_unserialize($value));
275 }
276 }
277 // Set as inactive by default
278 $conditions = get_post_meta($new_post_id, 'ka_woo_conditions', true);
279 if (!is_array($conditions)) {
280 $conditions = [];
281 }
282 $conditions['enabled'] = false;
283 update_post_meta($new_post_id, 'ka_woo_conditions', $conditions);
284 }
285 }
286 }
287 wp_safe_redirect(remove_query_arg(['ka_woo_duplicate', 'template_id', '_wpnonce']));
288 exit;
289 }
290
291 // Handle rename action (AJAX)
292 if (!empty($_POST['ka_woo_rename']) && !empty($_POST['template_id']) && !empty($_POST['new_title'])) {
293 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['_wpnonce'] ?? '')), 'ka_woo_rename')) {
294 $template_id = (int) $_POST['template_id'];
295 $new_title = sanitize_text_field(wp_unslash($_POST['new_title']));
296 wp_update_post([
297 'ID' => $template_id,
298 'post_title' => $new_title,
299 ]);
300 }
301 wp_safe_redirect(remove_query_arg(['ka_woo_rename', 'template_id', 'new_title', '_wpnonce']));
302 exit;
303 }
304
305 // Handle change type action
306 if (!empty($_GET['ka_woo_change_type']) && !empty($_GET['template_id']) && !empty($_GET['new_type'])) {
307 $template_id = (int) $_GET['template_id'];
308 $new_type = sanitize_key($_GET['new_type']);
309 $valid_types = ['single_product', 'product_archive', 'cart', 'checkout', 'my_account'];
310
311 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'ka_woo_change_type_' . $template_id)) {
312 if (in_array($new_type, $valid_types, true)) {
313 // Check Pro restriction for target type
314 if ($can_use_pro || !in_array($new_type, ['cart', 'checkout', 'my_account'], true)) {
315 update_post_meta($template_id, 'ka_woo_template_type', $new_type);
316 }
317 }
318 }
319 wp_safe_redirect(remove_query_arg(['ka_woo_change_type', 'template_id', 'new_type', '_wpnonce']));
320 exit;
321 }
322
323 // Handle delete action
324 if (!empty($_GET['ka_woo_delete']) && !empty($_GET['template_id'])) {
325 $template_id = (int) $_GET['template_id'];
326 if (current_user_can('manage_options') && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wpnonce'] ?? '')), 'ka_woo_delete_' . $template_id)) {
327 wp_trash_post($template_id);
328 }
329 wp_safe_redirect(remove_query_arg(['ka_woo_delete', 'template_id', '_wpnonce']));
330 exit;
331 }
332
333 // Template types
334 $types = [
335 'single_product' => [
336 'label' => esc_html__('Single Product', 'king-addons'),
337 'icon' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18"/><path d="M9 21V9"/></svg>',
338 'desc' => esc_html__('Customize product pages', 'king-addons'),
339 ],
340 'product_archive' => [
341 'label' => esc_html__('Shop & Category', 'king-addons'),
342 'icon' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg>',
343 'desc' => esc_html__('Design shop & category pages', 'king-addons'),
344 ],
345 'cart' => [
346 'label' => esc_html__('Cart', 'king-addons'),
347 'icon' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="9" cy="21" r="1"/><circle cx="20" cy="21" r="1"/><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"/></svg>',
348 'desc' => esc_html__('Custom cart layout', 'king-addons'),
349 'pro' => true,
350 ],
351 'checkout' => [
352 'label' => esc_html__('Checkout', 'king-addons'),
353 'icon' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="1" y="4" width="22" height="16" rx="2"/><line x1="1" y1="10" x2="23" y2="10"/></svg>',
354 'desc' => esc_html__('Streamlined checkout', 'king-addons'),
355 'pro' => true,
356 ],
357 'my_account' => [
358 'label' => esc_html__('My Account', 'king-addons'),
359 'icon' => '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>',
360 'desc' => esc_html__('Account dashboard', 'king-addons'),
361 'pro' => true,
362 ],
363 ];
364
365 // Create links for each type - now uses our custom handler that creates the post and redirects to Elementor
366 $create_links = [];
367 foreach ($types as $slug => $data) {
368 $create_links[$slug] = wp_nonce_url(
369 add_query_arg(
370 [
371 'page' => 'king-addons-woo-builder',
372 'ka_woo_create' => '1',
373 'ka_woo_template_type' => $slug,
374 ],
375 admin_url('admin.php')
376 ),
377 'ka_woo_create_' . $slug
378 );
379 }
380
381 // Get existing templates
382 $query = new WP_Query([
383 'post_type' => 'elementor_library',
384 'posts_per_page' => -1,
385 'post_status' => ['publish', 'draft'],
386 'meta_query' => [
387 [
388 'key' => 'ka_woo_template_type',
389 'compare' => 'EXISTS',
390 ],
391 ],
392 ]);
393
394 $templates = [];
395 foreach ($query->posts as $post) {
396 $type = get_post_meta($post->ID, 'ka_woo_template_type', true);
397 if (empty($type)) continue;
398
399 $conditions = get_post_meta($post->ID, 'ka_woo_conditions', true);
400 if (!is_array($conditions)) {
401 $conditions = ['enabled' => false, 'rules' => [['type' => 'all', 'values' => []]]];
402 }
403 $enabled = !empty($conditions['enabled']);
404 $pro_locked = (!$can_use_pro && in_array($type, ['cart', 'checkout', 'my_account'], true));
405
406 // Parse condition for display
407 $condition_type = $conditions['rules'][0]['type'] ?? 'all';
408 $condition_values = $conditions['rules'][0]['values'] ?? [];
409 $condition_label = __('All', 'king-addons');
410
411 if (in_array($condition_type, ['always'], true)) {
412 $condition_label = __('Always', 'king-addons');
413 } elseif (in_array($condition_type, ['shop', 'is_shop'], true)) {
414 $condition_label = __('Shop Page Only', 'king-addons');
415 } elseif ('all' === $condition_type) {
416 if ('single_product' === $type) {
417 $condition_label = __('All Products', 'king-addons');
418 } elseif ('product_archive' === $type) {
419 $condition_label = __('All Categories', 'king-addons');
420 } else {
421 $condition_label = __('Always', 'king-addons');
422 }
423 } elseif (!empty($condition_values)) {
424 switch ($condition_type) {
425 case 'product_cat':
426 $cat_names = [];
427 foreach ($condition_values as $cat_id) {
428 $term = get_term($cat_id, 'product_cat');
429 if ($term && !is_wp_error($term)) {
430 $cat_names[] = $term->name;
431 }
432 }
433 $condition_label = !empty($cat_names) ? implode(', ', $cat_names) : __('Categories', 'king-addons');
434 break;
435 case 'product_tag':
436 $tag_names = [];
437 foreach ($condition_values as $tag_id) {
438 $term = get_term($tag_id, 'product_tag');
439 if ($term && !is_wp_error($term)) {
440 $tag_names[] = $term->name;
441 }
442 }
443 $condition_label = !empty($tag_names) ? implode(', ', $tag_names) : __('Tags', 'king-addons');
444 break;
445 case 'specific_product':
446 $product_titles = [];
447 foreach ($condition_values as $product_id) {
448 $product_titles[] = get_the_title($product_id);
449 }
450 $condition_label = !empty($product_titles) ? implode(', ', $product_titles) : __('Specific Products', 'king-addons');
451 break;
452 }
453 }
454
455 $templates[] = [
456 'id' => $post->ID,
457 'title' => get_the_title($post),
458 'type' => $type,
459 'enabled' => $enabled,
460 'status' => $post->post_status,
461 'date' => get_the_modified_date('M j, Y', $post),
462 'pro_locked' => $pro_locked,
463 'condition_type' => $condition_type,
464 'condition_values' => $condition_values,
465 'condition_label' => $condition_label,
466 ];
467 }
468
469 // Condition options based on template type
470 $condition_options = [
471 'single_product' => [
472 'all' => __('All Products', 'king-addons'),
473 'product_cat' => __('Specific Categories', 'king-addons'),
474 'product_tag' => __('Specific Tags', 'king-addons'),
475 'specific_product' => __('Specific Products', 'king-addons'),
476 ],
477 'product_archive' => [
478 'all' => __('All Categories', 'king-addons'),
479 'shop' => __('Shop Page Only', 'king-addons'),
480 'product_cat' => __('Specific Categories (or Archives)', 'king-addons'),
481 'product_tag' => __('Specific Tags', 'king-addons'),
482 ],
483 'cart' => [
484 'always' => __('Always', 'king-addons'),
485 ],
486 'checkout' => [
487 'always' => __('Always', 'king-addons'),
488 ],
489 'my_account' => [
490 'always' => __('Always', 'king-addons'),
491 ],
492 ];
493
494 // Get Elementor edit URL
495 if (!function_exists('ka_woo_get_elementor_edit_url')) {
496 function ka_woo_get_elementor_edit_url(int $post_id): string {
497 return add_query_arg(['post' => $post_id, 'action' => 'elementor'], admin_url('post.php'));
498 }
499 }
500 ?>
501 <style>
502 /* ================================================
503 WooCommerce Builder - Pro Design
504 ================================================ */
505
506 :root {
507 --ka-wb-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", system-ui, sans-serif;
508 --ka-wb-bg: #f5f5f7;
509 --ka-wb-surface: #ffffff;
510 --ka-wb-text: #1d1d1f;
511 --ka-wb-text-secondary: #86868b;
512 --ka-wb-border: rgba(0, 0, 0, 0.06);
513 --ka-wb-accent: #0071e3;
514 --ka-wb-accent-hover: #0077ed;
515 --ka-wb-success: #34c759;
516 --ka-wb-warning: #ff9500;
517 --ka-wb-radius: 20px;
518 --ka-wb-radius-sm: 12px;
519 --ka-wb-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
520 --ka-wb-shadow-hover: 0 8px 32px rgba(0, 0, 0, 0.1);
521 --ka-wb-transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
522 }
523
524 body.ka-v3-dark {
525 --ka-wb-bg: #000000;
526 --ka-wb-surface: #1c1c1e;
527 --ka-wb-text: #f5f5f7;
528 --ka-wb-text-secondary: #98989d;
529 --ka-wb-border: rgba(255, 255, 255, 0.1);
530 --ka-wb-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
531 --ka-wb-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.4);
532 }
533
534 body.king-addons_page_king-addons-woo-builder #wpcontent,
535 body.king-addons_page_king-addons-woo-builder #wpbody,
536 body.king-addons_page_king-addons-woo-builder #wpbody-content {
537 background: var(--ka-wb-bg) !important;
538 padding: 0 !important;
539 }
540
541 .ka-wb {
542 font-family: var(--ka-wb-font);
543 max-width: 1100px;
544 margin: 0 auto;
545 padding: 48px 40px 80px;
546 color: var(--ka-wb-text);
547 -webkit-font-smoothing: antialiased;
548 }
549
550 .ka-wb * { box-sizing: border-box; }
551
552 /* Header */
553 .ka-wb-header {
554 display: flex;
555 justify-content: space-between;
556 align-items: flex-start;
557 margin-bottom: 56px;
558 }
559
560 .ka-wb-header-content {
561 display: flex;
562 align-items: flex-start;
563 gap: 16px;
564 }
565
566 .ka-wb-header-titles {
567 display: flex;
568 flex-direction: column;
569 gap: 8px;
570 min-width: 0;
571 }
572
573 .ka-wb-header-titles h1 {
574 font-size: 56px;
575 font-weight: 700;
576 letter-spacing: -0.025em;
577 margin: 0;
578 line-height: 1;
579 }
580
581 .ka-wb-header-titles p {
582 font-size: 21px;
583 color: var(--ka-wb-text-secondary);
584 margin: 0;
585 font-weight: 400;
586 }
587
588 .ka-wb-title-icon {
589 width: 76px;
590 height: 76px;
591 display: inline-flex;
592 align-items: center;
593 justify-content: center;
594 border-radius: 22px;
595 background: rgba(0, 113, 227, 0.12);
596 color: var(--ka-wb-accent);
597 flex: 0 0 auto;
598 }
599 body.ka-v3-dark .ka-wb-title-icon {
600 background: rgba(10, 132, 255, 0.18);
601 color: #0a84ff;
602 }
603 .ka-wb-title-icon svg { width: 36px; height: 36px; }
604
605 .ka-wb-title-text {
606 background: linear-gradient(135deg, var(--ka-wb-text) 0%, var(--ka-wb-text-secondary) 100%);
607 -webkit-background-clip: text;
608 -webkit-text-fill-color: transparent;
609 background-clip: text;
610 }
611
612 .ka-wb-header-content p {
613 font-size: 21px;
614 color: var(--ka-wb-text-secondary);
615 margin: 0;
616 font-weight: 400;
617 }
618
619 .ka-wb-header-actions {
620 display: flex;
621 align-items: center;
622 gap: 12px;
623 }
624
625 /* Template Types Grid */
626 .ka-wb-types {
627 display: grid;
628 grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
629 gap: 16px;
630 margin-bottom: 64px;
631 }
632
633 .ka-wb-type {
634 position: relative;
635 display: flex;
636 flex-direction: column;
637 align-items: center;
638 padding: 32px 20px;
639 background: var(--ka-wb-surface);
640 border: 1px solid var(--ka-wb-border);
641 border-radius: var(--ka-wb-radius);
642 text-decoration: none;
643 color: var(--ka-wb-text);
644 transition: var(--ka-wb-transition);
645 cursor: pointer;
646 overflow: hidden;
647 }
648
649 .ka-wb-type:hover {
650 transform: translateY(-4px);
651 box-shadow: var(--ka-wb-shadow-hover);
652 border-color: var(--ka-wb-accent);
653 }
654
655 .ka-wb-type:hover .ka-wb-type-icon {
656 transform: scale(1.1);
657 color: var(--ka-wb-accent);
658 }
659
660 .ka-wb-type.is-locked {
661 opacity: 0.6;
662 cursor: not-allowed;
663 }
664
665 .ka-wb-type.is-locked:hover {
666 transform: none;
667 box-shadow: none;
668 border-color: var(--ka-wb-border);
669 }
670
671 .ka-wb-type.is-locked .ka-wb-type-icon {
672 transform: none;
673 color: var(--ka-wb-text-secondary);
674 }
675
676 .ka-wb-type-icon {
677 width: 48px;
678 height: 48px;
679 margin-bottom: 16px;
680 color: var(--ka-wb-text-secondary);
681 transition: var(--ka-wb-transition);
682 }
683
684 .ka-wb-type-icon svg {
685 width: 100%;
686 height: 100%;
687 }
688
689 .ka-wb-type-label {
690 font-size: 17px;
691 font-weight: 600;
692 margin-bottom: 4px;
693 text-align: center;
694 }
695
696 .ka-wb-type-desc {
697 font-size: 13px;
698 color: var(--ka-wb-text-secondary);
699 text-align: center;
700 }
701
702 .ka-wb-type-badge {
703 position: absolute;
704 top: 12px;
705 right: 12px;
706 padding: 4px 10px;
707 font-size: 11px;
708 font-weight: 600;
709 background: linear-gradient(135deg, #0071e3, #5856d6);
710 color: #fff;
711 border-radius: 20px;
712 text-transform: uppercase;
713 letter-spacing: 0.5px;
714 }
715
716 /* Section */
717 .ka-wb-section {
718 margin-bottom: 48px;
719 }
720
721 .ka-wb-section-header {
722 display: flex;
723 justify-content: space-between;
724 align-items: center;
725 margin-bottom: 24px;
726 }
727
728 .ka-wb-section-title {
729 font-size: 28px;
730 font-weight: 600;
731 letter-spacing: -0.01em;
732 margin: 0;
733 }
734
735 .ka-wb-section-count {
736 font-size: 15px;
737 color: var(--ka-wb-text-secondary);
738 background: var(--ka-wb-surface);
739 padding: 6px 14px;
740 border-radius: 20px;
741 border: 1px solid var(--ka-wb-border);
742 }
743
744 /* Templates List */
745 .ka-wb-templates {
746 background: var(--ka-wb-surface);
747 border-radius: var(--ka-wb-radius);
748 border: 1px solid var(--ka-wb-border);
749 }
750
751 .ka-wb-template {
752 display: grid;
753 grid-template-columns: auto 1fr auto auto;
754 align-items: center;
755 gap: 20px;
756 padding: 20px 24px;
757 border-bottom: 1px solid var(--ka-wb-border);
758 transition: var(--ka-wb-transition);
759 }
760
761 .ka-wb-template:last-child {
762 border-bottom: none;
763 }
764
765 .ka-wb-template:hover {
766 background: rgba(0, 113, 227, 0.03);
767 }
768
769 body.ka-v3-dark .ka-wb-template:hover {
770 background: rgba(255, 255, 255, 0.03);
771 }
772
773 .ka-wb-template-info {
774 display: flex;
775 flex-direction: column;
776 gap: 4px;
777 min-width: 0;
778 }
779
780 .ka-wb-template-title {
781 font-size: 16px;
782 font-weight: 500;
783 color: var(--ka-wb-text);
784 text-decoration: none;
785 display: inline-flex;
786 align-items: center;
787 gap: 8px;
788 min-width: 0;
789 transition: var(--ka-wb-transition);
790 }
791
792 .ka-wb-template-title-icon {
793 width: 18px;
794 height: 18px;
795 display: inline-flex;
796 align-items: center;
797 justify-content: center;
798 color: var(--ka-wb-text-secondary);
799 flex: 0 0 auto;
800 }
801 .ka-wb-template-title-icon svg { width: 18px; height: 18px; }
802 .ka-wb-template-title-text {
803 min-width: 0;
804 white-space: nowrap;
805 overflow: hidden;
806 text-overflow: ellipsis;
807 }
808
809 .ka-wb-template-title:hover {
810 color: var(--ka-wb-accent);
811 }
812
813 .ka-wb-template-meta {
814 display: flex;
815 align-items: center;
816 gap: 12px;
817 font-size: 13px;
818 color: var(--ka-wb-text-secondary);
819 }
820
821 .ka-wb-template-type {
822 display: inline-flex;
823 align-items: center;
824 gap: 6px;
825 }
826
827 .ka-wb-template-type::before {
828 content: '';
829 width: 6px;
830 height: 6px;
831 background: var(--ka-wb-accent);
832 border-radius: 50%;
833 }
834
835 .ka-wb-template-status {
836 display: inline-flex;
837 align-items: center;
838 padding: 6px 14px;
839 font-size: 13px;
840 font-weight: 600;
841 border-radius: 8px;
842 white-space: nowrap;
843 min-width: 80px;
844 justify-content: center;
845 justify-self: start;
846 }
847
848 .ka-wb-template-status.is-enabled {
849 background: rgba(52, 199, 89, 0.15);
850 color: #30d158;
851 }
852
853 .ka-wb-template-status.is-disabled {
854 background: rgba(255, 149, 0, 0.15);
855 color: #ff9f0a;
856 }
857
858 .ka-wb-template-status.is-draft {
859 background: var(--ka-wb-border);
860 color: var(--ka-wb-text-secondary);
861 }
862
863 /* Condition Badge */
864 .ka-wb-template-condition {
865 display: inline-flex;
866 align-items: center;
867 gap: 8px;
868 padding: 10px 18px;
869 min-height: 40px;
870 font-size: 14px;
871 font-weight: 500;
872 border-radius: 980px;
873 background: rgba(0, 113, 227, 0.1);
874 color: var(--ka-wb-accent);
875 max-width: 240px;
876 overflow: hidden;
877 text-overflow: ellipsis;
878 white-space: nowrap;
879 border: none;
880 cursor: pointer;
881 transition: var(--ka-wb-transition);
882 }
883
884 .ka-wb-template-condition:hover {
885 background: rgba(0, 113, 227, 0.18);
886 }
887
888 .ka-wb-template-condition svg {
889 width: 18px;
890 height: 18px;
891 flex-shrink: 0;
892 opacity: 0.7;
893 }
894
895 .ka-wb-template-condition.is-pro-locked {
896 opacity: 0.5;
897 cursor: not-allowed;
898 }
899
900 .ka-wb-template-condition-btn {
901 background: rgba(0, 113, 227, 0.06);
902 border: 1px solid rgba(0, 113, 227, 0.18);
903 color: var(--ka-wb-accent);
904 }
905
906 .ka-wb-template-condition-btn:hover {
907 border-color: rgba(0, 113, 227, 0.32);
908 color: var(--ka-wb-accent);
909 background: rgba(0, 113, 227, 0.10);
910 }
911
912 .ka-wb-template-actions {
913 display: flex;
914 align-items: center;
915 gap: 12px;
916 }
917
918 .ka-wb-btn {
919 display: inline-flex;
920 align-items: center;
921 justify-content: center;
922 gap: 6px;
923 padding: 10px 18px;
924 font-size: 14px;
925 font-weight: 500;
926 text-decoration: none;
927 border-radius: 980px;
928 border: none;
929 cursor: pointer;
930 transition: var(--ka-wb-transition);
931 white-space: nowrap;
932 font-family: inherit;
933 }
934
935 .ka-wb-btn-primary {
936 background: var(--ka-wb-accent);
937 color: #fff;
938 }
939
940 .ka-wb-btn-primary:visited {
941 color: #fff;
942 }
943
944 .ka-wb-btn-primary:hover {
945 background: var(--ka-wb-accent-hover);
946 color: #fff;
947 transform: scale(1.02);
948 }
949
950 .ka-wb-btn-secondary {
951 background: rgba(0, 0, 0, 0.04);
952 color: var(--ka-wb-text);
953 }
954
955 body.ka-v3-dark .ka-wb-btn-secondary {
956 background: rgba(255, 255, 255, 0.08);
957 }
958
959 .ka-wb-btn-secondary:hover {
960 background: rgba(0, 0, 0, 0.08);
961 color: var(--ka-wb-text);
962 }
963
964 body.ka-v3-dark .ka-wb-btn-secondary:hover {
965 background: rgba(255, 255, 255, 0.12);
966 }
967
968 .ka-wb-btn-ghost {
969 background: transparent;
970 color: var(--ka-wb-accent);
971 padding: 10px 12px;
972 }
973
974 .ka-wb-btn-ghost:hover {
975 background: rgba(0, 113, 227, 0.08);
976 }
977
978 .ka-wb-btn-danger {
979 color: #ff3b30;
980 }
981
982 .ka-wb-btn-danger:hover {
983 background: rgba(255, 59, 48, 0.08);
984 }
985
986 .ka-wb-btn svg {
987 width: 16px;
988 height: 16px;
989 }
990
991 /* Dropdown Menu */
992 .ka-wb-dropdown {
993 position: relative;
994 }
995
996 .ka-wb-dropdown-trigger {
997 display: flex;
998 align-items: center;
999 justify-content: center;
1000 width: 40px;
1001 height: 40px;
1002 border-radius: 10px;
1003 background: transparent;
1004 border: 1px solid transparent;
1005 cursor: pointer;
1006 transition: var(--ka-wb-transition);
1007 color: var(--ka-wb-text-secondary);
1008 }
1009
1010 .ka-wb-dropdown-trigger:hover {
1011 background: var(--ka-wb-surface);
1012 border-color: var(--ka-wb-border);
1013 color: var(--ka-wb-text);
1014 }
1015
1016 .ka-wb-dropdown-trigger svg {
1017 width: 20px;
1018 height: 20px;
1019 }
1020
1021 .ka-wb-dropdown-menu {
1022 position: absolute;
1023 top: 100%;
1024 right: 0;
1025 z-index: 100;
1026 min-width: 200px;
1027 padding: 8px 0;
1028 background: var(--ka-wb-surface);
1029 border: 1px solid var(--ka-wb-border);
1030 border-radius: var(--ka-wb-radius-sm);
1031 box-shadow: var(--ka-wb-shadow-hover);
1032 opacity: 0;
1033 visibility: hidden;
1034 transform: translateY(-8px);
1035 transition: var(--ka-wb-transition);
1036 }
1037
1038 .ka-wb-dropdown.is-open .ka-wb-dropdown-menu {
1039 opacity: 1;
1040 visibility: visible;
1041 transform: translateY(4px);
1042 }
1043
1044 .ka-wb-dropdown-item {
1045 display: flex;
1046 align-items: center;
1047 gap: 10px;
1048 padding: 10px 16px;
1049 font-size: 14px;
1050 color: var(--ka-wb-text);
1051 text-decoration: none;
1052 cursor: pointer;
1053 transition: var(--ka-wb-transition);
1054 border: none;
1055 background: none;
1056 width: 100%;
1057 text-align: left;
1058 font-family: inherit;
1059 }
1060
1061 .ka-wb-dropdown-item:hover {
1062 background: var(--ka-wb-border);
1063 }
1064
1065 .ka-wb-dropdown-item svg {
1066 width: 16px;
1067 height: 16px;
1068 color: var(--ka-wb-text-secondary);
1069 flex-shrink: 0;
1070 }
1071
1072 .ka-wb-dropdown-item.is-danger {
1073 color: #ff3b30;
1074 }
1075
1076 .ka-wb-dropdown-item.is-danger svg {
1077 color: #ff3b30;
1078 }
1079
1080 .ka-wb-dropdown-divider {
1081 height: 1px;
1082 margin: 8px 0;
1083 background: var(--ka-wb-border);
1084 }
1085
1086 .ka-wb-dropdown-label {
1087 padding: 8px 16px 4px;
1088 font-size: 11px;
1089 font-weight: 600;
1090 color: var(--ka-wb-text-secondary);
1091 text-transform: uppercase;
1092 letter-spacing: 0.5px;
1093 }
1094
1095 /* Modal */
1096 .ka-wb-modal-overlay {
1097 position: fixed;
1098 top: 0;
1099 left: 0;
1100 right: 0;
1101 bottom: 0;
1102 z-index: 100000;
1103 background: rgba(0, 0, 0, 0.5);
1104 display: flex;
1105 align-items: center;
1106 justify-content: center;
1107 opacity: 0;
1108 visibility: hidden;
1109 transition: var(--ka-wb-transition);
1110 padding: 20px;
1111 }
1112
1113 .ka-wb-modal-overlay.is-open {
1114 opacity: 1;
1115 visibility: visible;
1116 }
1117
1118 .ka-wb-modal {
1119 width: 100%;
1120 max-width: 420px;
1121 padding: 36px;
1122 background: var(--ka-wb-surface);
1123 border-radius: var(--ka-wb-radius);
1124 box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
1125 transform: scale(0.95) translateY(10px);
1126 transition: var(--ka-wb-transition);
1127 }
1128
1129 body.ka-v3-dark .ka-wb-modal {
1130 border: 1px solid var(--ka-wb-border);
1131 }
1132
1133 .ka-wb-modal-overlay.is-open .ka-wb-modal {
1134 transform: scale(1) translateY(0);
1135 }
1136
1137 .ka-wb-modal h3 {
1138 font-size: 24px;
1139 font-weight: 600;
1140 margin: 0 0 8px;
1141 color: var(--ka-wb-text);
1142 letter-spacing: -0.02em;
1143 }
1144
1145 .ka-wb-modal-input {
1146 width: 100%;
1147 padding: 14px 18px;
1148 font-size: 16px;
1149 font-family: inherit;
1150 border: 1px solid var(--ka-wb-border);
1151 border-radius: var(--ka-wb-radius-sm);
1152 background: var(--ka-wb-surface);
1153 color: var(--ka-wb-text);
1154 transition: var(--ka-wb-transition);
1155 }
1156
1157 body.ka-v3-dark .ka-wb-modal-input {
1158 background: rgba(255, 255, 255, 0.06);
1159 }
1160
1161 .ka-wb-modal-input:focus {
1162 outline: none;
1163 border-color: var(--ka-wb-accent);
1164 box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
1165 }
1166 .ka-wb-modal-actions {
1167 display: flex;
1168 gap: 12px;
1169 margin-top: 28px;
1170 justify-content: flex-end;
1171 }
1172
1173 /* Conditions Modal */
1174 .ka-wb-modal.ka-wb-modal-conditions {
1175 max-width: 480px;
1176 }
1177
1178 .ka-wb-modal-desc {
1179 font-size: 15px;
1180 color: var(--ka-wb-text-secondary);
1181 margin: -8px 0 28px;
1182 line-height: 1.5;
1183 }
1184
1185 .ka-wb-form-group {
1186 margin-bottom: 24px;
1187 }
1188
1189 .ka-wb-form-group:last-of-type {
1190 margin-bottom: 0;
1191 }
1192
1193 .ka-wb-form-label {
1194 display: block;
1195 font-size: 13px;
1196 font-weight: 600;
1197 color: var(--ka-wb-text-secondary);
1198 margin-bottom: 10px;
1199 text-transform: uppercase;
1200 letter-spacing: 0.5px;
1201 }
1202
1203 .ka-wb-form-select {
1204 width: 100%;
1205 padding: 14px 18px;
1206 font-size: 16px;
1207 font-family: inherit;
1208 border: 1px solid var(--ka-wb-border);
1209 border-radius: var(--ka-wb-radius-sm);
1210 background: var(--ka-wb-surface);
1211 color: var(--ka-wb-text);
1212 transition: var(--ka-wb-transition);
1213 cursor: pointer;
1214 appearance: none;
1215 background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2386868b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
1216 background-repeat: no-repeat;
1217 background-position: right 16px center;
1218 }
1219
1220 body.ka-v3-dark .ka-wb-form-select {
1221 background-color: rgba(255, 255, 255, 0.06);
1222 }
1223
1224 .ka-wb-form-select:focus {
1225 outline: none;
1226 border-color: var(--ka-wb-accent);
1227 box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.12);
1228 }
1229
1230 .ka-wb-checkbox-list {
1231 max-height: 220px;
1232 overflow-y: auto;
1233 border: 1px solid var(--ka-wb-border);
1234 border-radius: var(--ka-wb-radius-sm);
1235 padding: 8px;
1236 background: var(--ka-wb-surface);
1237 }
1238
1239 body.ka-v3-dark .ka-wb-checkbox-list {
1240 background: rgba(255, 255, 255, 0.04);
1241 }
1242
1243 .ka-wb-checkbox-item {
1244 display: flex;
1245 align-items: center;
1246 gap: 12px;
1247 padding: 10px 14px;
1248 border-radius: 8px;
1249 cursor: pointer;
1250 transition: var(--ka-wb-transition);
1251 }
1252
1253 .ka-wb-checkbox-item:hover {
1254 background: rgba(0, 113, 227, 0.06);
1255 }
1256
1257 .ka-wb-checkbox-item input[type="checkbox"] {
1258 width: 20px;
1259 height: 20px;
1260 accent-color: var(--ka-wb-accent);
1261 cursor: pointer;
1262 border-radius: 4px;
1263 }
1264
1265 .ka-wb-checkbox-item span {
1266 font-size: 15px;
1267 color: var(--ka-wb-text);
1268 }
1269
1270 .ka-wb-pro-badge-inline {
1271 display: inline-flex;
1272 align-items: center;
1273 gap: 4px;
1274 padding: 2px 8px;
1275 font-size: 10px;
1276 font-weight: 600;
1277 background: linear-gradient(135deg, #0071e3, #5856d6);
1278 color: #fff;
1279 border-radius: 12px;
1280 text-transform: uppercase;
1281 letter-spacing: 0.5px;
1282 margin-left: 8px;
1283 }
1284
1285 .ka-wb-modal-locked {
1286 position: static;
1287 }
1288
1289 .ka-wb-modal-locked::after {
1290 content: '';
1291 position: absolute;
1292 top: 0;
1293 left: 0;
1294 right: 0;
1295 bottom: 0;
1296 background: rgba(var(--ka-wb-surface), 0.8);
1297 backdrop-filter: blur(3px);
1298 z-index: 1;
1299 }
1300
1301 .ka-wb-modal-locked-overlay {
1302 position: absolute;
1303 top: 50%;
1304 left: 50%;
1305 transform: translate(-50%, -50%);
1306 z-index: 2;
1307 text-align: center;
1308 padding: 24px;
1309 }
1310
1311 .ka-wb-modal-locked-overlay svg {
1312 width: 48px;
1313 height: 48px;
1314 color: var(--ka-wb-accent);
1315 margin-bottom: 12px;
1316 }
1317
1318 .ka-wb-modal-locked-overlay h4 {
1319 font-size: 18px;
1320 font-weight: 600;
1321 margin: 0 0 8px;
1322 color: var(--ka-wb-text);
1323 }
1324
1325 .ka-wb-modal-locked-overlay p {
1326 font-size: 14px;
1327 color: var(--ka-wb-text-secondary);
1328 margin: 0 0 16px;
1329 }
1330
1331 /* Empty State */
1332 .ka-wb-empty {
1333 text-align: center;
1334 padding: 64px 40px;
1335 }
1336
1337 .ka-wb-empty-icon {
1338 width: 64px;
1339 height: 64px;
1340 margin: 0 auto 20px;
1341 color: var(--ka-wb-text-secondary);
1342 opacity: 0.4;
1343 }
1344
1345 .ka-wb-empty-icon svg {
1346 width: 100%;
1347 height: 100%;
1348 }
1349
1350 .ka-wb-empty h3 {
1351 font-size: 20px;
1352 font-weight: 600;
1353 margin: 0 0 8px;
1354 color: var(--ka-wb-text);
1355 }
1356
1357 .ka-wb-empty p {
1358 font-size: 15px;
1359 color: var(--ka-wb-text-secondary);
1360 margin: 0;
1361 }
1362
1363 /* Quick Start */
1364 .ka-wb-quickstart {
1365 padding: 24px 28px;
1366 background: var(--ka-wb-surface);
1367 border: 1px solid var(--ka-wb-border);
1368 border-radius: var(--ka-wb-radius);
1369 box-shadow: var(--ka-wb-shadow);
1370 margin-bottom: 32px;
1371 }
1372
1373 .ka-wb-quickstart-head {
1374 display: flex;
1375 align-items: baseline;
1376 justify-content: space-between;
1377 gap: 16px;
1378 margin-bottom: 18px;
1379 }
1380
1381 .ka-wb-quickstart-head h3 {
1382 font-size: 16px;
1383 font-weight: 600;
1384 margin: 0;
1385 color: var(--ka-wb-text);
1386 }
1387
1388 .ka-wb-quickstart-head p {
1389 font-size: 13px;
1390 margin: 0;
1391 color: var(--ka-wb-text-secondary);
1392 white-space: nowrap;
1393 }
1394
1395 .ka-wb-quickstart-steps {
1396 display: grid;
1397 grid-template-columns: repeat(3, 1fr);
1398 gap: 14px;
1399 }
1400
1401 .ka-wb-quickstart-step {
1402 display: flex;
1403 gap: 12px;
1404 padding: 14px 16px;
1405 border-radius: var(--ka-wb-radius-sm);
1406 background: rgba(0, 0, 0, 0.02);
1407 border: 1px solid var(--ka-wb-border);
1408 }
1409
1410 body.ka-v3-dark .ka-wb-quickstart-step {
1411 background: rgba(255, 255, 255, 0.04);
1412 }
1413
1414 .ka-wb-quickstart-step-number {
1415 width: 28px;
1416 height: 28px;
1417 border-radius: 10px;
1418 display: inline-flex;
1419 align-items: center;
1420 justify-content: center;
1421 font-size: 13px;
1422 font-weight: 700;
1423 color: #fff;
1424 background: linear-gradient(135deg, var(--ka-wb-accent), var(--ka-wb-accent-hover));
1425 flex-shrink: 0;
1426 }
1427
1428 .ka-wb-quickstart-step-title {
1429 font-size: 14px;
1430 font-weight: 600;
1431 margin: 0 0 3px;
1432 color: var(--ka-wb-text);
1433 }
1434
1435 .ka-wb-quickstart-step-desc {
1436 font-size: 13px;
1437 margin: 0;
1438 color: var(--ka-wb-text-secondary);
1439 line-height: 1.35;
1440 }
1441
1442 /* Pro Notice */
1443 .ka-wb-pro-notice {
1444 display: flex;
1445 align-items: center;
1446 justify-content: space-between;
1447 gap: 24px;
1448 padding: 24px 28px;
1449 background: linear-gradient(135deg, rgba(0, 113, 227, 0.08), rgba(88, 86, 214, 0.08));
1450 border: 1px solid rgba(0, 113, 227, 0.15);
1451 border-radius: var(--ka-wb-radius);
1452 margin-bottom: 32px;
1453 }
1454
1455 body.ka-v3-dark .ka-wb-pro-notice {
1456 background: linear-gradient(135deg, rgba(0, 113, 227, 0.12), rgba(88, 86, 214, 0.12));
1457 border-color: rgba(0, 113, 227, 0.2);
1458 }
1459
1460 .ka-wb-pro-notice-content {
1461 display: flex;
1462 align-items: center;
1463 gap: 16px;
1464 }
1465
1466 .ka-wb-pro-notice-icon {
1467 width: 40px;
1468 height: 40px;
1469 background: linear-gradient(135deg, #0071e3, #5856d6);
1470 border-radius: 10px;
1471 display: flex;
1472 align-items: center;
1473 justify-content: center;
1474 color: #fff;
1475 flex-shrink: 0;
1476 }
1477
1478 .ka-wb-pro-notice-icon svg {
1479 width: 22px;
1480 height: 22px;
1481 }
1482
1483 .ka-wb-pro-notice-text h4 {
1484 font-size: 15px;
1485 font-weight: 600;
1486 margin: 0 0 2px;
1487 color: var(--ka-wb-text);
1488 }
1489
1490 .ka-wb-pro-notice-text p {
1491 font-size: 14px;
1492 color: var(--ka-wb-text-secondary);
1493 margin: 0;
1494 }
1495
1496 /* Responsive */
1497 @media (max-width: 768px) {
1498 .ka-wb {
1499 padding: 32px 20px 60px;
1500 }
1501
1502 .ka-wb-header {
1503 flex-direction: column;
1504 gap: 24px;
1505 }
1506
1507 .ka-wb-header-titles h1 {
1508 font-size: 36px;
1509 }
1510
1511 .ka-wb-title-icon {
1512 width: 64px;
1513 height: 64px;
1514 border-radius: 18px;
1515 }
1516
1517 .ka-wb-title-icon svg {
1518 width: 30px;
1519 height: 30px;
1520 }
1521
1522 .ka-wb-types {
1523 grid-template-columns: 1fr 1fr;
1524 }
1525
1526 .ka-wb-template {
1527 grid-template-columns: 1fr;
1528 gap: 16px;
1529 }
1530
1531 .ka-wb-template-actions {
1532 justify-content: flex-start;
1533 }
1534
1535 .ka-wb-pro-notice {
1536 flex-direction: column;
1537 text-align: center;
1538 }
1539
1540 .ka-wb-pro-notice-content {
1541 flex-direction: column;
1542 }
1543
1544 .ka-wb-quickstart {
1545 padding: 20px 20px;
1546 }
1547
1548 .ka-wb-quickstart-head {
1549 flex-direction: column;
1550 align-items: flex-start;
1551 gap: 6px;
1552 }
1553
1554 .ka-wb-quickstart-steps {
1555 grid-template-columns: 1fr;
1556 }
1557 }
1558 </style>
1559
1560 <?php
1561 ka_render_dark_theme_styles();
1562 ka_render_dark_theme_init();
1563 ?>
1564
1565 <script>
1566 if (document.body) {
1567 document.body.classList.add('ka-admin-v3');
1568 } else {
1569 document.addEventListener('DOMContentLoaded', function() {
1570 document.body.classList.add('ka-admin-v3');
1571 });
1572 }
1573 </script>
1574
1575 <div class="ka-wb">
1576 <!-- Header -->
1577 <header class="ka-wb-header">
1578 <div class="ka-wb-header-content">
1579 <span class="ka-wb-title-icon" aria-hidden="true">
1580 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1581 <path d="M6 6h15l-1.5 9h-12z" />
1582 <path d="M6 6l-2-3H1" />
1583 <circle cx="9" cy="20" r="1" />
1584 <circle cx="18" cy="20" r="1" />
1585 </svg>
1586 </span>
1587 <div class="ka-wb-header-titles">
1588 <h1><span class="ka-wb-title-text"><?php esc_html_e('WooCommerce Builder', 'king-addons'); ?></span></h1>
1589 <p><?php esc_html_e('Design beautiful store pages with Elementor', 'king-addons'); ?></p>
1590 </div>
1591 </div>
1592 <div class="ka-wb-header-actions">
1593 <?php ka_render_dark_theme_toggle(); ?>
1594 </div>
1595 </header>
1596
1597 <?php if (!$can_use_pro): ?>
1598 <!-- Pro Notice -->
1599 <div class="ka-wb-pro-notice">
1600 <div class="ka-wb-pro-notice-content">
1601 <div class="ka-wb-pro-notice-icon">
1602 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1603 <polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>
1604 </svg>
1605 </div>
1606 <div class="ka-wb-pro-notice-text">
1607 <h4><?php esc_html_e('Unlock All Templates', 'king-addons'); ?></h4>
1608 <p><?php esc_html_e('Cart, Checkout, and My Account templates require Pro', 'king-addons'); ?></p>
1609 </div>
1610 </div>
1611 <a href="https://kingaddons.com/pricing/" target="_blank" class="ka-wb-btn ka-wb-btn-primary">
1612 <?php esc_html_e('Upgrade to Pro', 'king-addons'); ?>
1613 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1614 <path d="M5 12h14M12 5l7 7-7 7"/>
1615 </svg>
1616 </a>
1617 </div>
1618 <?php endif; ?>
1619
1620 <!-- Template Types -->
1621 <div class="ka-wb-types">
1622 <?php foreach ($types as $slug => $data): ?>
1623 <?php
1624 $is_locked = (!$can_use_pro && !empty($data['pro']));
1625 $tag = $is_locked ? 'div' : 'a';
1626 $href = $is_locked ? '' : ' href="' . esc_url($create_links[$slug]) . '"';
1627 ?>
1628 <<?php echo $tag; ?> class="ka-wb-type <?php echo $is_locked ? 'is-locked' : ''; ?>"<?php echo $href; ?>>
1629 <?php if ($is_locked && !empty($data['pro'])): ?>
1630 <span class="ka-wb-type-badge">Pro</span>
1631 <?php endif; ?>
1632 <div class="ka-wb-type-icon"><?php echo $data['icon']; ?></div>
1633 <div class="ka-wb-type-label"><?php echo esc_html($data['label']); ?></div>
1634 <div class="ka-wb-type-desc"><?php echo esc_html($data['desc']); ?></div>
1635 </<?php echo $tag; ?>>
1636 <?php endforeach; ?>
1637 </div>
1638
1639 <!-- Templates Section -->
1640 <section class="ka-wb-section">
1641 <div class="ka-wb-section-header">
1642 <h2 class="ka-wb-section-title"><?php esc_html_e('Your Templates', 'king-addons'); ?></h2>
1643 <span class="ka-wb-section-count"><?php echo count($templates); ?> <?php esc_html_e('templates', 'king-addons'); ?></span>
1644 </div>
1645
1646 <div class="ka-wb-templates">
1647 <?php if (empty($templates)): ?>
1648 <div class="ka-wb-empty">
1649 <div class="ka-wb-empty-icon">
1650 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
1651 <rect x="3" y="3" width="18" height="18" rx="2"/>
1652 <line x1="12" y1="8" x2="12" y2="16"/>
1653 <line x1="8" y1="12" x2="16" y2="12"/>
1654 </svg>
1655 </div>
1656 <h3><?php esc_html_e('No templates yet', 'king-addons'); ?></h3>
1657 <p><?php esc_html_e('Create your first template by selecting a type above', 'king-addons'); ?></p>
1658 </div>
1659 <?php else: ?>
1660 <?php foreach ($templates as $template): ?>
1661 <?php
1662 $elementor_url = ka_woo_get_elementor_edit_url((int) $template['id']);
1663 $title_icon = $types[$template['type']]['icon'] ?? '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/></svg>';
1664 $duplicate_url = wp_nonce_url(add_query_arg([
1665 'page' => 'king-addons-woo-builder',
1666 'template_id' => $template['id'],
1667 'ka_woo_duplicate' => 1,
1668 ], admin_url('admin.php')), 'ka_woo_duplicate_' . $template['id']);
1669 $delete_url = wp_nonce_url(add_query_arg([
1670 'page' => 'king-addons-woo-builder',
1671 'template_id' => $template['id'],
1672 'ka_woo_delete' => 1,
1673 ], admin_url('admin.php')), 'ka_woo_delete_' . $template['id']);
1674 ?>
1675 <div class="ka-wb-template" data-template-id="<?php echo esc_attr($template['id']); ?>">
1676 <?php if ($template['status'] === 'draft'): ?>
1677 <span class="ka-wb-template-status is-draft"><?php esc_html_e('Draft', 'king-addons'); ?></span>
1678 <?php elseif ($template['enabled']): ?>
1679 <span class="ka-wb-template-status is-enabled"><?php esc_html_e('Active', 'king-addons'); ?></span>
1680 <?php else: ?>
1681 <span class="ka-wb-template-status is-disabled"><?php esc_html_e('Inactive', 'king-addons'); ?></span>
1682 <?php endif; ?>
1683
1684 <div class="ka-wb-template-info">
1685 <a href="<?php echo esc_url($elementor_url); ?>" class="ka-wb-template-title">
1686 <span class="ka-wb-template-title-icon" aria-hidden="true">
1687 <?php echo $title_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1688 </span>
1689 <span class="ka-wb-template-title-text"><?php echo esc_html($template['title']); ?></span>
1690 </a>
1691 <div class="ka-wb-template-meta">
1692 <span class="ka-wb-template-type">
1693 <?php echo esc_html($types[$template['type']]['label'] ?? $template['type']); ?>
1694 </span>
1695 <span><?php echo esc_html($template['date']); ?></span>
1696 </div>
1697 </div>
1698
1699 <!-- Condition Badge -->
1700 <?php
1701 $has_advanced_conditions = $template['condition_type'] !== 'all';
1702 $template_options = $condition_options[$template['type']] ?? ['all' => __('All', 'king-addons')];
1703 $show_conditions_button = count($template_options) > 1; // Show only if template type supports conditions
1704 ?>
1705 <?php if ($show_conditions_button): ?>
1706 <button type="button"
1707 class="ka-wb-template-condition <?php echo $has_advanced_conditions ? '' : 'ka-wb-template-condition-btn'; ?>"
1708 onclick="kaWbOpenConditions(<?php echo (int) $template['id']; ?>, '<?php echo esc_js($template['type']); ?>', '<?php echo esc_js($template['condition_type']); ?>', <?php echo esc_attr(wp_json_encode($template['condition_values'])); ?>)"
1709 title="<?php echo esc_attr($template['condition_label']); ?>">
1710 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1711 <circle cx="12" cy="12" r="3"/>
1712 <path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
1713 </svg>
1714 <?php echo esc_html($template['condition_label']); ?>
1715 <?php if (!$can_use_pro && $has_advanced_conditions): ?>
1716 <span class="ka-wb-pro-badge-inline">Pro</span>
1717 <?php endif; ?>
1718 </button>
1719 <?php else: ?>
1720 <span class="ka-wb-template-condition">
1721 <?php echo esc_html($template['condition_label']); ?>
1722 </span>
1723 <?php endif; ?>
1724
1725 <div class="ka-wb-template-actions">
1726 <a href="<?php echo esc_url($elementor_url); ?>" class="ka-wb-btn ka-wb-btn-primary">
1727 <?php esc_html_e('Edit', 'king-addons'); ?>
1728 </a>
1729
1730 <!-- Dropdown Menu -->
1731 <div class="ka-wb-dropdown">
1732 <button type="button" class="ka-wb-dropdown-trigger" aria-label="<?php esc_attr_e('More actions', 'king-addons'); ?>">
1733 <svg viewBox="0 0 24 24" fill="currentColor">
1734 <circle cx="12" cy="5" r="2"/>
1735 <circle cx="12" cy="12" r="2"/>
1736 <circle cx="12" cy="19" r="2"/>
1737 </svg>
1738 </button>
1739 <div class="ka-wb-dropdown-menu">
1740 <!-- Rename -->
1741 <button type="button" class="ka-wb-dropdown-item" onclick="kaWbRename(<?php echo (int) $template['id']; ?>, '<?php echo esc_js($template['title']); ?>')">
1742 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1743 <path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/>
1744 </svg>
1745 <?php esc_html_e('Rename', 'king-addons'); ?>
1746 </button>
1747
1748 <!-- Duplicate -->
1749 <a href="<?php echo esc_url($duplicate_url); ?>" class="ka-wb-dropdown-item">
1750 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1751 <rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>
1752 <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
1753 </svg>
1754 <?php esc_html_e('Duplicate', 'king-addons'); ?>
1755 </a>
1756
1757 <?php if (!$template['pro_locked']): ?>
1758 <!-- Toggle Active -->
1759 <a href="<?php echo esc_url(wp_nonce_url(add_query_arg([
1760 'page' => 'king-addons-woo-builder',
1761 'template_id' => $template['id'],
1762 'ka_woo_toggle' => 1,
1763 ], admin_url('admin.php')), 'ka_woo_toggle_' . $template['id'])); ?>" class="ka-wb-dropdown-item">
1764 <?php if ($template['enabled']): ?>
1765 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1766 <rect x="1" y="5" width="22" height="14" rx="7" ry="7"/>
1767 <circle cx="16" cy="12" r="3"/>
1768 </svg>
1769 <?php esc_html_e('Deactivate', 'king-addons'); ?>
1770 <?php else: ?>
1771 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1772 <rect x="1" y="5" width="22" height="14" rx="7" ry="7"/>
1773 <circle cx="8" cy="12" r="3"/>
1774 </svg>
1775 <?php esc_html_e('Activate', 'king-addons'); ?>
1776 <?php endif; ?>
1777 </a>
1778 <?php endif; ?>
1779
1780 <div class="ka-wb-dropdown-divider"></div>
1781
1782 <!-- Change Type -->
1783 <div class="ka-wb-dropdown-label"><?php esc_html_e('Change Type', 'king-addons'); ?></div>
1784 <?php foreach ($types as $type_slug => $type_data): ?>
1785 <?php
1786 if ($type_slug === $template['type']) continue;
1787 $is_type_locked = (!$can_use_pro && !empty($type_data['pro']));
1788 if ($is_type_locked) continue;
1789 $change_type_url = wp_nonce_url(add_query_arg([
1790 'page' => 'king-addons-woo-builder',
1791 'template_id' => $template['id'],
1792 'ka_woo_change_type' => 1,
1793 'new_type' => $type_slug,
1794 ], admin_url('admin.php')), 'ka_woo_change_type_' . $template['id']);
1795 ?>
1796 <a href="<?php echo esc_url($change_type_url); ?>" class="ka-wb-dropdown-item">
1797 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1798 <polyline points="9 18 15 12 9 6"/>
1799 </svg>
1800 <?php echo esc_html($type_data['label']); ?>
1801 </a>
1802 <?php endforeach; ?>
1803
1804 <div class="ka-wb-dropdown-divider"></div>
1805
1806 <!-- Delete -->
1807 <a href="<?php echo esc_url($delete_url); ?>" class="ka-wb-dropdown-item is-danger" onclick="return confirm('<?php esc_attr_e('Are you sure you want to delete this template?', 'king-addons'); ?>')">
1808 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1809 <polyline points="3 6 5 6 21 6"/>
1810 <path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
1811 </svg>
1812 <?php esc_html_e('Delete', 'king-addons'); ?>
1813 </a>
1814 </div>
1815 </div>
1816 </div>
1817 </div>
1818 <?php endforeach; ?>
1819 <?php endif; ?>
1820 </div>
1821 </section>
1822
1823 <!-- Quick Setup -->
1824 <div class="ka-wb-quickstart">
1825 <div class="ka-wb-quickstart-head">
1826 <h3><?php esc_html_e('Quick setup', 'king-addons'); ?></h3>
1827 <p><?php esc_html_e('3 steps to get started', 'king-addons'); ?></p>
1828 </div>
1829 <div class="ka-wb-quickstart-steps">
1830 <div class="ka-wb-quickstart-step">
1831 <span class="ka-wb-quickstart-step-number" aria-hidden="true">1</span>
1832 <div>
1833 <p class="ka-wb-quickstart-step-title"><?php esc_html_e('Pick a template type', 'king-addons'); ?></p>
1834 <p class="ka-wb-quickstart-step-desc"><?php esc_html_e('Choose what you want to customize: Single Product, Shop & Category, Cart, Checkout, or My Account.', 'king-addons'); ?></p>
1835 </div>
1836 </div>
1837 <div class="ka-wb-quickstart-step">
1838 <span class="ka-wb-quickstart-step-number" aria-hidden="true">2</span>
1839 <div>
1840 <p class="ka-wb-quickstart-step-title"><?php esc_html_e('Design in Elementor', 'king-addons'); ?></p>
1841 <p class="ka-wb-quickstart-step-desc"><?php esc_html_e('You’ll be taken straight into the Elementor editor. Build your layout visually using widgets from "King Addons Woo Builder" category or WooCommerce related widgets provided by other compatible plugins, then save.', 'king-addons'); ?></p>
1842 </div>
1843 </div>
1844 <div class="ka-wb-quickstart-step">
1845 <span class="ka-wb-quickstart-step-number" aria-hidden="true">3</span>
1846 <div>
1847 <p class="ka-wb-quickstart-step-title"><?php esc_html_e('Manage & activate templates', 'king-addons'); ?></p>
1848 <p class="ka-wb-quickstart-step-desc"><?php esc_html_e('Set display conditions in Pro. Activate or deactivate templates, and use the menu to rename, duplicate, or delete them.', 'king-addons'); ?></p>
1849 </div>
1850 </div>
1851 </div>
1852 </div>
1853
1854 </div>
1855
1856 <!-- Rename Modal -->
1857 <div class="ka-wb-modal-overlay" id="kaWbRenameModal">
1858 <div class="ka-wb-modal">
1859 <h3><?php esc_html_e('Rename Template', 'king-addons'); ?></h3>
1860 <form method="post" action="">
1861 <?php wp_nonce_field('ka_woo_rename', '_wpnonce'); ?>
1862 <input type="hidden" name="ka_woo_rename" value="1">
1863 <input type="hidden" name="template_id" id="kaWbRenameId" value="">
1864 <input type="text" name="new_title" id="kaWbRenameInput" class="ka-wb-modal-input" placeholder="<?php esc_attr_e('Template name', 'king-addons'); ?>">
1865 <div class="ka-wb-modal-actions">
1866 <button type="button" class="ka-wb-btn ka-wb-btn-secondary" onclick="kaWbCloseRename()"><?php esc_html_e('Cancel', 'king-addons'); ?></button>
1867 <button type="submit" class="ka-wb-btn ka-wb-btn-primary"><?php esc_html_e('Save', 'king-addons'); ?></button>
1868 </div>
1869 </form>
1870 </div>
1871 </div>
1872
1873 <!-- Conditions Modal -->
1874 <div class="ka-wb-modal-overlay" id="kaWbConditionsModal">
1875 <div class="ka-wb-modal ka-wb-modal-conditions">
1876 <h3><?php esc_html_e('Display Conditions', 'king-addons'); ?></h3>
1877 <p class="ka-wb-modal-desc"><?php esc_html_e('Choose where this template should be displayed', 'king-addons'); ?></p>
1878
1879 <?php if (!$can_use_pro): ?>
1880 <!-- Pro Lock Overlay -->
1881 <div class="ka-wb-modal-locked">
1882 <div class="ka-wb-modal-locked-overlay">
1883 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1884 <rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
1885 <path d="M7 11V7a5 5 0 0 1 10 0v4"/>
1886 </svg>
1887 <h4><?php esc_html_e('Pro Feature', 'king-addons'); ?></h4>
1888 <p><?php esc_html_e('Advanced display conditions are available in Pro', 'king-addons'); ?></p>
1889 <a href="https://kingaddons.com/pricing/" target="_blank" class="ka-wb-btn ka-wb-btn-primary">
1890 <?php esc_html_e('Upgrade to Pro', 'king-addons'); ?>
1891 </a>
1892 </div>
1893 <?php endif; ?>
1894
1895 <form method="post" action="" id="kaWbConditionsForm">
1896 <?php wp_nonce_field('ka_woo_conditions', '_wpnonce'); ?>
1897 <input type="hidden" name="ka_woo_update_conditions" value="1">
1898 <input type="hidden" name="template_id" id="kaWbConditionsId" value="">
1899
1900 <div class="ka-wb-form-group">
1901 <label class="ka-wb-form-label"><?php esc_html_e('Show template on', 'king-addons'); ?></label>
1902 <select name="condition_type" id="kaWbConditionType" class="ka-wb-form-select" onchange="kaWbUpdateConditionValues()">
1903 <!-- Options filled by JS -->
1904 </select>
1905 </div>
1906
1907 <div class="ka-wb-form-group" id="kaWbConditionValuesGroup" style="display: none;">
1908 <label class="ka-wb-form-label"><?php esc_html_e('Select items', 'king-addons'); ?></label>
1909 <div class="ka-wb-checkbox-list" id="kaWbConditionValues">
1910 <!-- Checkboxes filled by JS -->
1911 </div>
1912 </div>
1913
1914 <div class="ka-wb-modal-actions">
1915 <button type="button" class="ka-wb-btn ka-wb-btn-secondary" onclick="kaWbCloseConditions()"><?php esc_html_e('Cancel', 'king-addons'); ?></button>
1916 <button type="submit" class="ka-wb-btn ka-wb-btn-primary" <?php echo !$can_use_pro ? 'disabled' : ''; ?>><?php esc_html_e('Save', 'king-addons'); ?></button>
1917 </div>
1918 </form>
1919
1920 <?php if (!$can_use_pro): ?>
1921 </div>
1922 <?php endif; ?>
1923 </div>
1924 </div>
1925
1926 <script>
1927 // Condition options data
1928 const kaWbConditionOptions = <?php echo wp_json_encode($condition_options); ?>;
1929 const kaWbCategories = <?php echo wp_json_encode(array_map(function($cat) {
1930 return ['id' => $cat->term_id, 'name' => $cat->name];
1931 }, $product_categories)); ?>;
1932 const kaWbTags = <?php echo wp_json_encode(array_map(function($tag) {
1933 return ['id' => $tag->term_id, 'name' => $tag->name];
1934 }, $product_tags)); ?>;
1935 const kaWbProducts = <?php echo wp_json_encode(array_map(function($product) {
1936 return ['id' => $product->ID, 'name' => $product->post_title];
1937 }, $products)); ?>;
1938 const kaWbCanUsePro = <?php echo $can_use_pro ? 'true' : 'false'; ?>;
1939
1940 let kaWbCurrentConditionValues = [];
1941
1942 // Dropdown toggle
1943 document.addEventListener('click', function(e) {
1944 const trigger = e.target.closest('.ka-wb-dropdown-trigger');
1945 const dropdown = e.target.closest('.ka-wb-dropdown');
1946
1947 // Close all dropdowns first
1948 document.querySelectorAll('.ka-wb-dropdown.is-open').forEach(function(d) {
1949 if (d !== dropdown) d.classList.remove('is-open');
1950 });
1951
1952 // Toggle clicked dropdown
1953 if (trigger) {
1954 e.preventDefault();
1955 e.stopPropagation();
1956 dropdown.classList.toggle('is-open');
1957 } else if (!dropdown) {
1958 document.querySelectorAll('.ka-wb-dropdown.is-open').forEach(function(d) {
1959 d.classList.remove('is-open');
1960 });
1961 }
1962 });
1963
1964 // Rename modal
1965 function kaWbRename(id, title) {
1966 document.getElementById('kaWbRenameId').value = id;
1967 document.getElementById('kaWbRenameInput').value = title;
1968 document.getElementById('kaWbRenameModal').classList.add('is-open');
1969 setTimeout(function() {
1970 document.getElementById('kaWbRenameInput').focus();
1971 document.getElementById('kaWbRenameInput').select();
1972 }, 100);
1973 }
1974
1975 function kaWbCloseRename() {
1976 document.getElementById('kaWbRenameModal').classList.remove('is-open');
1977 }
1978
1979 // Conditions modal
1980 function kaWbOpenConditions(templateId, templateType, conditionType, conditionValues) {
1981 document.getElementById('kaWbConditionsId').value = templateId;
1982
1983 // Build select options
1984 const select = document.getElementById('kaWbConditionType');
1985 select.innerHTML = '';
1986 const options = kaWbConditionOptions[templateType] || {'all': 'All'};
1987
1988 for (const [value, label] of Object.entries(options)) {
1989 const option = document.createElement('option');
1990 option.value = value;
1991 option.textContent = label;
1992 if (value === conditionType) option.selected = true;
1993 select.appendChild(option);
1994 }
1995
1996 // Store current values
1997 kaWbCurrentConditionValues = conditionValues || [];
1998
1999 // Update values list
2000 kaWbUpdateConditionValues();
2001
2002 document.getElementById('kaWbConditionsModal').classList.add('is-open');
2003 }
2004
2005 function kaWbUpdateConditionValues() {
2006 const select = document.getElementById('kaWbConditionType');
2007 const conditionType = select.value;
2008 const valuesGroup = document.getElementById('kaWbConditionValuesGroup');
2009 const valuesContainer = document.getElementById('kaWbConditionValues');
2010
2011 let items = [];
2012
2013 switch (conditionType) {
2014 case 'product_cat':
2015 items = kaWbCategories;
2016 break;
2017 case 'product_tag':
2018 items = kaWbTags;
2019 break;
2020 case 'specific_product':
2021 items = kaWbProducts;
2022 break;
2023 default:
2024 valuesGroup.style.display = 'none';
2025 return;
2026 }
2027
2028 if (items.length === 0) {
2029 valuesGroup.style.display = 'none';
2030 return;
2031 }
2032
2033 valuesGroup.style.display = 'block';
2034 valuesContainer.innerHTML = '';
2035
2036 items.forEach(function(item) {
2037 const isChecked = kaWbCurrentConditionValues.includes(item.id);
2038 const label = document.createElement('label');
2039 label.className = 'ka-wb-checkbox-item';
2040 label.innerHTML = `
2041 <input type="checkbox" name="condition_values[]" value="${item.id}" ${isChecked ? 'checked' : ''}>
2042 <span>${item.name}</span>
2043 `;
2044 valuesContainer.appendChild(label);
2045 });
2046 }
2047
2048 function kaWbCloseConditions() {
2049 document.getElementById('kaWbConditionsModal').classList.remove('is-open');
2050 }
2051
2052 // Form submission for conditions
2053 document.getElementById('kaWbConditionsForm').addEventListener('submit', function(e) {
2054 if (!kaWbCanUsePro) {
2055 e.preventDefault();
2056 return false;
2057 }
2058
2059 // Update nonce with actual template ID
2060 const templateId = document.getElementById('kaWbConditionsId').value;
2061 const nonceField = this.querySelector('input[name="_wpnonce"]');
2062 // Nonce is already set, let form submit
2063 });
2064
2065 // Close modal on overlay click
2066 document.getElementById('kaWbRenameModal').addEventListener('click', function(e) {
2067 if (e.target === this) kaWbCloseRename();
2068 });
2069
2070 document.getElementById('kaWbConditionsModal').addEventListener('click', function(e) {
2071 if (e.target === this) kaWbCloseConditions();
2072 });
2073
2074 // Close modal on Escape key
2075 document.addEventListener('keydown', function(e) {
2076 if (e.key === 'Escape') {
2077 kaWbCloseRename();
2078 kaWbCloseConditions();
2079 }
2080 });
2081 </script>
2082
2083 <?php ka_render_dark_theme_script(); ?>
2084