'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var index = require('../packages/ui/dist/index.js');
var VectorEditor_module = require('./VectorEditor.module.css.js');
var vectorEditorTypes = require('./vectorEditorTypes.js');
var vectorGradients = require('./vectorGradients.js');

const VectorEditorRightPanel = ({ api }) => {
    var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
    const { tool, selId, selShape, shapes, fillCol, strokeCol, strokeW, shapeOpacity, cornerRadius, polygonSides, starPoints2, starInnerRatio, fontSize, fontFamily, snapGrid, gridSize, setFillCol, setStrokeCol, setStrokeW, setShapeOpacity, setCornerRadius, setPolygonSides, setStarPoints2, setStarInnerRatio, setFontSize, setFontFamily, setGridSize, updateSel, setSelId, setTool, } = api;
    // Gradient editing state
    const [fillMode, setFillMode] = React.useState("solid");
    const [selectedGradient, setSelectedGradient] = React.useState(null);
    const [showGradientEditor, setShowGradientEditor] = React.useState(false);
    const applyGradient = (gradient) => {
        const newGrad = { ...vectorGradients.cloneGradient(gradient), id: vectorGradients.gradientId() };
        setSelectedGradient(newGrad);
        // Store gradient in shape as serialized reference
        updateSel({
            fill: `url(#${newGrad.id})`,
            // Store gradient data as custom property (will be used in SVG export)
        });
    };
    return (jsxRuntime.jsxs("div", { className: VectorEditor_module.rightPanel, children: [jsxRuntime.jsxs("div", { className: VectorEditor_module.panelSection, children: [jsxRuntime.jsx("div", { className: VectorEditor_module.panelTitle, children: jsxRuntime.jsx("span", { children: "Appearance" }) }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Fill" }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: 4 }, children: [jsxRuntime.jsx(index.NiceButton, { className: `${VectorEditor_module.menuBtn} ${fillMode === "solid" ? VectorEditor_module.menuBtnActive : ""}`, style: { padding: "2px 6px", fontSize: 10 }, variant: fillMode === "solid" ? "primary" : "ghost", size: "sm", onClick: () => setFillMode("solid"), children: "Solid" }), jsxRuntime.jsx(index.NiceButton, { className: `${VectorEditor_module.menuBtn} ${fillMode === "gradient" ? VectorEditor_module.menuBtnActive : ""}`, style: { padding: "2px 6px", fontSize: 10 }, variant: fillMode === "gradient" ? "primary" : "ghost", size: "sm", onClick: () => setFillMode("gradient"), children: "Gradient" })] })] }), fillMode === "solid" ? (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel }), jsxRuntime.jsx("div", { className: VectorEditor_module.propColorSwatch, style: { background: fillCol }, children: jsxRuntime.jsx(index.NiceColorPicker, { value: fillCol, onChange: (c) => { setFillCol(c); updateSel({ fill: c }); } }) }), jsxRuntime.jsx(index.NiceTextInput, { className: VectorEditor_module.propInput, value: (selShape === null || selShape === void 0 ? void 0 : selShape.fill) || fillCol, onChange: (val) => { setFillCol(val); updateSel({ fill: val }); } })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: VectorEditor_module.propRow, style: { flexWrap: "wrap", gap: 4 }, children: vectorGradients.PRESET_GRADIENTS.map((grad, i) => (jsxRuntime.jsx("div", { style: {
                                        width: 24,
                                        height: 24,
                                        borderRadius: 4,
                                        background: vectorGradients.gradientToCSS(grad),
                                        cursor: "pointer",
                                        border: (selectedGradient === null || selectedGradient === void 0 ? void 0 : selectedGradient.id) === grad.id ? "2px solid #fff" : "1px solid #444",
                                    }, onClick: () => applyGradient(grad), title: `${grad.type} gradient` }, i))) }), jsxRuntime.jsx("div", { className: VectorEditor_module.propRow, children: jsxRuntime.jsx(index.NiceButton, { className: VectorEditor_module.menuBtn, variant: "ghost", size: "sm", style: { width: "100%", fontSize: 10 }, onClick: () => setShowGradientEditor(!showGradientEditor), children: showGradientEditor ? "▼ Hide Editor" : "► Edit Gradient" }) }), showGradientEditor && selectedGradient && (jsxRuntime.jsxs("div", { style: { padding: 4, background: "#252525", borderRadius: 4, margin: "4px 0" }, children: [jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Type" }), jsxRuntime.jsx(index.NiceSelect, { className: VectorEditor_module.propInput, value: selectedGradient.type, onChange: (val) => {
                                                    const type = val;
                                                    let newGrad;
                                                    if (type === "linear") {
                                                        newGrad = {
                                                            type: "linear",
                                                            id: vectorGradients.gradientId(),
                                                            angle: 0,
                                                            stops: selectedGradient.stops,
                                                        };
                                                    }
                                                    else {
                                                        newGrad = {
                                                            type: "radial",
                                                            id: vectorGradients.gradientId(),
                                                            cx: 0.5,
                                                            cy: 0.5,
                                                            r: 0.7,
                                                            stops: selectedGradient.stops,
                                                        };
                                                    }
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                }, options: [
                                                    { value: "linear", label: "Linear" },
                                                    { value: "radial", label: "Radial" },
                                                ] })] }), selectedGradient.type === "linear" && (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Angle" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 0, max: 360, value: selectedGradient.angle, onChange: (val) => {
                                                    const newGrad = {
                                                        ...selectedGradient,
                                                        id: vectorGradients.gradientId(),
                                                        angle: val,
                                                    };
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                } }), jsxRuntime.jsxs("span", { style: { fontSize: 10, minWidth: 28 }, children: [selectedGradient.angle, "\u00B0"] })] })), selectedGradient.type === "radial" && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "CX" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 0, max: 100, value: selectedGradient.cx * 100, onChange: (val) => {
                                                            const newGrad = {
                                                                ...selectedGradient,
                                                                id: vectorGradients.gradientId(),
                                                                cx: val / 100,
                                                            };
                                                            setSelectedGradient(newGrad);
                                                            updateSel({ fill: `url(#${newGrad.id})` });
                                                        } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "CY" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 0, max: 100, value: selectedGradient.cy * 100, onChange: (val) => {
                                                            const newGrad = {
                                                                ...selectedGradient,
                                                                id: vectorGradients.gradientId(),
                                                                cy: val / 100,
                                                            };
                                                            setSelectedGradient(newGrad);
                                                            updateSel({ fill: `url(#${newGrad.id})` });
                                                        } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "R" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 10, max: 100, value: selectedGradient.r * 100, onChange: (val) => {
                                                            const newGrad = {
                                                                ...selectedGradient,
                                                                id: vectorGradients.gradientId(),
                                                                r: val / 100,
                                                            };
                                                            setSelectedGradient(newGrad);
                                                            updateSel({ fill: `url(#${newGrad.id})` });
                                                        } })] })] })), jsxRuntime.jsx("div", { style: { fontSize: 10, color: "#888", marginTop: 4 }, children: "Color Stops:" }), selectedGradient.stops.map((stop, i) => (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx(index.NiceColorPicker, { value: stop.color, style: { width: 24, height: 20 }, onChange: (color) => {
                                                    const newStops = [...selectedGradient.stops];
                                                    newStops[i] = { ...newStops[i], color };
                                                    const newGrad = { ...selectedGradient, id: vectorGradients.gradientId(), stops: newStops };
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                } }), jsxRuntime.jsx(index.NiceSlider, { min: 0, max: 100, value: stop.offset * 100, style: { flex: 1 }, onChange: (val) => {
                                                    const newStops = [...selectedGradient.stops];
                                                    newStops[i] = { ...newStops[i], offset: val / 100 };
                                                    newStops.sort((a, b) => a.offset - b.offset);
                                                    const newGrad = { ...selectedGradient, id: vectorGradients.gradientId(), stops: newStops };
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                } }), jsxRuntime.jsxs("span", { style: { fontSize: 9, minWidth: 24 }, children: [Math.round(stop.offset * 100), "%"] })] }, i))), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, style: { gap: 4 }, children: [jsxRuntime.jsx(index.NiceButton, { className: VectorEditor_module.menuBtn, variant: "ghost", size: "sm", style: { fontSize: 10, flex: 1 }, onClick: () => {
                                                    const newStops = [...selectedGradient.stops, { offset: 0.5, color: "#888888" }];
                                                    newStops.sort((a, b) => a.offset - b.offset);
                                                    const newGrad = { ...selectedGradient, id: vectorGradients.gradientId(), stops: newStops };
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                }, children: "+ Add Stop" }), jsxRuntime.jsx(index.NiceButton, { className: VectorEditor_module.menuBtn, variant: "ghost", size: "sm", style: { fontSize: 10, flex: 1 }, disabled: selectedGradient.stops.length <= 2, onClick: () => {
                                                    if (selectedGradient.stops.length <= 2)
                                                        return;
                                                    const newStops = selectedGradient.stops.slice(0, -1);
                                                    const newGrad = { ...selectedGradient, id: vectorGradients.gradientId(), stops: newStops };
                                                    setSelectedGradient(newGrad);
                                                    updateSel({ fill: `url(#${newGrad.id})` });
                                                }, children: "- Remove" })] })] }))] })), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Stroke" }), jsxRuntime.jsx("div", { className: VectorEditor_module.propColorSwatch, style: { background: strokeCol }, children: jsxRuntime.jsx(index.NiceColorPicker, { value: strokeCol, onChange: (c) => { setStrokeCol(c); updateSel({ stroke: c }); } }) }), jsxRuntime.jsx(index.NiceTextInput, { className: VectorEditor_module.propInput, value: (selShape === null || selShape === void 0 ? void 0 : selShape.stroke) || strokeCol, onChange: (val) => { setStrokeCol(val); updateSel({ stroke: val }); } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Width" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 0, max: 100, value: (_a = selShape === null || selShape === void 0 ? void 0 : selShape.strokeWidth) !== null && _a !== void 0 ? _a : strokeW, onChange: (val) => { const v = val !== null && val !== void 0 ? val : 0; setStrokeW(v); updateSel({ strokeWidth: v }); } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Opacity" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 0, max: 1, step: 0.01, value: (_b = selShape === null || selShape === void 0 ? void 0 : selShape.opacity) !== null && _b !== void 0 ? _b : shapeOpacity, onChange: (val) => { setShapeOpacity(val); updateSel({ opacity: val }); } }), jsxRuntime.jsxs("span", { style: { fontSize: 10, minWidth: 28 }, children: [Math.round(((_c = selShape === null || selShape === void 0 ? void 0 : selShape.opacity) !== null && _c !== void 0 ? _c : shapeOpacity) * 100), "%"] })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Rotation" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: -360, max: 360, value: (_d = selShape === null || selShape === void 0 ? void 0 : selShape.rotation) !== null && _d !== void 0 ? _d : 0, onChange: (val) => updateSel({ rotation: val !== null && val !== void 0 ? val : 0 }) }), jsxRuntime.jsx("span", { style: { fontSize: 10 }, children: "\u00B0" })] })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.panelSection, children: [jsxRuntime.jsx("div", { className: VectorEditor_module.panelTitle, children: jsxRuntime.jsx("span", { children: "Tool Options" }) }), (tool === "roundrect" || (selShape === null || selShape === void 0 ? void 0 : selShape.type) === "roundrect") && (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Radius" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 0, max: 200, value: (_e = selShape === null || selShape === void 0 ? void 0 : selShape.rx) !== null && _e !== void 0 ? _e : cornerRadius, onChange: (val) => { const v = val !== null && val !== void 0 ? val : 0; setCornerRadius(v); updateSel({ rx: v }); } })] })), (tool === "polygon" || (selShape === null || selShape === void 0 ? void 0 : selShape.type) === "polygon") && (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Sides" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 3, max: 32, value: (_f = selShape === null || selShape === void 0 ? void 0 : selShape.sides) !== null && _f !== void 0 ? _f : polygonSides, onChange: (val) => { const v = val !== null && val !== void 0 ? val : 3; setPolygonSides(v); updateSel({ sides: v }); } })] })), (tool === "star" || (selShape === null || selShape === void 0 ? void 0 : selShape.type) === "star") && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Points" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 3, max: 32, value: (_g = selShape === null || selShape === void 0 ? void 0 : selShape.sides) !== null && _g !== void 0 ? _g : starPoints2, onChange: (val) => { const v = val !== null && val !== void 0 ? val : 3; setStarPoints2(v); updateSel({ sides: v }); } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Inner R" }), jsxRuntime.jsx(index.NiceSlider, { className: VectorEditor_module.propInput, min: 0.1, max: 0.9, step: 0.05, value: (_h = selShape === null || selShape === void 0 ? void 0 : selShape.innerRadius) !== null && _h !== void 0 ? _h : starInnerRatio, onChange: (val) => { setStarInnerRatio(val); updateSel({ innerRadius: val }); } }), jsxRuntime.jsxs("span", { style: { fontSize: 10 }, children: [Math.round(((_j = selShape === null || selShape === void 0 ? void 0 : selShape.innerRadius) !== null && _j !== void 0 ? _j : starInnerRatio) * 100), "%"] })] })] })), (tool === "text" || (selShape === null || selShape === void 0 ? void 0 : selShape.type) === "text") && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Size" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 8, max: 200, value: (_k = selShape === null || selShape === void 0 ? void 0 : selShape.fontSize) !== null && _k !== void 0 ? _k : fontSize, onChange: (val) => { const v = val !== null && val !== void 0 ? val : 12; setFontSize(v); updateSel({ fontSize: v }); } })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Font" }), jsxRuntime.jsx(index.NiceSelect, { className: VectorEditor_module.propInput, value: (_l = selShape === null || selShape === void 0 ? void 0 : selShape.fontFamily) !== null && _l !== void 0 ? _l : fontFamily, onChange: (val) => { setFontFamily(val); updateSel({ fontFamily: val }); }, options: vectorEditorTypes.FONTS.map((f) => ({ value: f, label: f })) })] })] })), snapGrid && (jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Grid" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, min: 4, max: 128, value: gridSize, onChange: (val) => setGridSize(val !== null && val !== void 0 ? val : 8) })] }))] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.panelSection, children: [jsxRuntime.jsx("div", { className: VectorEditor_module.panelTitle, children: jsxRuntime.jsxs("span", { children: ["Shapes (", shapes.length, ")"] }) }), [...shapes].reverse().map((s) => (jsxRuntime.jsxs("div", { className: `${VectorEditor_module.shapeItem} ${s.id === selId ? VectorEditor_module.shapeItemActive : ""}`, onClick: () => { setSelId(s.id); setTool("pointer"); }, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.shapeIcon, children: s.type === "rect" ? "▢"
                                    : s.type === "roundrect" ? "▣"
                                        : s.type === "ellipse" ? "◯"
                                            : s.type === "line" ? "╱"
                                                : s.type === "arrow" ? "→"
                                                    : s.type === "polygon" ? "⬡"
                                                        : s.type === "star" ? "★"
                                                            : s.type === "polyline" ? "✎"
                                                                : "T" }), jsxRuntime.jsxs("span", { className: VectorEditor_module.shapeName, children: [s.type, s.text ? ` "${s.text}"` : ""] })] }, s.id))), shapes.length === 0 && (jsxRuntime.jsx("div", { style: { color: "#555", fontSize: 11, padding: 4 }, children: "No shapes yet. Use the tools to draw." }))] }), selShape && (jsxRuntime.jsxs("div", { className: VectorEditor_module.panelSection, children: [jsxRuntime.jsx("div", { className: VectorEditor_module.panelTitle, children: jsxRuntime.jsx("span", { children: "Transform" }) }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "X" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, value: Math.round(selShape.x), onChange: (val) => updateSel({ x: val !== null && val !== void 0 ? val : 0 }) })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "Y" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, value: Math.round(selShape.y), onChange: (val) => updateSel({ y: val !== null && val !== void 0 ? val : 0 }) })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "W" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, value: Math.round(selShape.w), onChange: (val) => updateSel({ w: val !== null && val !== void 0 ? val : 0 }) })] }), jsxRuntime.jsxs("div", { className: VectorEditor_module.propRow, children: [jsxRuntime.jsx("span", { className: VectorEditor_module.propLabel, children: "H" }), jsxRuntime.jsx(index.NiceNumberInput, { className: VectorEditor_module.propInput, value: Math.round(selShape.h), onChange: (val) => updateSel({ h: val !== null && val !== void 0 ? val : 0 }) })] })] }))] }));
};
var VectorEditorRightPanel$1 = React.memo(VectorEditorRightPanel);

module.exports = VectorEditorRightPanel$1;
//# sourceMappingURL=VectorEditorRightPanel.js.map
