"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkFormControl = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const FormDesignConstants_1 = require("../../Utilities/FormDesignConstants");
const IDesignValidationProvider_1 = require("@appglue/common/dist/Common/IDesignValidationProvider");
const PropertyEditorText_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorText");
const core_1 = require("@material-ui/core");
const FormControl_1 = require("../FormControl");
const Link_1 = require("../../../CommonUI/BuilderUI/Link");
const PropertyEditorSelect_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorSelect");
const PropertyEditorBoolean_1 = require("../../../CommonUI/PropertyEditing/PropertyEditorBoolean");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
class LinkFormControl extends FormControl_1.FormControl {
    __type = "Link";
    label = "Test Link";
    type = FormDesignConstants_1.LinkControlType.URL;
    linkUnderline = FormDesignConstants_1.LinkControlUnderline.HOVER;
    size;
    valueName;
    useNameAsOutcomeName = true;
    outcomeName = "";
    onClick = () => {
        this.getFormContext()?.outcomeTriggered(this.getOutcomeName());
    };
    getOutcomeName = () => {
        if (this.useNameAsOutcomeName)
            return this.label;
        return this.outcomeName;
    };
    render() {
        let size = this.size
            ? this.size
            : this.getFormContext()?.form?.defaultButtonSize ?? "medium";
        let underline = this.getFormContext()?.form?.defaultLinkUnderline ?? "hover";
        if (this.linkUnderline)
            underline = this.linkUnderline;
        return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [this.type === FormDesignConstants_1.LinkControlType.ACTION && ((0, jsx_runtime_1.jsx)(Link_1.StyledLink, { size: size, underline: underline, "data-testid": "xlink-action", onClick: this.onClick, ref: this.ref, children: this.label })), this.type === FormDesignConstants_1.LinkControlType.URL && ((0, jsx_runtime_1.jsx)(Link_1.StyledLink, { size: size, underline: underline, "data-testid": "xlink-url", href: this.valueName ? this.getFormDataValue(this.valueName) : "", ref: this.ref, children: this.label }))] }));
    }
    getDesignValidationIssues() {
        let issues = [];
        if (!this.label) {
            issues.push(new IDesignValidationProvider_1.ValidationIssue("Label is required", "label", this.id));
        }
        return issues;
    }
    getRuntimeValidationIssues() {
        let issues = [];
        return issues;
    }
    renderEditUI() {
        return (0, jsx_runtime_1.jsx)(XLinkEditUI, { editMe: this });
    }
    getAddedData() {
        return;
    }
    getStorageData() {
        let retData = super.getStorageData();
        retData = DataUtilities_1.DataUtilities.addStorageData(this, retData, "__type", "label", "type", "linkUnderline", "size", "valueName", "useNameAsOutcomeName", "outcomeName");
        return retData;
    }
    setStorageData(data) {
        super.setStorageData(data);
        DataUtilities_1.DataUtilities.setStorageData(this, data, "__type", "label", "type", "linkUnderline", "size", "valueName", "useNameAsOutcomeName", "outcomeName");
    }
}
exports.LinkFormControl = LinkFormControl;
function XLinkEditUI(props) {
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { editObject: props.editMe, propertyName: "label", updateCallback: props.editMe.controlUpdate, label: "Label" }), (0, jsx_runtime_1.jsx)(PropertyEditorBoolean_1.PropertyEditorBoolean, { editObject: props.editMe, label: "Use name as outcomeName", propertyName: "useNameAsOutcomeName", updateCallback: props.editMe.controlUpdate }), (0, jsx_runtime_1.jsx)(core_1.Collapse, { in: !props.editMe.useNameAsOutcomeName, children: (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { editObject: props.editMe, propertyName: "outcomeName", label: "Outcome Name", updateCallback: props.editMe.controlUpdate }) }), (0, jsx_runtime_1.jsx)(PropertyEditorSelect_1.PropertyEditorSelect, { editObject: props.editMe, propertyName: "size", options: [FormDesignConstants_1.ButtonControlSize.SMALL, FormDesignConstants_1.ButtonControlSize.STANDARD, FormDesignConstants_1.ButtonControlSize.LARGE], updateCallback: props.editMe.controlUpdate, label: "Size" }), (0, jsx_runtime_1.jsx)(PropertyEditorSelect_1.PropertyEditorSelect, { editObject: props.editMe, propertyName: "type", options: [FormDesignConstants_1.LinkControlType.URL, FormDesignConstants_1.LinkControlType.ACTION], updateCallback: props.editMe.controlUpdate, label: "Type" }), (0, jsx_runtime_1.jsx)(PropertyEditorSelect_1.PropertyEditorSelect, { editObject: props.editMe, propertyName: "linkUnderline", options: [FormDesignConstants_1.LinkControlUnderline.ALWAYS, FormDesignConstants_1.LinkControlUnderline.HOVER, FormDesignConstants_1.LinkControlUnderline.NONE], updateCallback: props.editMe.controlUpdate, label: "Underline" }), (0, jsx_runtime_1.jsx)(core_1.Collapse, { in: props.editMe.type === FormDesignConstants_1.LinkControlType.URL, children: (0, jsx_runtime_1.jsx)(PropertyEditorText_1.PropertyEditorText, { editObject: props.editMe, updateCallback: props.editMe.controlUpdate, propertyName: "valueName", label: "Value Name" }) })] }));
}
//# sourceMappingURL=LinkFormControl.js.map