Ext.define("IceCap.component.Cursor", {

	xtype: "icecap-cursor",

	alias: [
		"widget-icecap-cursor"
	],

	extend: "Ext.Component",

	hidden: true,

	width: 9,

    height: 0,

    baseCls: Ext.baseCSSPrefix + "icecap-cursor",

	config: {
		inUse:  false,
		xValue: 0,
        yValue: 0,
        theme: "default"
	},

	listeners: {
        beforerender: {
            fn: function (i_cursor) {

                var i_self = this;

                var o_data = i_self.renderData || i_self.data || {};



                Ext.applyIf(o_data, {
                    width: i_self.width
                });

                i_self.renderData = i_self.data = o_data;
            }
        },
		afterrender: {
			fn: function(i_cursor) {

				i_cursor.update();
			}
		},
		show: {
			fn: function(i_cursor) {

				i_cursor.update();
			}
		}
	},

	renderTpl: [
        "<span id=\"{id}-cursor\" role=presentation data-ref=\"cursorEl\"",
        "style=\"",
            "width:{width}px;",
			"position: absolute !important;",
        "\">",
        "</span>"
	],

	childEls: [
		{
            name: "cursorEl",
            itemId: "cursor"
		},
    ],

	constructor: function(o_config) {

		var i_self = this;

        i_self.callParent(arguments);
    },

    initComponent: function() {

        var i_self = this;
        i_self.cls = ["iceCap-cursor", i_self.getTheme()].filter(Boolean).join("-");
    },

	updateInUse: function(value) {

		var i_self = this;

		i_self[value ? "show" : "hide"]();
	},

	updateXValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {
            i_self.setLocalX(value);
		}
	},

	updateYValue: function(value) {

		var i_self = this;

		if (i_self.rendered) {

            i_self.setLocalY(value);
		}
	},

	update: function() {

		var i_self = this;

		var n_x = i_self.getXValue();
		var n_y = i_self.getYValue();

		i_self.updateXValue(n_x);
		i_self.updateYValue(n_y);
	},

	move: function(a_position) {

		var i_self = this;

		i_self.setXValue(a_position[0]);
		i_self.setYValue(a_position[1]);
	},

	toggle: function() {

		var i_self = this;

		var b_InUse = i_self.getInUse();

		i_self.setInUse(!b_InUse);
	}
});
