import {
    typoPrefix_title,
    typoPrefix_content,
    typoPrefix_badge,
} from "./constants/typographyPrefixConstants";
import {
    generateTypographyAttributes,
    generateResponsiveRangeAttributes,
    generateDimensionsAttributes,
    generateBackgroundAttributes,
    generateBorderShadowAttributes,
    ImageComponent,
} from "@essential-blocks/controls";
import {
    connectorWidth,
    listSpace,
    rowSpace,
    iconBackgroundType,
    iconBackgroundSize,
    iconPadding,
    iconSize,
    iconSpace,
    titleSpace,
    iconBorder,
    wrapperMargin,
    wrapperPadding,
    boxPadding,
    boxBackgroundType,
    boxBorder,
    wrapperBorder,
    wrapperBackgroundType,
    listBackgroundType,
    listBorderShadow,
    listPadding,
    badgePadding,
    badgeBorder,
    iconLiquidGlassShadowEffectBorder,
} from "./constants";

const attributes = {
    // the following 4 attributes is must required for responsive options and asset generation for frontend
    // responsive control attributes ⬇
    resOption: {
        type: "string",
        default: "Desktop",
    },
    // blockId attribute for making unique className and other uniqueness ⬇
    blockId: {
        type: "string",
    },
    blockRoot: {
        type: "string",
        default: "essential_block",
    },
    // blockMeta is for keeping all the styles ⬇
    blockMeta: {
        type: "object",
    },
    featureListAlign: {
        type: "string",
    },
    features: {
        type: "array",
        source: "query",
        selector: ".eb-feature-list-wrapper .eb-feature-list-items li",
        query: {
            title: {
                type: "string",
                source: "text",
                selector: ".eb-feature-list-title",
            },
            iconType: {
                type: "string",
                source: "attribute",
                attribute: "data-icon-type",
            },
            featureImageId: {
                type: "string",
                source: "attribute",
                attribute: "data-image-id",
            },
            featureImage: {
                type: "string",
                source: "attribute",
                attribute: "data-image",
            },
            featureImageAlt: {
                type: "string",
                source: "attribute",
                attribute: "data-alt",
            },
            featureImageTitle: {
                type: "string",
                source: "attribute",
                attribute: "data-title",
            },
            icon: {
                type: "string",
                source: "attribute",
                attribute: "data-icon",
            },
            iconColor: {
                type: "string",
                source: "attribute",
                attribute: "data-icon-color",
            },
            iconBackgroundColor: {
                type: "string",
                source: "attribute",
                attribute: "data-icon-background-color",
            },
            content: {
                type: "string",
                source: "text",
                selector: ".eb-feature-list-content",
            },
            link: {
                type: "string",
                source: "attribute",
                attribute: "data-link",
            },
            linkOpenNewTab: {
                type: "string",
                source: "attribute",
                attribute: "data-new-tab",
            },
            showBadge: {
                type: "string",
                source: "attribute",
                attribute: "data-show-badge",
            },
            badgeText: {
                type: "string",
                source: "attribute",
                attribute: "data-badge-text",
            },
            badgeTextColor: {
                type: "string",
                source: "attribute",
                attribute: "data-badge-text-color",
            },
            badgeBackgroundColor: {
                type: "string",
                source: "attribute",
                attribute: "data-badge-background-color",
            },
        },
        default: [
            {
                iconType: "icon",
                icon: "fas fa-check",
                title: "Feature Item 1",
                content:
                    "Lorem ipsum dolor sit amet, consectetur adipisi cing elit, sed do eiusmod tempor incididunt ut abore et dolore magna",
                iconColor: "",
                link: "",
                linkOpenNewTab: "false",
                iconBackgroundColor: "",
                showBadge: 'false',
                badgeText: "New",
                badgeTextColor: "",
                badgeBackgroundColor: "",
            },
            {
                iconType: "icon",
                icon: "fas fa-times",
                title: "Feature Item 2",
                content:
                    "Lorem ipsum dolor sit amet, consectetur adipisi cing elit, sed do eiusmod tempor incididunt ut abore et dolore magna",
                iconColor: "",
                link: "",
                linkOpenNewTab: "false",
                iconBackgroundColor: "",
                showBadge: 'false',
                badgeText: "New",
                badgeTextColor: "",
                badgeBackgroundColor: "",
            },
            {
                iconType: "icon",
                icon: "fas fa-anchor",
                title: "Feature Item 3",
                content:
                    "Lorem ipsum dolor sit amet, consectetur adipisi cing elit, sed do eiusmod tempor incididunt ut abore et dolore magna",
                iconColor: "",
                link: "",
                linkOpenNewTab: "false",
                iconBackgroundColor: "",
                showBadge: 'false',
                badgeText: "New",
                badgeTextColor: "",
                badgeBackgroundColor: "",
            },
        ]
    },
    iconGlobalColor: {
        type: "string",
        default: "var(--eb-global-background-color)",
    },
    titleTag: {
        type: "string",
        default: "h3",
    },
    iconShape: {
        type: "string",
        default: "circle",
    },
    shapeView: {
        type: "string",
        default: "stacked",
    },
    iconPosition: {
        type: "string",
        default: "left",
    },
    titleTextColor: {
        type: "string",
        default: "var(--eb-global-heading-color)",
    },
    titleTextHoverColor: {
        type: "string",
    },
    descTextColor: {
        type: "string",
        default: "var(--eb-global-text-color)",
    },
    showContentVertical: {
        type: "boolean",
        default: false,
    },
    showConnector: {
        type: "boolean",
        default: false,
    },
    connectorStyle: {
        type: "string",
        default: "style-1",
    },
    connectorType: {
        type: "string",
        default: "solid",
    },
    connectorColor: {
        type: "string",
        default: "var(--eb-global-primary-color)",
    },
    useInlineDesign: {
        type: "boolean",
        default: false,
    },

    designItemBox: {
        type: "boolean",
        default: false,
    },
    // Global badge colors
    badgeTextColor: {
        type: "string",
        default: "#fff",
    },
    badgeBackgroundColor: {
        type: "string",
        default: "var(--eb-global-primary-color)",
    },
    badgeGap: {
        type: "number",
        default: 5,
    },

    iconLiquidGlass: {
        type: "object",
        default: {
            enable: false,
            effect: "effect1",
            shadowEffect: "effect1",
            backgroundColor: "#FFFFFF1F",
            backdropFilter: 24,
            brightness: 1,
        },
    },

    ...generateResponsiveRangeAttributes(connectorWidth, {
        defaultRange: 2,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(listSpace, {
        defaultRange: 20,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(rowSpace, {
        defaultRange: 10,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(iconBackgroundSize, {
        defaultRange: 60,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(iconSize, {
        defaultRange: 21,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(iconSpace, {
        defaultRange: 20,
        noUnits: true,
    }),
    ...generateResponsiveRangeAttributes(titleSpace, {
        defaultRange: 5,
        noUnits: true,
    }),

    // typography attributes
    ...generateTypographyAttributes(typoPrefix_title, {
        fontSize: 18
    }),
    ...generateTypographyAttributes(typoPrefix_content, {
        fontSize: 14
    }),
    ...generateTypographyAttributes(typoPrefix_badge, {
        fontSize: 12
    }),
    // background attributes
    ...generateBackgroundAttributes(iconBackgroundType, {
        defaultFillColor: "var(--eb-global-primary-color)",
        noOverlay: true,
        noMainBgi: true,
    }),
    ...generateBackgroundAttributes(boxBackgroundType, {
        noOverlay: true,
        noMainBgi: true,
    }),
    ...generateBackgroundAttributes(wrapperBackgroundType),
    // Dimension attributes
    ...generateDimensionsAttributes(iconPadding, {
        top: 15,
        right: 15,
        bottom: 15,
        left: 15,
        isLinked: false,
    }),
    ...generateDimensionsAttributes(boxPadding),
    ...generateDimensionsAttributes(wrapperMargin, {
        top: 28,
        right: 0,
        bottom: 28,
        left: 0,
        isLinked: false,
    }),
    ...generateDimensionsAttributes(wrapperPadding, {
        top: 10,
        right: 10,
        bottom: 10,
        left: 10,
        isLinked: true,
    }),
    ...generateDimensionsAttributes(badgePadding, {
        top: 2,
        right: 10,
        bottom: 2,
        left: 10,
        isLinked: false,
    }),
    // border
    ...generateBorderShadowAttributes(iconBorder, {
        bdrDefaults: {
            top: 2,
            right: 2,
            bottom: 2,
            left: 2,
        },
        noShadow: true,
        defaultBdrColor: "#6e2d8d",
        defaultBdrStyle: "solid",
    }),
    ...generateBorderShadowAttributes(boxBorder),
    ...generateBorderShadowAttributes(wrapperBorder),
    ...generateBorderShadowAttributes(badgeBorder, {
        rdsDefaults: {
            top: 10,
            right: 10,
            bottom: 10,
            left: 10,
        },
    }),

    ...generateBackgroundAttributes(listBackgroundType, {
        noOverlay: true,
        noMainBgi: true,
    }),
    ...generateBorderShadowAttributes(listBorderShadow, {
        noShadow: true,
    }),
    ...generateDimensionsAttributes(listPadding),
    ...generateBorderShadowAttributes(iconLiquidGlassShadowEffectBorder, {
        defaultBdrColor: "#FFFFFF1F",
        defaultBdrStyle: "solid",
        bdrDefaults: {
            top: 1,
            bottom: 1,
            right: 1,
            left: 1,
        },
        rdsDefaults: {
            top: 24,
            bottom: 24,
            right: 24,
            left: 24,
        },
    }),

    // Image masking attributes (per QA report TC for FeatureList)
    // Note: per-item masking would require migrating into the `features` array;
    // for v1 these are block-level (shared across all feature items).
    ...ImageComponent?.addAttributes({
        hasBorder: false,
        hasPadding: false,
        hasMargin: false,
        hasWidth: false,
        hasHeight: false,
    }),
};

export default attributes;
