<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of rtgrid_field_callback
 *
 * @author Igor Ratsun
 */
class rtgrid_field_callback extends CI_Model {

    public $buffer = NULL;

    public function default_field($name = '', $value = NULL) {

        return $this->input($name, $value);
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function input($name = '', $value = NULL) {

        return '<input type="text" name="' . $name . '" value="' . $value . '" />';
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function active($name = '', $value = NULL) {
        return (new \Rtgc_active())->field($name, $value);
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function textarea($name = '', $value = NULL) {
        return (new \Rtgc_textarea())->field($name, $value);
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function texteditor($name = '', $value = NULL) {
        return (new \Rtgc_texteditor())->field($name, $value);
    }

    /**
     * @deprecated since version 3.3.2
     */
    public function date($name = '', $value = NULL) {

        return (new \Rtgc_date())->field($name, $value);
    }

    /**
     * @deprecated since version 3.3.2
     */
    public function datetime($name = '', $value = NULL) {

        return (new \Rtgc_date(['with_time' => true]))->field($name, $value);
    }

    /**
     * @deprecated since version 3.6.0
     */
    public function spinner($name = '', $value = 0) {

        return (new \Rtgc_number())->field($name, $value);
    }

    public function dropdown($name = '', $value = '') {
        if (!is_array($this->buffer[$name])) {

            return '';
        }

        $this->load->helper('form');

        return form_dropdown($name, $this->buffer[$name], $value);
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function price($name = '', $value = '', $currency = 'uah') {
        
        return $this->load->library('rtgrid/callback/rtgc_price')->set_currency($currency)->field($name, $value);
    }

    /**
     * @deprecated since version 3.1.20
     */
    public function price_uah($name = '', $value = '') {
        
        return $this->price($name, $value, 'uah');
    }
    
    /**
     * @deprecated since version 3.1.20
     */
    public function price_usd($name = '', $value = '') {
        
        return $this->price($name, $value, 'usd');
    }
    
    /**
     * @deprecated since version 3.1.20
     */
    public function price_rub($name = '', $value = '') {
        
        return $this->price($name, $value, 'rub');
    }

    public function readonly($name = '', $value = '') {
        
        return '<input class="input" type="text" disabled value="' . $value .'" />';
    }

}
