<?php
/**
 * Example custom widget for ONYX Builder.
 *
 * HOW TO USE
 * 1. Copy this file, rename it to something like  my-banner.php  (it must end with .php).
 * 2. Change the type 'my-banner' to a unique name, then edit the controls and the render function.
 * 3. Put a  my-banner.css  and/or  my-banner.js  in this same folder: they load automatically on pages that use ONYX widgets.
 * 4. Open the builder: your widget shows up under the category you chose (cat).
 *
 * This folder lives in  wp-content/onyx-widgets/  — plugin updates never touch it.
 * Rename this file to .php to activate it (files ending in .txt are ignored).
 */
if (!defined('ABSPATH')) exit;

obx_widget('my-banner', [
  'title' => 'My banner', 'title_ar' => 'بانر بتاعي', 'cat' => 'content', 'icon' => 'star', 'keywords' => 'custom banner',
  'controls' => [
    'content' => [
      'heading' => ['text', 'Heading', 'default' => 'Hello from my widget'],
      'text'    => ['textarea', 'Text', 'default' => 'Edit me in the builder.'],
      'link'    => ['link', 'Link'],
    ],
    'style' => [
      'bg'    => obx_color('Background', '{{W}} .my-banner', 'background'),
      'color' => obx_color('Text colour', '{{W}} .my-banner', 'color'),
      'pad'   => obx_dims('Padding', '{{W}} .my-banner', 'padding'),
      'typo'  => obx_typo('Heading typography', '{{W}} .my-banner h3'),
    ],
  ],
  // 'js' => 'my-banner',  // optional: then in my-banner.js:  OBX.modules['my-banner'] = function (el) { ... };
  'render' => function ($s, $el, $ctx) {
    $o = '<div class="my-banner"><h3>' . esc_html($s['heading']) . '</h3><p>' . esc_html($s['text']) . '</p>';
    if (obx_has_link($s['link'])) $o .= '<a class="obx-btn"' . obx_link_attrs($s['link']) . '>' . esc_html__('Open', 'onyx-builder') . '</a>';
    return $o . '</div>';
  },
]);
