<?php

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

if ( !class_exists( 'Reon' ) ) {
    return;
}


if ( !class_exists( 'Pricely_Admin_Amount_Type_Order' ) ) {

    class Pricely_Admin_Amount_Type_Order {

        public function __construct() {

            add_filter( 'pricely_admin_get-amount-type-groups', array( $this, 'get_groups' ), 10, 2 );
            add_filter( 'pricely_admin_get-amount-group-types-order', array( $this, 'get_types' ), 10, 2 );

            add_filter( 'pricely_admin_get-based-on-required-ids', array( $this, 'get_based_on_required_ids' ), 10, 2 );
            
            add_filter( 'pricely_admin_process-per_amount-amount-options', array( $this, 'process_per_amount_options' ), 10, 3 );
        }

        public function get_groups( $in_groups, $args ) {

            $in_groups[ 'order' ] = esc_html__( 'Amount Per Order', 'pricely-dynamic-pricing-cart-discounts' );

            return $in_groups;
        }

        public function get_types( $in_types, $args ) {

            $in_types[ 'fixed_amount' ] = esc_html__( 'Fixed amount', 'pricely-dynamic-pricing-cart-discounts' );
            $in_types[ 'per_amount' ] = esc_html__( 'Percentage amount', 'pricely-dynamic-pricing-cart-discounts' );

            return $in_types;
        }

        public function get_based_on_required_ids( $in_ids, $args ) {

            $in_ids[] = 'per_amount';

            return $in_ids;
        }
        
        public function process_per_amount_options( $options, $raw_options, $args ) {

            if ( isset( $raw_options[ 'based_on' ] ) ) {

                $options[ 'based_on' ] = $raw_options[ 'based_on' ];
            }

            return $options;
        }

    }

    new Pricely_Admin_Amount_Type_Order();
}