import { __ } from "@wordpress/i18n";
import "./editor.scss";
import keyIcon from "./img/icon_feather_key.svg";
import chainIcon from "./img/icon_block_chain.svg";
import houseIcon from "./img/icon_house.svg";
import bulbIcon from "./img/icon_bulb.svg";
import {
RichText,
useBlockProps,
BlockControls,
InnerBlocks,
InspectorControls,
MediaReplaceFlow,
} from "@wordpress/block-editor";
import { trash } from "@wordpress/icons";
import {
Button,
ToolbarButton,
PanelBody,
ToggleControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from "@wordpress/components";
export default function Edit({ attributes, setAttributes }) {
const {
title,
iconName,
hasTitle,
hasTitleIcon,
hasLogo,
variant,
logoAlt,
logoId,
logoUrl,
} = attributes;
function getIconPicture() {
switch (iconName) {
case "key":
return keyIcon;
case "chain":
return chainIcon;
case "house":
return houseIcon;
case "bulb":
return bulbIcon;
}
}
function onIconChange(newIconName) {
setAttributes({ iconName: newIconName });
}
function onTitleChange(title) {
setAttributes({ title });
}
function onHasTitleChange() {
setAttributes({
hasTitle: !hasTitle,
title: undefined,
});
}
function onhasTitleIconChange() {
setAttributes({
hasTitleIcon: !hasTitleIcon,
});
}
function onVariantChange(variant) {
setAttributes({ variant });
}
function onHasLogoChange() {
setAttributes({
hasLogo: !hasLogo,
});
if (!hasLogo) {
removeLogoAttributes();
}
}
function setLogoAttributes(media) {
setAttributes({
logoUrl: media.url,
logoId: media.id,
logoAlt: media?.alt,
});
}
function removeLogoAttributes() {
setAttributes({
logoUrl: null,
logoId: null,
logoAlt: null,
});
}
let iconPicture = getIconPicture();
return (
<>
{hasLogo && (
{logoUrl &&
}
{logoUrl && (
<>
>
)}
)}
onIconChange("key")}
/>
onIconChange("chain")}
/>
onIconChange("house")}
/>
onIconChange("bulb")}
/>
{hasTitle && (
)}
{hasLogo && (
{!logoUrl && (
)}
{logoUrl &&

}
)}
>
);
}