import type { EditorObject } from "../../../store/editorStore";
import Input from "@/components/Input";
import { normalizeLinkUrl } from "@/helpers/func";
import Select from "@/components/Select";
import ColorPicker from "@/components/ColorPicker";

const fontWeightOptions = [
    { label: "Bold", value: "bold" },
    { label: "Normal", value: "normal" },
    { label: "Light", value: "300" },
];

type LinkSettingsProps = {
    selectedObject: EditorObject;
    onUpdate: (id: string, updates: Partial<EditorObject>) => void;
};

const LinkSettings = ({ selectedObject, onUpdate }: LinkSettingsProps) => {
    return (
        <>
            <Input
                label="آدرس لینک"
                value={selectedObject.linkUrl || ""}
                onChange={(e) => onUpdate(selectedObject.id, { linkUrl: e.target.value })}
                onBlur={(e) => onUpdate(selectedObject.id, { linkUrl: normalizeLinkUrl(e.target.value) })}
                placeholder="https://example.com"
            />
            <Input
                label="متن لینک"
                value={selectedObject.text || ""}
                onChange={(e) => onUpdate(selectedObject.id, { text: e.target.value })}
            />
            <div className="flex gap-2">
                <Select
                    label="وزن فونت"
                    items={fontWeightOptions}
                    value={selectedObject.fontWeight || "normal"}
                    onChange={(e) => onUpdate(selectedObject.id, { fontWeight: e.target.value })}
                />
                <Input
                    label="اندازه فونت"
                    type="number"
                    value={selectedObject.fontSize || 24}
                    onChange={(e) =>
                        onUpdate(selectedObject.id, {
                            fontSize: parseInt(e.target.value) || 24,
                        })
                    }
                />
            </div>
            <ColorPicker
                label="رنگ متن"
                value={selectedObject.fill || "#0000ff"}
                onChange={(value) => onUpdate(selectedObject.id, { fill: value })}
            />
        </>
    );
};

export default LinkSettings;

