/**
 * EventKoi Event Data Block Registration.
 *
 * @package EventKoi
 */

import { registerBlockType } from "@wordpress/blocks";
import { __ } from "@wordpress/i18n";
import { attributes } from "./attributes";
import Edit from "./edit";
import "./editor.scss";
import { icon } from "./icon";
import save from "./save";

registerBlockType("eventkoi/event-data", {
  apiVersion: 3,
  title: __("EK Event Data", "eventkoi-lite"),
  description: __(
    "Display specific details (title, location, time, etc.) from an event. Can be used alone or inside an Event Query.",
    "eventkoi-lite"
  ),
  category: "eventkoi-blocks",
  icon,
  attributes,

  // ---------------------------------------------------------------------
  // Block supports.
  // These flags ensure the block can be selected, moved, and reordered.
  // ---------------------------------------------------------------------
  supports: {
    reusable: false,
    inserter: true, // Allow appearing in inserter.
    multiple: true, // Allow multiple instances.
    lock: false, // Disable full locking (can move).
    __experimentalMovable: true, // Explicitly enable move up/down handles.

    color: {
      text: true,
      background: true,
    },
    typography: {
      fontSize: true,
      lineHeight: true,
      textColumns: true,
      textIndent: true,
      __experimentalFontFamily: true,
      __experimentalTextDecoration: true,
      __experimentalFontStyle: true,
      __experimentalFontWeight: true,
      __experimentalLetterSpacing: true,
      __experimentalTextTransform: true,
      __experimentalWritingMode: true,
      fitText: true,
      __experimentalDefaultControls: {
        fontSize: true,
      },
    },
    spacing: {
      margin: true,
      padding: true,
    },
    align: ["left", "center", "right"],
  },

  // ---------------------------------------------------------------------
  // Dynamic label for List View / breadcrumbs.
  // ---------------------------------------------------------------------
  __experimentalLabel: (attributes) => {
    const labels = {
      title: __("Title", "eventkoi-lite"),
      excerpt: __("Excerpt / Description", "eventkoi-lite"),
      timeline: __("Date and Time", "eventkoi-lite"),
      location: __("Location", "eventkoi-lite"),
      image: __("Image", "eventkoi-lite"),
    };
    const label = labels[attributes.field] || __("Unknown", "eventkoi-lite");
    return `Event data: ${label}`;
  },

  edit: Edit,
  save,
});
