<?php

namespace Phox\core\admin\panel\wdes_options\pages\elements;

use Phox\core\admin\panel\wdes_options\pages\elements\Abstract_Basic_Type;
use Phox\core\admin\panel\wdes_options\Panel_Controller;

class Abstract_Multi_Values extends Abstract_Basic_Type
{

    public function saved_value():mixed
    {
        $options = Panel_Controller::getInstance()->get_db_source()->get_option($this->id);

        if(is_string($options)){
            $pre_save_value = json_decode(str_replace('\\','',$options),true);
        }else{
            $pre_save_value = $options;
        }

        return $pre_save_value;

    }

    public function get_prepared_save_values()
    {
        $values = $this->values;

        $validate_values = $this->validate_values();

        if( ! $validate_values->check_status() ) {

            $values = [
                'error' => $validate_values->get_validator()
            ];

        };

        return $values;
    }

}