<?php

namespace Booktics\Base\Services;

/**
 * Handles registration of all custom post statuses for Booktics.
 */
class Post_Status_Service {

    public $post_statuses = array(
        'active',
        'deactive',
        'pending',
        'canceled',
        'approved',
        'completed',
        'not_show',
    );

    /**
     * Get translated label for a specific post status.
     *
     * @param string $post_status The post status.
     * @return string The translated label.
     */
    private function get_label( $post_status ) {
        switch ( $post_status ) {
            case 'active':
                return __( 'Active', 'booktics' );
            case 'deactive':
                return __( 'Deactive', 'booktics' );
            case 'pending':
                return __( 'Pending', 'booktics' );
            case 'canceled':
                return __( 'Canceled', 'booktics' );
            case 'approved':
                return __( 'Approved', 'booktics' );
            case 'completed':
                return __( 'Completed', 'booktics' );
            case 'not_show':
                return __( 'Not Show', 'booktics' );
            default:
                return __( 'Status', 'booktics' );
        }
    }

    /**
     * Get label count for a specific post status.
     *
     * @param string $post_status The post status.
     * @return array The label count array.
     */
    private function get_label_count( $post_status ) {
        switch ( $post_status ) {
            case 'active':
                // translators: %s is the count of active items.
                return _n_noop(
                    'Active <span class="count">(%s)</span>',
                    'Active <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'deactive':
                // translators: %s is the count of deactive items.
                return _n_noop(
                    'Deactive <span class="count">(%s)</span>',
                    'Deactive <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'pending':
                // translators: %s is the count of pending items.
                return _n_noop(
                    'Pending <span class="count">(%s)</span>',
                    'Pending <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'canceled':
                // translators: %s is the count of canceled items.
                return _n_noop(
                    'Canceled <span class="count">(%s)</span>',
                    'Canceled <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'approved':
                // translators: %s is the count of approved items.
                return _n_noop(
                    'Approved <span class="count">(%s)</span>',
                    'Approved <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'completed':
                // translators: %s is the count of completed items.
                return _n_noop(
                    'Completed <span class="count">(%s)</span>',
                    'Completed <span class="count">(%s)</span>',
                    'booktics'
                );
            case 'not_show':
                // translators: %s is the count of items not shown.
                return _n_noop(
                    'Not Show <span class="count">(%s)</span>',
                    'Not Show <span class="count">(%s)</span>',
                    'booktics'
                );
            default:
                // translators: %s is the count of items with this status.
                return _n_noop(
                    'Status <span class="count">(%s)</span>',
                    'Status <span class="count">(%s)</span>',
                    'booktics'
                );
        }
    }

    /**
     * Register all custom post statuses.
     */
    public function register() {
        foreach ( $this->post_statuses as $post_status ) {
			register_post_status(
                $post_status, array(
					'label'                     => $this->get_label( $post_status ),
					'public'                    => true,
					'publicly_queryable'        => true,
					'exclude_from_search'       => false,
					'show_in_admin_all_list'    => true,
					'show_in_admin_status_list' => true,
					'label_count'               => $this->get_label_count( $post_status ),
				)
            );
        }
    }
}
