<?php

class MbExample extends MBComponentBase {
  protected function init_options($options) {
    // podmienka ci je komponent povoleny
    $options->enabled = current_user_can("manage_options");
    // id a title su povinne
    $options->id = "example";
    $options->title = "example";

    // ako sa ma vykreslit
    // bud cez funkciu
    // $options->render_callback = [$this, "render"];
    // alebo cez template
    $options->render_template = get_theme_file_path("components/example/template.php");

    // definicia fieldov
    $options->fields[] = [
      "name" => "text",
      "id" => "example_text",
      "type" => "text",
    ];
  }

  function render($attributes, $is_preview, $post_id) {
    $text = $attributes["data"]["example_text"] ?? "";
    echo $text;
  }
}
