'boolean', ]; public static function description() { return __eva('Create custom WhatsApp messages that can be sent manually from the dashboard at any time.'); } public function restaurant() { return $this->belongsTo(Restaurant::class); } public function fields() { return [ [ 'attribute' => 'name', 'stacked' => true, 'inputClass' => 'form-input-bordered-highlight', 'name' => __eva('Name'), 'helpText' => __eva('Use this field to identify your custom message'), 'component' => 'text-field', 'value' => $this->name ], [ 'attribute' => 'whatsapp_active', 'stacked' => true, 'style' => 'display: inline-block; width: 20%; vertical-align: top;', 'name' => __eva('Active'), 'helpText' => __eva('Enable this custom message so it can be sent from the dashboard.'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->whatsapp_active ], [ 'attribute' => 'whatsapp_custom_message', 'stacked' => true, 'name' => __eva('WhatsApp custom message template'), 'component' => 'group-whatsapp-template-field', 'helpText' => __eva('Select the WhatsApp template to use for this custom message in each language.'), 'value' => $this->valueWithLanguagesFor('whatsapp_custom_message'), 'bookingFields' => self::getBookingFields(), 'isAdmin' => false, 'allowStaticValues' => true, ], ]; } public function defaultValue() { return [ 'name' => __eva('Custom Message'), 'whatsapp_active' => false, 'whatsapp_custom_message' => $this->getDefaultTemplateValue() ]; } /** * Get default template value structure for all languages * * @return array */ protected function getDefaultTemplateValue() { $languages = evavel_languages_allowed(); $value = []; foreach ($languages as $lang => $label) { $value[$lang] = [ 'template_sid' => '', 'template_name' => '', 'field_mapping' => [], 'static_values' => [], ]; } return $value; } /** * Get value with languages for a specific field * * @param string $key * @return array */ public function valueWithLanguagesFor($key) { $languages = evavel_languages_allowed(); $value = $this->{$key}; if (!is_array($value)) { $value = []; } // Ensure all languages have a configuration foreach ($languages as $lang => $label) { if (!isset($value[$lang])) { $value[$lang] = [ 'template_sid' => '', 'template_name' => '', 'field_mapping' => [], 'static_values' => [], ]; } // Ensure static_values key exists for existing configs if (!isset($value[$lang]['static_values'])) { $value[$lang]['static_values'] = []; } } return $value; } /** * Get configured template for a specific language * * @param string $language * @return array|null */ public function getTemplateConfig($language) { $config = $this->whatsapp_custom_message; if (!is_array($config) || !isset($config[$language])) { return null; } return $config[$language]; } /** * Check if the custom message is enabled * * @return bool */ public function isEnabled() { return (bool) $this->whatsapp_active; } }