<?php

namespace Inoby;

use \Inoby_Config;

if (Inoby_Config::cookie_bar() && RC_ENABLED) {
  /**
   * META BOXES
   */

  add_filter("rwmb_meta_boxes", function ($meta_boxes) {
    $meta_boxes[] = [
      "id" => "mb-cookie-bar",
      "settings_pages" => "options",
      "tab" => "cookies",
      "title" => __("Cookies", "inoby"),
      "fields" => [
        [
          "id" => "cookies-title",
          "name" => __("Title"),
          "type" => "text",
          "std" => __("Na vašom súkromí nám záleží", "inoby"),
        ],
        [
          "id" => "cookies-description",
          "name" => __("Description"),
          "type" => "wysiwyg",
          "raw" => false,
          "options" => [
            "textarea_rows" => 4,
            "teeny" => true,
            "media_buttons" => false,
          ],
        ],
        [
          "id" => "cookies-settings-title",
          "name" => __("Settings") . " " . __("Title"),
          "type" => "text",
          "std" => __("Nastavenia cookies", "inoby"),
        ],
        [
          "type" => "divider",
        ],
        [
          "id" => "cookies-btn-accept",
          "name" => __("Tlačidlo \"Prijať všetko\"", "inoby"),
          "type" => "text",
          "std" => _x("Prijať všetko", "cookies", "inoby"),
        ],
        [
          "id" => "cookies-btn-settings",
          "name" => __("Tlačidlo \"Zobraziť nastavenia\"", "inoby"),
          "type" => "text",
          "std" => _x("Podrobné nastavenia", "cookies", "inoby"),
        ],
        [
          "id" => "cookies-btn-save",
          "name" => __("Tlačidlo \"Uložiť nastavenia\"", "inoby"),
          "type" => "text",
          "std" => _x("Potvrdiť vybrané", "cookies", "inoby"),
        ],
        [
          "type" => "divider",
        ],
        [
          "name" => __("Typ Cookies"), // Optional
          "id" => "cookie-types",
          "group_title" => _("Type") . ": {cookie-type}",
          "type" => "group",
          "clone" => true,
          "sort_clone" => true,
          "add_button" => __("Pridať ďalší typ", "inoby"),
          "fields" => [
            [
              "name" => __("Type"),
              "id" => "cookie-type",
              "type" => "select",
              "required" => true,
              "options" => [
                "base" => "Nevyhnutné",
                "performance" => "Výkonnostné",
                "functional" => "Funkčné",
                "marketing" => "Marketingové",
              ],
            ],
            [
              "name" => __("Title"),
              "id" => "cookie-type-title",
              "type" => "text",
            ],
            [
              "name" => __("Description"),
              "id" => "cookie-type-desc",
              "type" => "wysiwyg",
              "raw" => false,
              "options" => [
                "textarea_rows" => 4,
                "teeny" => true,
                "media_buttons" => false,
              ],
            ],
          ],
        ],
      ],
    ];
    return $meta_boxes;
  });

  do_action("rootcommerce_cookie_consent_categories", function ($categories) {
    ["base", "performance", "functional", "marketing"];

    $types = rwmb_meta("cookie-types", ["object_type" => "setting"], "options");
    return array_map(function ($type) {
      return $type["cookie-type"];
    }, $types);
  });
}
