| 1 |
<?php |
| 2 |
/** |
| 3 |
* MxChat Actions Page - Redesigned with Sidebar Navigation |
| 4 |
* |
| 5 |
* @package MxChat |
| 6 |
* @since 2.7.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
if (!defined('ABSPATH')) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Render the new sidebar-based Actions page |
| 15 |
*/ |
| 16 |
function mxchat_render_actions_page($admin_instance, $page_data) { |
| 17 |
$is_activated = $admin_instance->is_activated(); |
| 18 |
$plugin_url = plugin_dir_url(dirname(__FILE__)); |
| 19 |
|
| 20 |
// Extract page data |
| 21 |
extract($page_data); |
| 22 |
?> |
| 23 |
<div class="mxch-admin-wrapper mxch-actions-wrapper"> |
| 24 |
<!-- Mobile Header --> |
| 25 |
<header class="mxch-mobile-header"> |
| 26 |
<a href="#" class="mxch-mobile-logo"> |
| 27 |
<div class="mxch-mobile-logo-icon"> |
| 28 |
<img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat"> |
| 29 |
</div> |
| 30 |
<span class="mxch-mobile-logo-text">MxChat</span> |
| 31 |
</a> |
| 32 |
<button type="button" class="mxch-mobile-menu-btn" aria-label="<?php esc_attr_e('Open menu', 'mxchat'); ?>"> |
| 33 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></svg> |
| 34 |
</button> |
| 35 |
</header> |
| 36 |
|
| 37 |
<!-- Mobile Menu Overlay --> |
| 38 |
<div class="mxch-mobile-overlay"></div> |
| 39 |
|
| 40 |
<!-- Mobile Menu Modal --> |
| 41 |
<div class="mxch-mobile-menu"> |
| 42 |
<div class="mxch-mobile-menu-header"> |
| 43 |
<span class="mxch-mobile-menu-title"><?php esc_html_e('Actions', 'mxchat'); ?></span> |
| 44 |
<button type="button" class="mxch-mobile-menu-close" aria-label="<?php esc_attr_e('Close menu', 'mxchat'); ?>"> |
| 45 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> |
| 46 |
</button> |
| 47 |
</div> |
| 48 |
<nav class="mxch-mobile-menu-nav"> |
| 49 |
<!-- Actions umbrella: Dashboard, then AI Tools (recommended), then Trigger Phrases --> |
| 50 |
<div class="mxch-mobile-nav-section"> |
| 51 |
<div class="mxch-mobile-nav-section-title"><?php esc_html_e('Actions', 'mxchat'); ?></div> |
| 52 |
<button class="mxch-mobile-nav-link <?php echo (isset($active_tab) && $active_tab === 'dashboard') ? 'active' : ''; ?>" data-target="dashboard"> |
| 53 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="9"/><rect x="14" y="3" width="7" height="5"/><rect x="14" y="12" width="7" height="9"/><rect x="3" y="16" width="7" height="5"/></svg> |
| 54 |
<span><?php esc_html_e('Dashboard', 'mxchat'); ?></span> |
| 55 |
</button> |
| 56 |
<button class="mxch-mobile-nav-link <?php echo (isset($active_tab) && $active_tab === 'ai-tools') ? 'active' : ''; ?>" data-target="ai-tools"> |
| 57 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg> |
| 58 |
<span><?php esc_html_e('AI Tools', 'mxchat'); ?></span> |
| 59 |
</button> |
| 60 |
<button class="mxch-mobile-nav-link" data-target="all-actions"> |
| 61 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> |
| 62 |
<span><?php esc_html_e('Trigger Phrases', 'mxchat'); ?></span> |
| 63 |
</button> |
| 64 |
</div> |
| 65 |
<?php if (!$is_activated): ?> |
| 66 |
<div class="mxch-mobile-menu-footer"> |
| 67 |
<a href="https://mxchat.ai/" target="_blank" class="mxch-mobile-upgrade-btn"> |
| 68 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"/><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"/><path d="M4 22h16"/><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"/><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"/><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"/></svg> |
| 69 |
<?php esc_html_e('Upgrade to Pro', 'mxchat'); ?> |
| 70 |
</a> |
| 71 |
</div> |
| 72 |
<?php endif; ?> |
| 73 |
</nav> |
| 74 |
</div> |
| 75 |
|
| 76 |
<!-- Sidebar Navigation --> |
| 77 |
<aside class="mxch-sidebar"> |
| 78 |
<div class="mxch-sidebar-header"> |
| 79 |
<a href="#" class="mxch-sidebar-logo"> |
| 80 |
<div class="mxch-sidebar-logo-icon"> |
| 81 |
<img src="<?php echo esc_url($plugin_url . 'images/icon-128x128.png'); ?>" alt="MxChat"> |
| 82 |
</div> |
| 83 |
<span class="mxch-sidebar-logo-text">MxChat</span> |
| 84 |
<span class="mxch-sidebar-version">v<?php echo esc_html(MXCHAT_VERSION ?? '2.7.0'); ?></span> |
| 85 |
</a> |
| 86 |
</div> |
| 87 |
|
| 88 |
<nav class="mxch-sidebar-nav"> |
| 89 |
<!-- Actions umbrella: Dashboard, then AI Tools (recommended), then Trigger Phrases --> |
| 90 |
<div class="mxch-nav-section"> |
| 91 |
<div class="mxch-nav-section-title"><?php esc_html_e('Actions', 'mxchat'); ?></div> |
| 92 |
|
| 93 |
<div class="mxch-nav-item" data-section="dashboard"> |
| 94 |
<button class="mxch-nav-link <?php echo (isset($active_tab) && $active_tab === 'dashboard') ? 'active' : ''; ?>" data-target="dashboard"> |
| 95 |
<span class="mxch-nav-link-icon"> |
| 96 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="9"/><rect x="14" y="3" width="7" height="5"/><rect x="14" y="12" width="7" height="9"/><rect x="3" y="16" width="7" height="5"/></svg> |
| 97 |
</span> |
| 98 |
<span class="mxch-nav-link-text"><?php esc_html_e('Dashboard', 'mxchat'); ?></span> |
| 99 |
</button> |
| 100 |
</div> |
| 101 |
|
| 102 |
<div class="mxch-nav-item" data-section="ai-tools"> |
| 103 |
<button class="mxch-nav-link <?php echo (isset($active_tab) && $active_tab === 'ai-tools') ? 'active' : ''; ?>" data-target="ai-tools"> |
| 104 |
<span class="mxch-nav-link-icon"> |
| 105 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg> |
| 106 |
</span> |
| 107 |
<span class="mxch-nav-link-text"><?php esc_html_e('AI Tools', 'mxchat'); ?></span> |
| 108 |
<span class="mxch-nav-link-badge"><?php echo esc_html($total_tools); ?></span> |
| 109 |
</button> |
| 110 |
</div> |
| 111 |
|
| 112 |
<div class="mxch-nav-item" data-section="all-actions"> |
| 113 |
<button class="mxch-nav-link" data-target="all-actions"> |
| 114 |
<span class="mxch-nav-link-icon"> |
| 115 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> |
| 116 |
</span> |
| 117 |
<span class="mxch-nav-link-text"><?php esc_html_e('Trigger Phrases', 'mxchat'); ?></span> |
| 118 |
<span class="mxch-nav-link-badge"><?php echo esc_html($total_actions); ?></span> |
| 119 |
</button> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</nav> |
| 123 |
|
| 124 |
<?php if (!$is_activated): ?> |
| 125 |
<div class="mxch-sidebar-footer"> |
| 126 |
<a href="https://mxchat.ai/" target="_blank" class="mxch-sidebar-upgrade-v2"> |
| 127 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><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"/></svg> |
| 128 |
<?php esc_html_e('Pro Upgrade', 'mxchat'); ?> |
| 129 |
</a> |
| 130 |
</div> |
| 131 |
<?php endif; ?> |
| 132 |
</aside> |
| 133 |
|
| 134 |
<!-- Main Content Area --> |
| 135 |
<main class="mxch-content"> |
| 136 |
<!-- Dashboard Section --> |
| 137 |
<div id="dashboard" class="mxch-section <?php echo (isset($active_tab) && $active_tab === 'dashboard') ? 'active' : ''; ?>"> |
| 138 |
<div class="mxch-content-header"> |
| 139 |
<h1 class="mxch-content-title"><?php esc_html_e('Actions', 'mxchat'); ?></h1> |
| 140 |
<p class="mxch-content-subtitle"><?php esc_html_e('Give your chatbot the ability to do things — generate images, search the web, hand off to a human, capture an email, and more. There are two ways to set this up. The cards below explain when to use each.', 'mxchat'); ?></p> |
| 141 |
</div> |
| 142 |
|
| 143 |
<!-- Two ways to set up actions — landing explainer --> |
| 144 |
<div class="mxch-info-section"> |
| 145 |
<div class="mxch-info-section-header"> |
| 146 |
<div class="mxch-info-section-icon"> |
| 147 |
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg> |
| 148 |
</div> |
| 149 |
<h3 class="mxch-info-section-title"><?php esc_html_e('Two ways to set up actions', 'mxchat'); ?></h3> |
| 150 |
</div> |
| 151 |
<p class="mxch-info-section-desc"> |
| 152 |
<?php esc_html_e('Both let your chatbot take action during a conversation. Pick whichever fits how you want it to behave — or use both together.', 'mxchat'); ?> |
| 153 |
</p> |
| 154 |
|
| 155 |
<div class="mxch-approach-grid"> |
| 156 |
<!-- AI Tools (recommended) --> |
| 157 |
<div class="mxch-approach-card mxch-approach-card-primary"> |
| 158 |
<div class="mxch-approach-card-head"> |
| 159 |
<div class="mxch-approach-icon"> |
| 160 |
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg> |
| 161 |
</div> |
| 162 |
<div class="mxch-approach-titles"> |
| 163 |
<h4 class="mxch-approach-title"><?php esc_html_e('AI Tools', 'mxchat'); ?></h4> |
| 164 |
<span class="mxch-approach-pill"><?php esc_html_e('Recommended', 'mxchat'); ?></span> |
| 165 |
</div> |
| 166 |
</div> |
| 167 |
<p class="mxch-approach-desc"><?php esc_html_e('Add the tools your chatbot is allowed to use, and the AI decides when to use each one from the conversation. Easiest to set up — there are no phrases to write. Best for most sites.', 'mxchat'); ?></p> |
| 168 |
<button type="button" class="mxch-btn mxch-btn-primary mxch-approach-btn" data-approach-target="ai-tools"> |
| 169 |
<?php esc_html_e('Set up AI Tools', 'mxchat'); ?> |
| 170 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="5" y1="12" x2="19" y2="12"/><polyline points="12 5 19 12 12 19"/></svg> |
| 171 |
</button> |
| 172 |
</div> |
| 173 |
<!-- Trigger Phrases --> |
| 174 |
<div class="mxch-approach-card"> |
| 175 |
<div class="mxch-approach-card-head"> |
| 176 |
<div class="mxch-approach-icon mxch-approach-icon-muted"> |
| 177 |
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> |
| 178 |
</div> |
| 179 |
<div class="mxch-approach-titles"> |
| 180 |
<h4 class="mxch-approach-title"><?php esc_html_e('Trigger Phrases', 'mxchat'); ?></h4> |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
<p class="mxch-approach-desc"><?php esc_html_e('You write the exact phrases that should fire a capability, with a match-strength slider. Precise and predictable — best when you want tight control over exactly when something happens.', 'mxchat'); ?></p> |
| 184 |
<button type="button" class="mxch-btn mxch-btn-secondary mxch-approach-btn" id="mxch-add-action-dashboard-btn"> |
| 185 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> |
| 186 |
<?php esc_html_e('Add Trigger Phrase', 'mxchat'); ?> |
| 187 |
</button> |
| 188 |
</div> |
| 189 |
</div> |
| 190 |
|
| 191 |
<div class="mxch-approach-note"> |
| 192 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg> |
| 193 |
<span><strong><?php esc_html_e('Can I use both?', 'mxchat'); ?></strong> <?php esc_html_e('Yes. When a visitor\'s message matches one of your trigger phrases, that fires first; AI Tools cover everything else. Many sites run both together.', 'mxchat'); ?></span> |
| 194 |
</div> |
| 195 |
</div> |
| 196 |
|
| 197 |
</div> |
| 198 |
|
| 199 |
<!-- All Actions Section - Split Panel Layout --> |
| 200 |
<div id="all-actions" class="mxch-section"> |
| 201 |
<div class="mxch-split-panel"> |
| 202 |
<!-- Left Panel - Action List --> |
| 203 |
<div class="mxch-action-list-panel"> |
| 204 |
<!-- Bulk Actions Toolbar --> |
| 205 |
<div class="mxch-bulk-toolbar"> |
| 206 |
<label class="mxch-bulk-select-all"> |
| 207 |
<input type="checkbox" id="mxch-select-all-actions"> |
| 208 |
<span><?php esc_html_e('All', 'mxchat'); ?></span> |
| 209 |
</label> |
| 210 |
<span class="mxch-selected-count" id="mxch-selected-action-count">0</span> |
| 211 |
<div class="mxch-bulk-actions"> |
| 212 |
<button type="button" class="mxch-bulk-btn mxch-bulk-delete" id="mxch-delete-selected-actions" disabled title="<?php esc_attr_e('Delete Selected', 'mxchat'); ?>"> |
| 213 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><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"/></svg> |
| 214 |
</button> |
| 215 |
</div> |
| 216 |
</div> |
| 217 |
<div class="mxch-panel-header"> |
| 218 |
<div class="mxch-search-wrapper"> |
| 219 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> |
| 220 |
<input type="text" id="mxch-search-actions" class="mxch-search-input" placeholder="<?php esc_attr_e('Search trigger phrases...', 'mxchat'); ?>"> |
| 221 |
</div> |
| 222 |
<div class="mxch-panel-title-row"> |
| 223 |
<span class="mxch-panel-count" id="mxch-action-count">0 / 0 trigger phrases</span> |
| 224 |
<div class="mxch-panel-actions"> |
| 225 |
<button type="button" id="mxch-add-action-btn" class="mxch-btn mxch-btn-primary mxch-btn-sm" title="<?php esc_attr_e('Add Trigger Phrase', 'mxchat'); ?>"> |
| 226 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> |
| 227 |
<?php esc_html_e('Add', 'mxchat'); ?> |
| 228 |
</button> |
| 229 |
<button type="button" id="mxch-refresh-actions" class="mxch-icon-btn" title="<?php esc_attr_e('Refresh', 'mxchat'); ?>"> |
| 230 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg> |
| 231 |
</button> |
| 232 |
</div> |
| 233 |
</div> |
| 234 |
</div> |
| 235 |
<div class="mxch-action-list" id="mxch-action-list"> |
| 236 |
<!-- Action list items loaded via AJAX --> |
| 237 |
</div> |
| 238 |
<div class="mxch-panel-footer"> |
| 239 |
<div class="mxch-pagination-simple" id="mxch-actions-pagination"> |
| 240 |
<!-- Pagination controls --> |
| 241 |
</div> |
| 242 |
</div> |
| 243 |
</div> |
| 244 |
|
| 245 |
<!-- Right Panel - Action Details/Editor --> |
| 246 |
<div class="mxch-action-detail-panel" id="mxch-action-detail-panel"> |
| 247 |
<!-- Empty State --> |
| 248 |
<div class="mxch-action-empty" id="mxch-action-empty"> |
| 249 |
<div class="mxch-empty-icon"> |
| 250 |
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg> |
| 251 |
</div> |
| 252 |
<h3><?php esc_html_e('Select a trigger phrase', 'mxchat'); ?></h3> |
| 253 |
<p><?php esc_html_e('Choose a trigger phrase from the list to view details and edit, or create a new one.', 'mxchat'); ?></p> |
| 254 |
<button type="button" id="mxch-create-first-action-btn" class="mxch-btn mxch-btn-primary"> |
| 255 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> |
| 256 |
<?php esc_html_e('Create Trigger Phrase', 'mxchat'); ?> |
| 257 |
</button> |
| 258 |
</div> |
| 259 |
|
| 260 |
<!-- Action Editor (hidden initially) --> |
| 261 |
<div class="mxch-action-editor" id="mxch-action-editor" style="display: none;"> |
| 262 |
<!-- Step 1: Action Type Selection --> |
| 263 |
<div id="mxch-editor-step-1" class="mxch-editor-step active"> |
| 264 |
<div class="mxch-editor-header"> |
| 265 |
<button type="button" class="mxch-mobile-back-btn"> |
| 266 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg> |
| 267 |
<?php esc_html_e('Back', 'mxchat'); ?> |
| 268 |
</button> |
| 269 |
<h3 class="mxch-editor-title"><?php esc_html_e('Choose what it does', 'mxchat'); ?></h3> |
| 270 |
<button type="button" class="mxch-editor-close" id="mxch-close-editor"> |
| 271 |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> |
| 272 |
</button> |
| 273 |
</div> |
| 274 |
|
| 275 |
<div class="mxch-type-search"> |
| 276 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> |
| 277 |
<input type="text" id="mxch-type-search-input" placeholder="<?php esc_attr_e('Search types...', 'mxchat'); ?>"> |
| 278 |
</div> |
| 279 |
|
| 280 |
<div class="mxch-type-categories"> |
| 281 |
<button type="button" class="mxch-category-btn active" data-category="all"><?php esc_html_e('All', 'mxchat'); ?></button> |
| 282 |
<?php foreach ($callback_groups as $group_label => $group_callbacks): ?> |
| 283 |
<button type="button" class="mxch-category-btn" data-category="<?php echo esc_attr(sanitize_title($group_label)); ?>"><?php echo esc_html($group_label); ?></button> |
| 284 |
<?php endforeach; ?> |
| 285 |
</div> |
| 286 |
|
| 287 |
<div class="mxch-types-grid" id="mxch-types-grid"> |
| 288 |
<?php foreach ($callback_groups as $group_label => $group_callbacks): |
| 289 |
$category_slug = sanitize_title($group_label); |
| 290 |
foreach ($group_callbacks as $function => $data): |
| 291 |
$label = $data['label']; |
| 292 |
$pro_only = $data['pro_only']; |
| 293 |
$icon = isset($data['icon']) ? $data['icon'] : 'admin-generic'; |
| 294 |
$description = isset($data['description']) ? $data['description'] : ''; |
| 295 |
$is_addon = isset($data['addon']) && $data['addon'] !== false; |
| 296 |
$addon_name = isset($data['addon_name']) ? $data['addon_name'] : ''; |
| 297 |
$is_installed = isset($data['installed']) ? $data['installed'] : true; |
| 298 |
?> |
| 299 |
<div class="mxch-type-card <?php echo (!$is_activated && $pro_only) ? 'mxch-type-pro' : ''; ?> <?php echo ($is_addon && !$is_installed) ? 'mxch-type-addon' : ''; ?>" |
| 300 |
data-category="<?php echo esc_attr($category_slug); ?>" |
| 301 |
data-value="<?php echo esc_attr($function); ?>" |
| 302 |
data-label="<?php echo esc_attr($label); ?>" |
| 303 |
data-pro="<?php echo $pro_only ? 'true' : 'false'; ?>" |
| 304 |
data-addon="<?php echo esc_attr($is_addon ? $data['addon'] : ''); ?>" |
| 305 |
data-installed="<?php echo $is_installed ? 'true' : 'false'; ?>"> |
| 306 |
<div class="mxch-type-icon"> |
| 307 |
<span class="dashicons dashicons-<?php echo esc_attr($icon); ?>"></span> |
| 308 |
</div> |
| 309 |
<div class="mxch-type-info"> |
| 310 |
<h4><?php echo esc_html($label); ?></h4> |
| 311 |
<p><?php echo esc_html($description ?: sprintf(__('Use the %s action', 'mxchat'), $label)); ?></p> |
| 312 |
<?php if ($pro_only && !$is_activated): ?> |
| 313 |
<span class="mxch-badge mxch-badge-pro"><?php esc_html_e('Pro', 'mxchat'); ?></span> |
| 314 |
<?php endif; ?> |
| 315 |
<?php if ($is_addon && !$is_installed): ?> |
| 316 |
<span class="mxch-badge mxch-badge-addon"><?php echo esc_html(sprintf(__('Requires %s', 'mxchat'), $addon_name)); ?></span> |
| 317 |
<?php endif; ?> |
| 318 |
</div> |
| 319 |
</div> |
| 320 |
<?php endforeach; endforeach; ?> |
| 321 |
</div> |
| 322 |
</div> |
| 323 |
|
| 324 |
<!-- Step 2: Action Configuration --> |
| 325 |
<div id="mxch-editor-step-2" class="mxch-editor-step"> |
| 326 |
<div class="mxch-editor-header"> |
| 327 |
<button type="button" class="mxch-back-btn" id="mxch-back-to-step-1"> |
| 328 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg> |
| 329 |
<?php esc_html_e('Back', 'mxchat'); ?> |
| 330 |
</button> |
| 331 |
<h3 class="mxch-editor-title" id="mxch-config-title"><?php esc_html_e('Configure Trigger Phrase', 'mxchat'); ?></h3> |
| 332 |
<button type="button" class="mxch-editor-close" id="mxch-close-editor-2"> |
| 333 |
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg> |
| 334 |
</button> |
| 335 |
</div> |
| 336 |
|
| 337 |
<div class="mxch-selected-type"> |
| 338 |
<div class="mxch-selected-type-icon" id="mxch-selected-type-icon"> |
| 339 |
<span class="dashicons dashicons-admin-generic"></span> |
| 340 |
</div> |
| 341 |
<div class="mxch-selected-type-info"> |
| 342 |
<h4 id="mxch-selected-type-label"><?php esc_html_e('Selected Type', 'mxchat'); ?></h4> |
| 343 |
<p id="mxch-selected-type-desc"><?php esc_html_e('Configure this trigger phrase for your chatbot', 'mxchat'); ?></p> |
| 344 |
</div> |
| 345 |
</div> |
| 346 |
|
| 347 |
<form id="mxch-action-form" method="post"> |
| 348 |
<?php wp_nonce_field('mxchat_add_intent_nonce', 'mxch_action_nonce'); ?> |
| 349 |
<input type="hidden" name="action_id" id="mxch-action-id" value=""> |
| 350 |
<input type="hidden" name="callback_function" id="mxch-callback-function" value=""> |
| 351 |
<input type="hidden" name="form_mode" id="mxch-form-mode" value="add"> |
| 352 |
|
| 353 |
<div class="mxch-form-group"> |
| 354 |
<label for="mxch-action-label"><?php esc_html_e('Label', 'mxchat'); ?></label> |
| 355 |
<input type="text" id="mxch-action-label" name="intent_label" required placeholder="<?php esc_attr_e('e.g., Newsletter Signup', 'mxchat'); ?>"> |
| 356 |
<p class="mxch-form-hint"><?php esc_html_e('A descriptive name for this trigger phrase (for your reference only).', 'mxchat'); ?></p> |
| 357 |
</div> |
| 358 |
|
| 359 |
<div class="mxch-form-group"> |
| 360 |
<label><?php esc_html_e('Trigger Phrases', 'mxchat'); ?></label> |
| 361 |
<div class="mxch-phrase-input-wrapper"> |
| 362 |
<div class="mxch-phrase-tags" id="mxch-phrase-tags"> |
| 363 |
<!-- Phrase pills rendered dynamically --> |
| 364 |
</div> |
| 365 |
<div class="mxch-phrase-add-row"> |
| 366 |
<input type="text" id="mxch-phrase-input" placeholder="<?php esc_attr_e('Type a trigger phrase and press Enter', 'mxchat'); ?>"> |
| 367 |
<button type="button" class="mxch-btn mxch-btn-sm" id="mxch-add-phrase-btn"><?php esc_html_e('Add', 'mxchat'); ?></button> |
| 368 |
</div> |
| 369 |
</div> |
| 370 |
<p class="mxch-form-hint"><?php esc_html_e('Each phrase gets its own embedding vector for more accurate matching.', 'mxchat'); ?></p> |
| 371 |
</div> |
| 372 |
|
| 373 |
<div class="mxch-form-group"> |
| 374 |
<label for="mxch-action-threshold"> |
| 375 |
<?php esc_html_e('Similarity Threshold', 'mxchat'); ?> |
| 376 |
<span class="mxch-threshold-value" id="mxch-threshold-value">85%</span> |
| 377 |
</label> |
| 378 |
<input type="range" id="mxch-action-threshold" name="similarity_threshold" min="10" max="95" value="85"> |
| 379 |
<p class="mxch-form-hint"><?php esc_html_e('Lower values (10-30) trigger more easily. Higher values (70-95) require more exact matches.', 'mxchat'); ?></p> |
| 380 |
</div> |
| 381 |
|
| 382 |
<div class="mxch-form-group"> |
| 383 |
<label><?php esc_html_e('Enabled Bots', 'mxchat'); ?></label> |
| 384 |
<div class="mxch-bot-selector" id="mxch-bot-selector"> |
| 385 |
<label class="mxch-checkbox-label"> |
| 386 |
<input type="checkbox" name="enabled_bots[]" value="default" checked> |
| 387 |
<span class="mxch-checkmark"></span> |
| 388 |
<?php esc_html_e('Default Bot', 'mxchat'); ?> |
| 389 |
</label> |
| 390 |
<?php if (class_exists('MxChat_Multi_Bot_Core_Manager')): |
| 391 |
$multi_bot_manager = MxChat_Multi_Bot_Core_Manager::get_instance(); |
| 392 |
$available_bots_list = $multi_bot_manager->get_available_bots(); |
| 393 |
foreach ($available_bots_list as $bot_id => $bot_name): |
| 394 |
if ($bot_id === 'default') continue; |
| 395 |
?> |
| 396 |
<label class="mxch-checkbox-label"> |
| 397 |
<input type="checkbox" name="enabled_bots[]" value="<?php echo esc_attr($bot_id); ?>"> |
| 398 |
<span class="mxch-checkmark"></span> |
| 399 |
<?php echo esc_html($bot_name); ?> |
| 400 |
</label> |
| 401 |
<?php endforeach; endif; ?> |
| 402 |
</div> |
| 403 |
</div> |
| 404 |
|
| 405 |
<div class="mxch-form-actions"> |
| 406 |
<button type="button" class="mxch-btn mxch-btn-secondary" id="mxch-cancel-action"> |
| 407 |
<?php esc_html_e('Cancel', 'mxchat'); ?> |
| 408 |
</button> |
| 409 |
<button type="submit" class="mxch-btn mxch-btn-primary" id="mxch-save-action"> |
| 410 |
<?php esc_html_e('Save Trigger Phrase', 'mxchat'); ?> |
| 411 |
</button> |
| 412 |
</div> |
| 413 |
</form> |
| 414 |
</div> |
| 415 |
|
| 416 |
<!-- Action View (for viewing existing action details) --> |
| 417 |
<div id="mxch-action-view" class="mxch-editor-step"> |
| 418 |
<div class="mxch-editor-header"> |
| 419 |
<button type="button" class="mxch-mobile-back-btn"> |
| 420 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg> |
| 421 |
<?php esc_html_e('Back', 'mxchat'); ?> |
| 422 |
</button> |
| 423 |
<h3 class="mxch-editor-title" id="mxch-view-title"><?php esc_html_e('Trigger Phrase Details', 'mxchat'); ?></h3> |
| 424 |
<div class="mxch-header-actions"> |
| 425 |
<label class="mxch-toggle-switch" title="<?php esc_attr_e('Toggle Enabled', 'mxchat'); ?>"> |
| 426 |
<input type="checkbox" id="mxch-action-enabled-toggle" checked> |
| 427 |
<span class="mxch-toggle-slider"></span> |
| 428 |
</label> |
| 429 |
<button type="button" class="mxch-icon-btn" id="mxch-edit-action-btn" title="<?php esc_attr_e('Edit', 'mxchat'); ?>"> |
| 430 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> |
| 431 |
</button> |
| 432 |
<button type="button" class="mxch-icon-btn mxch-btn-danger-icon" id="mxch-delete-action-btn" title="<?php esc_attr_e('Delete', 'mxchat'); ?>"> |
| 433 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><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"/></svg> |
| 434 |
</button> |
| 435 |
</div> |
| 436 |
</div> |
| 437 |
|
| 438 |
<div class="mxch-action-details"> |
| 439 |
<div class="mxch-detail-card"> |
| 440 |
<div class="mxch-detail-icon" id="mxch-view-icon"> |
| 441 |
<span class="dashicons dashicons-admin-generic"></span> |
| 442 |
</div> |
| 443 |
<div class="mxch-detail-content"> |
| 444 |
<h4 id="mxch-view-label"><?php esc_html_e('Label', 'mxchat'); ?></h4> |
| 445 |
<p class="mxch-detail-type" id="mxch-view-type"><?php esc_html_e('Type', 'mxchat'); ?></p> |
| 446 |
</div> |
| 447 |
</div> |
| 448 |
|
| 449 |
<div class="mxch-detail-section"> |
| 450 |
<h5><?php esc_html_e('Trigger Phrases', 'mxchat'); ?></h5> |
| 451 |
<div class="mxch-phrases-list" id="mxch-view-phrases"> |
| 452 |
<!-- Phrases loaded dynamically --> |
| 453 |
</div> |
| 454 |
</div> |
| 455 |
|
| 456 |
<div class="mxch-detail-section"> |
| 457 |
<h5><?php esc_html_e('Settings', 'mxchat'); ?></h5> |
| 458 |
<div class="mxch-settings-grid"> |
| 459 |
<div class="mxch-setting-item"> |
| 460 |
<span class="mxch-setting-label"><?php esc_html_e('Similarity Threshold', 'mxchat'); ?></span> |
| 461 |
<span class="mxch-setting-value" id="mxch-view-threshold">85%</span> |
| 462 |
</div> |
| 463 |
<div class="mxch-setting-item"> |
| 464 |
<span class="mxch-setting-label"><?php esc_html_e('Status', 'mxchat'); ?></span> |
| 465 |
<span class="mxch-setting-value mxch-status-badge" id="mxch-view-status"><?php esc_html_e('Enabled', 'mxchat'); ?></span> |
| 466 |
</div> |
| 467 |
</div> |
| 468 |
</div> |
| 469 |
|
| 470 |
<div class="mxch-detail-section"> |
| 471 |
<h5><?php esc_html_e('Assigned Bots', 'mxchat'); ?></h5> |
| 472 |
<div class="mxch-bots-list" id="mxch-view-bots"> |
| 473 |
<!-- Bots loaded dynamically --> |
| 474 |
</div> |
| 475 |
</div> |
| 476 |
</div> |
| 477 |
</div> |
| 478 |
</div> |
| 479 |
</div> |
| 480 |
</div> |
| 481 |
</div> |
| 482 |
|
| 483 |
<!-- AI Tools Section (native function calling) --> |
| 484 |
<!-- No content-header band here — the section starts directly at the |
| 485 |
list+detail split panel, exactly like the Trigger Phrases section |
| 486 |
(#all-actions) above, for pixel parity (plan 5f7409). The per- |
| 487 |
approach explainer already lives on the Dashboard landing. --> |
| 488 |
<div id="ai-tools" class="mxch-section <?php echo (isset($active_tab) && $active_tab === 'ai-tools') ? 'active' : ''; ?>"> |
| 489 |
<div id="mxch-fc-settings" data-fc-nonce="<?php echo esc_attr(wp_create_nonce('mxchat_fc_autosave')); ?>"> |
| 490 |
|
| 491 |
<!-- Model-not-capable notice (relocated from the removed master toggle). |
| 492 |
Tools can still be added; they just won't fire until a tool-capable |
| 493 |
model is selected — so a user on a non-tool model isn't met with silence. --> |
| 494 |
<?php if (empty($fc_model_capable)): ?> |
| 495 |
<div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;"> |
| 496 |
<svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg> |
| 497 |
<div><?php printf(esc_html__('Your current chat model (%s) does not support tools. You can still add tools here, but they will not fire until you choose a tool-capable model in Settings.', 'mxchat'), '<strong>' . esc_html($fc_current_model) . '</strong>'); ?></div> |
| 498 |
</div> |
| 499 |
<?php endif; ?> |
| 500 |
|
| 501 |
<!-- Brave-key-not-set notice (plan 183856). Web Search + Image Search |
| 502 |
run on the Brave Search API; if either is enabled as a tool with no |
| 503 |
brave_api_key configured, they silently won't fire — so the admin |
| 504 |
gets a clear setup cue instead. Mirrors the model-not-capable notice. --> |
| 505 |
<?php if (!empty($fc_brave_missing)): ?> |
| 506 |
<div class="mxch-notice mxch-notice-warning" style="margin-bottom: 20px;"> |
| 507 |
<svg class="mxch-notice-icon" xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg> |
| 508 |
<div><?php printf(esc_html__('Web Search and Image Search are powered by Brave Search and need a Brave Search API key to work. Add your key under %s to enable them.', 'mxchat'), '<strong>' . esc_html__('Settings → Brave Search', 'mxchat') . '</strong>'); ?></div> |
| 509 |
</div> |
| 510 |
<?php endif; ?> |
| 511 |
|
| 512 |
<?php if (empty($fc_tools)): ?> |
| 513 |
<div class="mxch-card"> |
| 514 |
<div class="mxch-card-body"> |
| 515 |
<p class="mxch-fc-intro"><?php esc_html_e('No tools available yet. Core search and image tools appear here, and activating add-ons like WooCommerce adds more.', 'mxchat'); ?></p> |
| 516 |
</div> |
| 517 |
</div> |
| 518 |
<?php else: ?> |
| 519 |
<?php |
| 520 |
// Hidden store — the SINGLE source of truth for autosave. Each |
| 521 |
// .mxch-fc-tool keeps its hidden marker + checkbox + usage-hint |
| 522 |
// textarea exactly as the per-tool checklist did, so fcCollectAndSave() |
| 523 |
// and the mxchat_fc_autosave endpoint are UNCHANGED (HARD: no data-model |
| 524 |
// change). The master-detail list + detail panel below only toggle these |
| 525 |
// inputs. A tool whose checkbox is checked = active (plan d450a7) — there |
| 526 |
// is no global toggle and no per-tool enable checkbox in the UI anymore. |
| 527 |
$fc_hint_max = (int) (class_exists('MxChat_Tool_Registry') ? MxChat_Tool_Registry::HINT_MAX : 500); |
| 528 |
?> |
| 529 |
<div id="mxch-fc-tool-store" class="mxch-fc-tool-store" hidden aria-hidden="true"> |
| 530 |
<?php foreach ($fc_tools as $fc_tool): |
| 531 |
$fc_cb = $fc_tool['callback']; |
| 532 |
$fc_on = !empty($fc_tool['enabled']); |
| 533 |
$fc_icon = isset($fc_tool['icon']) ? $fc_tool['icon'] : 'admin-generic'; |
| 534 |
?> |
| 535 |
<div class="mxch-fc-tool" |
| 536 |
data-fc-callback="<?php echo esc_attr($fc_cb); ?>" |
| 537 |
data-fc-label="<?php echo esc_attr($fc_tool['label']); ?>" |
| 538 |
data-fc-desc="<?php echo esc_attr($fc_tool['description']); ?>" |
| 539 |
data-fc-setup="<?php echo esc_attr(isset($fc_tool['setup_note']) ? $fc_tool['setup_note'] : ''); ?>" |
| 540 |
data-fc-icon="<?php echo esc_attr($fc_icon); ?>" |
| 541 |
data-fc-addon="<?php echo !empty($fc_tool['is_addon']) ? '1' : '0'; ?>" |
| 542 |
data-fc-cautious="<?php echo !empty($fc_tool['cautious']) ? '1' : '0'; ?>"> |
| 543 |
<input type="hidden" name="mxchat_fc_all_tools[]" value="<?php echo esc_attr($fc_cb); ?>"> |
| 544 |
<input type="checkbox" name="mxchat_fc_tools[]" value="<?php echo esc_attr($fc_cb); ?>" <?php checked($fc_on); ?>> |
| 545 |
<textarea class="mxch-fc-hint-input" data-fc-callback="<?php echo esc_attr($fc_cb); ?>" maxlength="<?php echo $fc_hint_max; ?>"><?php echo esc_textarea(isset($fc_tool['usage_hint']) ? $fc_tool['usage_hint'] : ''); ?></textarea> |
| 546 |
</div> |
| 547 |
<?php endforeach; ?> |
| 548 |
</div> |
| 549 |
|
| 550 |
<!-- Master-detail split panel — clones the Trigger Phrases list+detail |
| 551 |
component (same mxch-* classes/CSS) so AI Tools reads as the same surface. |
| 552 |
FC-specific IDs keep the Trigger Phrases JS off these elements. --> |
| 553 |
<div class="mxch-split-panel" |
| 554 |
id="mxch-fc-panel" |
| 555 |
data-i18n-tools="<?php esc_attr_e('tools', 'mxchat'); ?>" |
| 556 |
data-i18n-tool="<?php esc_attr_e('tool', 'mxchat'); ?>" |
| 557 |
data-i18n-active="<?php esc_attr_e('Active', 'mxchat'); ?>" |
| 558 |
data-i18n-addon="<?php esc_attr_e('Add-on', 'mxchat'); ?>" |
| 559 |
data-i18n-sensitive="<?php esc_attr_e('Sensitive', 'mxchat'); ?>" |
| 560 |
data-i18n-nohint="<?php esc_attr_e('No usage note — the AI decides on its own when to use this.', 'mxchat'); ?>"> |
| 561 |
|
| 562 |
<!-- Left: tool list --> |
| 563 |
<div class="mxch-action-list-panel"> |
| 564 |
<!-- Bulk Actions Toolbar — exact clone of the Trigger Phrases |
| 565 |
#all-actions toolbar (All select-all + bulk-remove trash), |
| 566 |
FC-specific IDs so the Trigger Phrases JS stays off it (plan 5f7409). --> |
| 567 |
<div class="mxch-bulk-toolbar"> |
| 568 |
<label class="mxch-bulk-select-all"> |
| 569 |
<input type="checkbox" id="mxch-fc-select-all"> |
| 570 |
<span><?php esc_html_e('All', 'mxchat'); ?></span> |
| 571 |
</label> |
| 572 |
<span class="mxch-selected-count" id="mxch-fc-selected-count">0</span> |
| 573 |
<div class="mxch-bulk-actions"> |
| 574 |
<button type="button" class="mxch-bulk-btn mxch-bulk-delete" id="mxch-fc-delete-selected" disabled title="<?php esc_attr_e('Remove Selected', 'mxchat'); ?>"> |
| 575 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><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"/></svg> |
| 576 |
</button> |
| 577 |
</div> |
| 578 |
</div> |
| 579 |
<div class="mxch-panel-header"> |
| 580 |
<div class="mxch-search-wrapper"> |
| 581 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg> |
| 582 |
<input type="text" id="mxch-fc-search" class="mxch-search-input" placeholder="<?php esc_attr_e('Search tools...', 'mxchat'); ?>"> |
| 583 |
</div> |
| 584 |
<div class="mxch-panel-title-row"> |
| 585 |
<span class="mxch-panel-count" id="mxch-fc-count">0 <?php esc_html_e('tools', 'mxchat'); ?></span> |
| 586 |
<div class="mxch-panel-actions"> |
| 587 |
<button type="button" id="mxch-fc-add-btn" class="mxch-btn mxch-btn-primary mxch-btn-sm js-mxch-fc-add" title="<?php esc_attr_e('Add Tool', 'mxchat'); ?>"> |
| 588 |
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> |
| 589 |
<?php esc_html_e('Add', 'mxchat'); ?> |
| 590 |
</button> |
| 591 |
<button type="button" id="mxch-fc-refresh" class="mxch-icon-btn" title="<?php esc_attr_e('Refresh', 'mxchat'); ?>"> |
| 592 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/><path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"/><path d="M16 16h5v5"/></svg> |
| 593 |
</button> |
| 594 |
</div> |
| 595 |
</div> |
| 596 |
</div> |
| 597 |
<div class="mxch-action-list" id="mxch-fc-list"> |
| 598 |
<!-- Tool rows built by JS from the hidden store (enabled tools only) --> |
| 599 |
</div> |
| 600 |
<div class="mxch-panel-footer"> |
| 601 |
<span id="mxch-fc-save-status" class="mxch-fc-save-status" role="status" aria-live="polite"></span> |
| 602 |
</div> |
| 603 |
</div> |
| 604 |
|
| 605 |
<!-- Right: detail / view panel --> |
| 606 |
<div class="mxch-action-detail-panel" id="mxch-fc-detail-panel"> |
| 607 |
<!-- Empty state --> |
| 608 |
<div class="mxch-action-empty" id="mxch-fc-empty"> |
| 609 |
<div class="mxch-empty-icon"> |
| 610 |
<svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg> |
| 611 |
</div> |
| 612 |
<h3><?php esc_html_e('Select a tool', 'mxchat'); ?></h3> |
| 613 |
<p><?php esc_html_e('Choose a tool from the list to view details and edit when the AI should use it, or add a new one.', 'mxchat'); ?></p> |
| 614 |
<button type="button" class="mxch-btn mxch-btn-primary js-mxch-fc-add"> |
| 615 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg> |
| 616 |
<?php esc_html_e('Add Tool', 'mxchat'); ?> |
| 617 |
</button> |
| 618 |
</div> |
| 619 |
|
| 620 |
<!-- Tool view (shown when a tool is selected) --> |
| 621 |
<div class="mxch-action-editor" id="mxch-fc-view" style="display: none;"> |
| 622 |
<div class="mxch-editor-header"> |
| 623 |
<button type="button" class="mxch-mobile-back-btn"> |
| 624 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg> |
| 625 |
<?php esc_html_e('Back', 'mxchat'); ?> |
| 626 |
</button> |
| 627 |
<h3 class="mxch-editor-title"><?php esc_html_e('Tool Details', 'mxchat'); ?></h3> |
| 628 |
<div class="mxch-header-actions"> |
| 629 |
<button type="button" class="mxch-icon-btn" id="mxch-fc-edit-btn" title="<?php esc_attr_e('Edit usage note', 'mxchat'); ?>"> |
| 630 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg> |
| 631 |
</button> |
| 632 |
<button type="button" class="mxch-icon-btn mxch-btn-danger-icon" id="mxch-fc-remove-btn" title="<?php esc_attr_e('Remove tool', 'mxchat'); ?>"> |
| 633 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><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"/></svg> |
| 634 |
</button> |
| 635 |
</div> |
| 636 |
</div> |
| 637 |
|
| 638 |
<div class="mxch-action-details"> |
| 639 |
<div class="mxch-detail-card"> |
| 640 |
<div class="mxch-detail-icon" id="mxch-fc-view-icon"> |
| 641 |
<span class="dashicons dashicons-admin-generic"></span> |
| 642 |
</div> |
| 643 |
<div class="mxch-detail-content"> |
| 644 |
<h4 id="mxch-fc-view-label"><?php esc_html_e('Tool', 'mxchat'); ?></h4> |
| 645 |
<p class="mxch-detail-type" id="mxch-fc-view-type"></p> |
| 646 |
</div> |
| 647 |
</div> |
| 648 |
|
| 649 |
<div class="mxch-detail-section"> |
| 650 |
<h5><?php esc_html_e('What it does', 'mxchat'); ?></h5> |
| 651 |
<p class="mxch-fc-view-desc" id="mxch-fc-view-desc"></p> |
| 652 |
</div> |
| 653 |
|
| 654 |
<div class="mxch-detail-section"> |
| 655 |
<h5><?php esc_html_e('When the assistant uses this', 'mxchat'); ?></h5> |
| 656 |
<p class="mxch-fc-view-hint" id="mxch-fc-view-hint"></p> |
| 657 |
</div> |
| 658 |
|
| 659 |
<!-- Setup requirement (plan 183856) — only shown for tools that |
| 660 |
declare a setup_note (e.g. Web/Image Search → Brave key). JS |
| 661 |
toggles this section based on the tool's data-fc-setup. --> |
| 662 |
<div class="mxch-detail-section" id="mxch-fc-view-setup-wrap" style="display:none;"> |
| 663 |
<h5><?php esc_html_e('Setup', 'mxchat'); ?></h5> |
| 664 |
<p class="mxch-fc-view-setup" id="mxch-fc-view-setup"></p> |
| 665 |
</div> |
| 666 |
|
| 667 |
<div class="mxch-detail-section"> |
| 668 |
<h5><?php esc_html_e('Status', 'mxchat'); ?></h5> |
| 669 |
<div class="mxch-settings-grid"> |
| 670 |
<div class="mxch-setting-item"> |
| 671 |
<span class="mxch-setting-label"><?php esc_html_e('State', 'mxchat'); ?></span> |
| 672 |
<span class="mxch-setting-value mxch-status-badge"><?php esc_html_e('Active', 'mxchat'); ?></span> |
| 673 |
</div> |
| 674 |
</div> |
| 675 |
</div> |
| 676 |
</div> |
| 677 |
</div> |
| 678 |
</div> |
| 679 |
</div> |
| 680 |
<?php endif; ?> |
| 681 |
</div> |
| 682 |
</div> |
| 683 |
</main> |
| 684 |
</div> |
| 685 |
|
| 686 |
<!-- Loading Overlay --> |
| 687 |
<div id="mxch-action-loading" class="mxch-loading-overlay" style="display: none;"> |
| 688 |
<div class="mxch-loading-spinner"></div> |
| 689 |
<div class="mxch-loading-text"><?php esc_html_e('Saving, please wait...', 'mxchat'); ?></div> |
| 690 |
</div> |
| 691 |
|
| 692 |
<!-- Delete Confirmation Modal --> |
| 693 |
<div id="mxch-delete-modal" class="mxch-modal-overlay" style="display: none;"> |
| 694 |
<div class="mxch-modal-content mxch-modal-sm"> |
| 695 |
<div class="mxch-modal-header"> |
| 696 |
<h2><?php esc_html_e('Delete Trigger Phrase', 'mxchat'); ?></h2> |
| 697 |
<button type="button" class="mxch-modal-close">×</button> |
| 698 |
</div> |
| 699 |
<div class="mxch-modal-body"> |
| 700 |
<p><?php esc_html_e('Are you sure you want to delete this trigger phrase? This cannot be undone.', 'mxchat'); ?></p> |
| 701 |
</div> |
| 702 |
<div class="mxch-modal-footer"> |
| 703 |
<button type="button" class="mxch-btn mxch-btn-secondary" id="mxch-cancel-delete"><?php esc_html_e('Cancel', 'mxchat'); ?></button> |
| 704 |
<button type="button" class="mxch-btn mxch-btn-danger" id="mxch-confirm-delete"><?php esc_html_e('Delete', 'mxchat'); ?></button> |
| 705 |
</div> |
| 706 |
</div> |
| 707 |
</div> |
| 708 |
|
| 709 |
<!-- Add-Tool modal (AI Tools card flow, plan 8bbf98 part 4) --> |
| 710 |
<div id="mxch-fc-tool-modal" class="mxch-modal-overlay" style="display: none;"> |
| 711 |
<div class="mxch-modal-content mxch-modal-lg"> |
| 712 |
<!-- Step 1: pick a capability --> |
| 713 |
<div class="mxch-fc-modal-step" data-step="1"> |
| 714 |
<div class="mxch-modal-header"> |
| 715 |
<h2><?php esc_html_e('Add a Tool', 'mxchat'); ?></h2> |
| 716 |
<button type="button" class="mxch-modal-close" data-fc-modal-close>×</button> |
| 717 |
</div> |
| 718 |
<div class="mxch-modal-body"> |
| 719 |
<p class="mxch-fc-intro"><?php esc_html_e('Pick a capability the AI can call from the conversation.', 'mxchat'); ?></p> |
| 720 |
<div class="mxch-types-grid mxch-fc-modal-grid" id="mxch-fc-modal-grid"></div> |
| 721 |
<p class="mxch-fc-modal-allset" id="mxch-fc-modal-allset" style="display:none;"><?php esc_html_e('Every available tool is already added. Activate add-ons like WooCommerce to unlock more.', 'mxchat'); ?></p> |
| 722 |
</div> |
| 723 |
</div> |
| 724 |
<!-- Step 2: confirm + when-to-use --> |
| 725 |
<div class="mxch-fc-modal-step" data-step="2" style="display:none;"> |
| 726 |
<div class="mxch-modal-header"> |
| 727 |
<button type="button" class="mxch-back-btn" id="mxch-fc-modal-back"> |
| 728 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg> |
| 729 |
<?php esc_html_e('Back', 'mxchat'); ?> |
| 730 |
</button> |
| 731 |
<h2 id="mxch-fc-modal-step2-title" data-add-title="<?php esc_attr_e('Add Tool', 'mxchat'); ?>" data-edit-title="<?php esc_attr_e('Edit Tool', 'mxchat'); ?>"><?php esc_html_e('Add Tool', 'mxchat'); ?></h2> |
| 732 |
<button type="button" class="mxch-modal-close" data-fc-modal-close>×</button> |
| 733 |
</div> |
| 734 |
<div class="mxch-modal-body"> |
| 735 |
<div class="mxch-selected-type"> |
| 736 |
<div class="mxch-selected-type-icon" id="mxch-fc-modal-selected-icon"> |
| 737 |
<span class="dashicons dashicons-admin-generic"></span> |
| 738 |
</div> |
| 739 |
<div class="mxch-selected-type-info"> |
| 740 |
<h4 id="mxch-fc-modal-selected-label"><?php esc_html_e('Selected tool', 'mxchat'); ?></h4> |
| 741 |
<p id="mxch-fc-modal-selected-desc"></p> |
| 742 |
</div> |
| 743 |
</div> |
| 744 |
<div class="mxch-form-group"> |
| 745 |
<label for="mxch-fc-modal-hint"><?php esc_html_e('When should the assistant use this?', 'mxchat'); ?></label> |
| 746 |
<textarea id="mxch-fc-modal-hint" class="mxch-fc-modal-hint-input" rows="3" maxlength="<?php echo (int) (class_exists('MxChat_Tool_Registry') ? MxChat_Tool_Registry::HINT_MAX : 500); ?>" placeholder="<?php esc_attr_e('Optional — e.g. “Use only when the visitor asks about pricing or discounts.”', 'mxchat'); ?>"></textarea> |
| 747 |
<p class="mxch-form-hint"><?php esc_html_e('Leave blank to let the AI decide on its own. Your note is added to what the model knows about this tool.', 'mxchat'); ?></p> |
| 748 |
</div> |
| 749 |
<div class="mxch-fc-modal-sensitive-note" id="mxch-fc-modal-sensitive" style="display:none;"> |
| 750 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg> |
| 751 |
<span><?php esc_html_e('Sensitive tool — it can spend money, expose customer data, or hand off to a human. Only add it if you want the AI to do that.', 'mxchat'); ?></span> |
| 752 |
</div> |
| 753 |
</div> |
| 754 |
<div class="mxch-modal-footer"> |
| 755 |
<button type="button" class="mxch-btn mxch-btn-secondary" data-fc-modal-close><?php esc_html_e('Cancel', 'mxchat'); ?></button> |
| 756 |
<button type="button" class="mxch-btn mxch-btn-primary" id="mxch-fc-modal-save" data-add-label="<?php esc_attr_e('Add Tool', 'mxchat'); ?>" data-save-label="<?php esc_attr_e('Save Changes', 'mxchat'); ?>"><?php esc_html_e('Add Tool', 'mxchat'); ?></button> |
| 757 |
</div> |
| 758 |
</div> |
| 759 |
</div> |
| 760 |
</div> |
| 761 |
|
| 762 |
<?php |
| 763 |
} |
| 764 |
|