<?php

if ( !defined( 'ABSPATH' ) ) {
    exit;
}

if ( !class_exists( 'Reon' ) ) {

    return;
}

if ( !class_exists( 'Pricely_Admin_Locale_Product_Promotion_Label' ) ) {

    class Pricely_Admin_Locale_Product_Promotion_Label {

        private static $instance;
        private $ui_type = 'label';
        private $settings_id;
        private $promotion_id;

        public static function get_instance(): self {

            if ( is_null( self::$instance ) ) {

                self::$instance = new self();
            }

            return self::$instance;
        }

        public function can_process_string( $promotion_type ) {

            return ('label' == $promotion_type);
        }

        public function process_strings( $strings, $promotion ) {

            $this->settings_id = $promotion[ 'setting_id' ];
            $this->promotion_id = $promotion[ 'id' ];

            return $this->process_text( $strings, $promotion );
        }

        private function process_text( $strings, $promotion ) {

            if ( empty( $promotion[ 'text' ] ) ) {

                return $strings;
            }

            $string_id = $this->get_string_id( 'text' );

            $strings[ $string_id ] = $promotion[ 'text' ];

            return $strings;
        }

        private function get_string_id( $text_key ) {

            return 'product-promotion-' . $this->ui_type . '-' . $this->settings_id . '-' . $this->promotion_id . '-' . $text_key;
        }

    }

}