import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { ButtonControlSize } from "../FormDesignConstants";
import { LinkControlType, LinkControlUnderline } from "../FormDesignConstants";
import { ValidationIssue } from "../../Common/IDesignValidationProvider";
import { PropertyEditorText } from "../../CommonUI/PropertyEditing/PropertyEditorText";
import { Collapse } from "@material-ui/core";
import { XBaseControl } from "./XBaseControl";
import { StyledLink } from "../../CommonUI/BuildUI/Link";
import { PropertyEditorSelect } from "../../CommonUI/PropertyEditing/PropertyEditorSelect";
export class XLink extends XBaseControl {
    constructor() {
        super(...arguments);
        this.label = "Test Link";
        this.type = LinkControlType.URL;
        this.linkUnderline = LinkControlUnderline.HOVER;
        this.getOutcomeName = () => {
            return this.label;
        };
    }
    render() {
        var _a, _b, _c, _d, _e, _f;
        let size = this.size
            ? this.size
            : (_c = (_b = (_a = this.getFormContext()) === null || _a === void 0 ? void 0 : _a.form) === null || _b === void 0 ? void 0 : _b.defaultButtonSize) !== null && _c !== void 0 ? _c : "medium";
        let underline = (_f = (_e = (_d = this.getFormContext()) === null || _d === void 0 ? void 0 : _d.form) === null || _e === void 0 ? void 0 : _e.defaultLinkUnderline) !== null && _f !== void 0 ? _f : "hover";
        if (this.linkUnderline)
            underline = this.linkUnderline;
        return (_jsxs(_Fragment, { children: [this.type === LinkControlType.ACTION && (_jsx(StyledLink, Object.assign({ size: size, underline: underline, "data-testid": "xlink-action", onClick: () => {
                        var _a;
                        (_a = this.getFormContext()) === null || _a === void 0 ? void 0 : _a.outcomeTriggered(this.getOutcomeName());
                    }, ref: this.ref }, { children: this.label }), void 0)),
                this.type === LinkControlType.URL && (_jsx(StyledLink, Object.assign({ size: size, underline: underline, "data-testid": "xlink-url", href: this.valueName ? this.getFormDataValue(this.valueName) : "", ref: this.ref }, { children: this.label }), void 0))] }, void 0));
    }
    getDesignValidationIssues() {
        let issues = [];
        if (!this.label) {
            issues.push(new ValidationIssue("Label is required", "label", this.id));
        }
        return issues;
    }
    getRuntimeValidationIssues() {
        let issues = [];
        return issues;
    }
    renderEditUI() {
        return _jsx(XLinkEditUI, { editMe: this }, void 0);
    }
    getAddedData() {
        return;
    }
}
function XLinkEditUI(props) {
    return (_jsxs(_Fragment, { children: [_jsx(PropertyEditorText, { editObject: props.editMe, propertyName: "label", updateCallback: props.editMe.controlUpdate, label: "Label" }, void 0),
            _jsx(PropertyEditorSelect, { editObject: props.editMe, propertyName: "size", options: [ButtonControlSize.SMALL, ButtonControlSize.STANDARD, ButtonControlSize.LARGE], updateCallback: props.editMe.controlUpdate, label: "Size" }, void 0),
            _jsx(PropertyEditorSelect, { editObject: props.editMe, propertyName: "type", options: [LinkControlType.URL, LinkControlType.ACTION], updateCallback: props.editMe.controlUpdate, label: "Type" }, void 0),
            _jsx(PropertyEditorSelect, { editObject: props.editMe, propertyName: "linkUnderline", options: [LinkControlUnderline.ALWAYS, LinkControlUnderline.HOVER, LinkControlUnderline.NONE], updateCallback: props.editMe.controlUpdate, label: "Underline" }, void 0),
            _jsx(Collapse, Object.assign({ in: props.editMe.type === LinkControlType.URL }, { children: _jsx(PropertyEditorText, { editObject: props.editMe, updateCallback: props.editMe.controlUpdate, propertyName: "valueName", label: "Value Name" }, void 0) }), void 0)] }, void 0));
}
//# sourceMappingURL=XLink.js.map