'boolean', 'for_shifts' => 'boolean', 'for_events' => 'boolean', ]; public static function description() { return __eva('When the reservation is approaching, make sure to send WhatsApp reminders to your clients.'); } public function restaurant() { return $this->belongsTo(Restaurant::class); } public function fields() { return [ [ 'attribute' => 'for_shifts', 'stacked' => true, 'style' => 'display: inline-block; width: 10%; vertical-align: top;', 'name' => __eva('Use For Shifts'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->for_shifts ], [ 'attribute' => 'for_events', 'stacked' => true, 'style' => 'display: inline-block; width: 10%; vertical-align: top;', 'name' => __eva('Use For Events'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->for_events ], [ 'attribute' => 'name', 'stacked' => true, 'inputClass' => 'form-input-bordered-highlight', 'name' => __eva('Name'), 'helpText' => __eva('Use this field to identify your reminder'), 'component' => 'text-field', 'value' => $this->name ], [ 'attribute' => 'whatsapp_active', 'stacked' => true, 'style' => 'display: inline-block; width: 20%; vertical-align: top;', 'name' => __eva('Send this WhatsApp'), 'component' => 'boolean-field', 'type' => 'switch', 'value' => $this->whatsapp_active ], [ 'attribute' => 'whatsapp_time', 'stacked' => true, 'style' => 'display: inline-block; width: 50%; vertical-align: top;', 'name' => __eva('When should be sent'), 'component' => 'select-field', 'options' => $this->getListOfTimes(), 'value' => $this->whatsapp_time ], [ 'attribute' => 'whatsapp_reminder', 'stacked' => true, 'name' => __eva('WhatsApp reminder template'), 'component' => 'group-whatsapp-template-field', 'helpText' => __eva('Select the WhatsApp template to use for the reminder in each language.'), 'value' => $this->valueWithLanguagesFor('whatsapp_reminder'), 'bookingFields' => self::getBookingFields(), 'isAdmin' => false, ], ]; } protected function getListOfTimes() { $options = [ ['label' => __eva('1 hour before'), 'value' => 3600], ]; for ($i = 2; $i <= 48; $i++) { $label = $i . ' ' .__eva('hours before'); if ($i == 24) { $label .= ' ' . __eva('(1 day before)'); } else if ($i == 36) { $label .= ' ' . __eva('(1.5 days before)'); } else if ($i == 48) { $label .= ' ' . __eva('(2 days before)'); } $options[] = ['label' => $label, 'value' => 3600 * $i]; } for($i = 3; $i <= 30; $i++) { $value = $i * 24 * 3600; $label = str_replace('{x}', $i, __eva('{x} days before')); $options[] = ['label' => $label, 'value' => $value]; } return $options; } public function defaultValue() { return [ 'name' => __eva('WhatsApp Reminder'), 'for_shifts' => true, 'for_events' => true, 'whatsapp_active' => true, 'whatsapp_time' => 7200, 'whatsapp_reminder' => $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' => [], ]; } 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' => [], ]; } } return $value; } /** * Get configured template for a specific language * * @param string $language * @return array|null */ public function getTemplateConfig($language) { $config = $this->whatsapp_reminder; if (!is_array($config) || !isset($config[$language])) { return null; } return $config[$language]; } /** * Check if the reminder is enabled * * @return bool */ public function isEnabled() { return (bool) $this->whatsapp_active; } /** * Get the time before the booking when the reminder should be sent * * @return int Time in seconds */ public function getTimeBefore() { return (int) $this->whatsapp_time; } /** * Check if this reminder should be used for shifts * * @return bool */ public function isForShifts() { return (bool) $this->for_shifts; } /** * Check if this reminder should be used for events * * @return bool */ public function isForEvents() { return (bool) $this->for_events; } }