<?php

namespace Inoby;

/**
 * Post type base class used to register post types.
 */
abstract class PostTypeBase {
  /**
   * @var string $slug
   * slug of post type
   */
  protected string $slug = "";

  /**
   * @var string $singular
   * singular form of post type name
   */
  protected string $singular = "";

  /**
   * @var string $plural
   * plural form of post type name
   */
  protected string $plural = "";

  /**
   * @var string $icon
   * dashicon
   */
  protected string $icon = "";

  /**
   * @var int $menu_position
   * position in admin menu
   */
  protected int $menu_position = 10;

  /**
   * @var mixed[] $metaboxes
   */
  protected array $metaboxes = [];

  /**
   * @var string $archive_reusable_block
   * slug of reusable block to be used as archive header
   */
  protected string $archive_reusable_block = "";

  /**
   * @var string[] $supports
   * available supports: title, editor, author, thumbnail, excerpt, trackbacks, custom-fields, comments, revisions, page-attributes, post-formats
   */
  protected array $supports = [];

  /**
   * @var bool|string $has_archive
   * archive disabled if set to false
   */
  protected bool $has_archive = true;

  function __construct() {
    $this->init();
  }

  abstract protected function init(): void;

  function register_pt() {
    $labels = [
      "name" => _x(ucfirst($this->plural), "Post Type General Name", "inoby"),
      "singular_name" => _x(ucfirst($this->singular), "Post Type Singular Name", "inoby"),
      "menu_name" => __(ucfirst($this->plural), "inoby"),
      "parent_item_colon" => __("Nadradené {$this->plural}", "inoby"),
      "all_items" => __("Všetky {$this->plural}", "inoby"),
      "view_item" => __("Zobraz {$this->singular}", "inoby"),
      "add_new_item" => __("Pridať {$this->singular}", "inoby"),
      "add_new" => __("Pridať {$this->singular}", "inoby"),
      "edit_item" => __("Upraviť {$this->singular}", "inoby"),
      "update_item" => __("Aktualizovať {$this->singular}", "inoby"),
      "search_items" => __("Hladať {$this->plural}", "inoby"),
      "not_found" => __("Nič sa nenašlo", "inoby"),
      "not_found_in_trash" => __("Nič sa nenašlo v koši", "inoby"),
    ];

    $args = [
      "label" => __(ucfirst($this->plural), "inoby"),
      "description" => __(ucfirst($this->singular), "inoby"),
      "labels" => $labels,
      "supports" => $this->supports,
      "menu_icon" => $this->icon,
      "hierarchical" => false,
      "public" => true,
      "show_ui" => true,
      "show_in_menu" => true,
      "show_in_nav_menus" => true,
      "show_in_admin_bar" => true,
      "menu_position" => $this->menu_position,
      "can_export" => true,
      "has_archive" => $this->has_archive,
      "exclude_from_search" => false,
      "publicly_queryable" => true,
      "capability_type" => "page",
      "show_in_rest" => true,
    ];

    register_post_type($this->slug, $args);
  }

  function get_mb() {
    $default = [
      "id" => "pt_" . $this->slug,
      "title" => esc_html__(ucfirst($this->singular), "inoby"),
      "post_types" => [$this->slug],
      "context" => "normal",
      "priority" => "default",
      "autosave" => "false",
    ];
    $meta_boxes = wp_parse_args($this->metaboxes, $default);
    $meta_boxes = apply_filters("inoby_{$this->slug}_metaboxes", $meta_boxes);
    return $meta_boxes;
  }
}

$a = "b";
