<?php

namespace ProudNerds\Admin;

/**
 * A single help tab.
 */
class HelpTab
{
    private string $id = '';
    private string $title = '';
    private string $content = '';
    private string $screenId = '';
    private int $priority = 10;

    /**
     * Private constructor.
     *
     * @param string $title
     * @param string $content
     * @param string $screenId
     * @param int    $priority
     */
    private function __construct(string $title = '', string $content = '', string $screenId = '', int $priority = 10)
    {
        $this->setTitle($title);
        $this->setContent($content);
        $this->setScreenId($screenId);
        $this->setPriority($priority);
    }

    /**
     * Creates a new help tab. Tip: dump the get_current_screen() to get the current screen ID.
     *
     * @param string $title
     * @param string $content
     * @param string $screenId
     * @param int    $priority
     *
     * @return static
     */
    public static function create(
        string $title = '',
        string $content = '',
        string $screenId = '',
        int $priority = 10
    ): static {
        return new static($title, $content, $screenId, $priority);
    }

    /**
     * Sets the ID of the help tab.
     *
     * @param string $id
     *
     * @return static
     */
    public function setId(string $id): static
    {
        $this->id = $id;
        return $this;
    }

    /**
     * Sets the title of the help tab. If no ID is set for the tab, the title will be converted to a usable ID.
     *
     * @param string $title
     *
     * @return static
     */
    public function setTitle(string $title): static
    {
        if (!$this->id) {
            $this->id = strtolower(str_replace(' ', '-', $title));
        }

        $this->title = $title;
        return $this;
    }

    /**
     * Sets the content of the help tab. Can be HTML.
     *
     * @param string $content
     *
     * @return static
     */
    public function setContent(string $content): static
    {
        $this->content = $content;
        return $this;
    }

    /**
     * Sets the screen ID for the help tab. If no screen ID is set, the tab will be added to all screens.
     *
     * @param string $screenId
     *
     * @return static
     */
    public function setScreenId(string $screenId): static
    {
        $this->screenId = $screenId;
        return $this;
    }

    /**
     * Sets the priority of the help tab. The default priority is 10.
     *
     * @param int $priority
     *
     * @return static
     */
    public function setPriority(int $priority): static
    {
        $this->priority = $priority;
        return $this;
    }

    /**
     * Gets the title of the help tab.
     *
     * @return string
     */
    public function getTitle(): string
    {
        return $this->title;
    }

    /**
     * Gets the content of the help tab.
     *
     * @return string
     */
    public function getContent(): string
    {
        return $this->content;
    }

    /**
     * Gets the screen ID of the help tab.
     *
     * @return string
     */
    public function getScreenId(): string
    {
        return $this->screenId;
    }

    /**
     * Gets the priority of the help tab.
     *
     * @return int
     */
    public function getPriority(): int
    {
        return $this->priority;
    }

    /**
     * Gets the ID of the help tab.
     *
     * @return string
     */
    public function getId(): string
    {
        return $this->id;
    }
}
