import { ActionAPI } from "../../../ActionAPI";
import { EditorAPI, EditorAPI_Field } from "../../../EditorAPI";

module.exports = (ActionAPI: ActionAPI) => {
    ActionAPI.onExecute((properties, status) => {

    })


    ActionAPI.onOpenEditor((EditorAPI, properties) => {
        var connectionField: EditorAPI_Field = {
            id: "connectionID",
            name: "Connection",
            type: "connection",
            connectionType: "pjlink",
            value: properties.connectionID != undefined ? properties.connectionID : 'none'
        }

        var stateField: EditorAPI_Field = {
            id: 'state',
            name: "State",
            type: 'select',
            values: [{ id: "on", text: "Power On" }, { id: "off", text: "Power Off" }],
            value: properties.state != undefined ? properties.state : 'on'
        }

        EditorAPI.onFieldChanges((fields) => {
            var fieldObject = EditorAPI.tools.objectifyFieldsValues(fields)

            EditorAPI.saveProperties({ connectionID: fieldObject.connectionID, state: fieldObject.state })
        })

        EditorAPI.setFields([connectionField, stateField])
    })
}