<?php

namespace forge12\floating_menu\component\floatingmenu {
    if (!defined('ABSPATH')) {
        exit;
    }

	/**
	 * Dependencies
	 */
	require_once('MetaBoxFloatingMenuItems.class.php');
	require_once('MetaBoxFloatingMenuSettings.class.php');

    /**
     * Class PostType
     */
    class PostTypeFloatingMenu
    {
        /**
         * Admin constructor.
         */
        public function __construct()
        {
            add_action('init', [$this, '_registerPostType']);
            add_filter('wpml_is_translated_post_type', [$this, '_disableWpmlTranslation'], 10, 2);

			$MetaBoxFloatingMenuItems = new MetaBoxFloatingMenuItems();
            $MetaBoxFloatingMenuSettings = new MetaBoxFloatingMenuSettings();
        }

        /**
         * Prevent WPML from treating floating_menu as translatable.
         *
         * @param bool   $translatable
         * @param string $post_type
         *
         * @return bool
         */
        public function _disableWpmlTranslation( bool $translatable, string $post_type ): bool
        {
            if ( 'floating_menu' === $post_type ) {
                return false;
            }
            return $translatable;
        }

        /**
         * Register the post type
         */
        public function _registerPostType(): void
        {
            $labels = [
                'name'                  => __( 'Floating Menus', 'f12-floating-menu' ),
                'singular_name'         => __( 'Floating Menu', 'f12-floating-menu' ),
                'add_new'               => __( 'Add Menu', 'f12-floating-menu' ),
                'add_new_item'          => __( 'Add New Menu', 'f12-floating-menu' ),
                'edit_item'             => __( 'Edit Menu', 'f12-floating-menu' ),
                'new_item'              => __( 'New Menu', 'f12-floating-menu' ),
                'view_item'             => __( 'View Menu', 'f12-floating-menu' ),
                'view_items'            => __( 'View Menus', 'f12-floating-menu' ),
                'search_items'          => __( 'Search Menus', 'f12-floating-menu' ),
                'not_found'             => __( 'No menus found.', 'f12-floating-menu' ),
                'not_found_in_trash'    => __( 'No menus found in Trash.', 'f12-floating-menu' ),
                'all_items'             => __( 'All Menus', 'f12-floating-menu' ),
                'item_published'        => __( 'Menu published.', 'f12-floating-menu' ),
                'item_updated'          => __( 'Menu updated.', 'f12-floating-menu' ),
                'item_trashed'          => __( 'Menu trashed.', 'f12-floating-menu' ),
            ];

            $args = [
                'public' => true,
                'labels' => $labels,
                'label' => __( 'Floating Menu', 'f12-floating-menu' ),
                'menu_icon' => 'dashicons-menu',
                'show_in_menu' => true,
                'menu_position' => null,
                'supports' => ['title', 'revision']
            ];

            register_post_type('floating_menu', $args);
        }
    }
}