import type { Layer } from '@/types/layout';

export type SectionKey =
    | 'content'
    | 'transform'
    | 'opacity'
    | 'blend'
    | 'fill'
    | 'stroke'
    | 'shadow'
    | 'imageTransform'
    | 'imagePan'
    | 'crop'
    | 'clipShape'
    | 'filters'
    | 'text'
    | 'shapeKind'
    | 'cornerRadius'
    | 'devicePreset'
    | 'screenFill'
    /**
     * Frame-level skew/tilt/flip — applies to bezel + bound screen together.
     * Distinct from `imageTransform`, which targets a standalone image
     * layer's pan/zoom/skew/tilt and includes pan controls a frame doesn't
     * want (the screen has its own pan inside `frameScreen`).
     */
    | 'frameTransform'
    /**
     * Bound app-screen image on a frame layer (`FrameLayer.screen`). The
     * panel section internally renders an upload control plus, when a screen
     * is bound, fit/pan/zoom/crop/filters for the screen content.
     */
    | 'frameScreen'
    /**
     * Callout source picker + region editor (sourceLayerId + sourceRect %).
     * Only on `callout` layers.
     */
    | 'calloutSource'
    /**
     * Optional leader-line connecting a callout's source rect to its
     * display rect. Only on `callout` layers.
     */
    | 'calloutLeader';

export function capabilitiesFor(layer: Layer): Set<SectionKey> {
    switch (layer.type) {
        case 'text':
            return new Set<SectionKey>([
                'content',
                'transform',
                'opacity',
                'blend',
                'fill',
                'stroke',
                'shadow',
                'text',
            ]);
        case 'background':
            return new Set<SectionKey>(['fill', 'opacity']);
        case 'shape': {
            const caps = new Set<SectionKey>([
                'shapeKind',
                'transform',
                'opacity',
                'blend',
                'fill',
                'stroke',
                'shadow',
            ]);
            // Only rects expose a corner-radius control; ellipses/stars/etc.
            // drive their curvature from shape-specific fields.
            if (layer.shape === 'rect') caps.add('cornerRadius');
            return caps;
        }
        case 'image':
            return new Set<SectionKey>([
                'content',
                'transform',
                'opacity',
                'blend',
                'stroke',
                'shadow',
                'imageTransform',
                'crop',
                'clipShape',
                'filters',
            ]);
        case 'frame':
            return new Set<SectionKey>([
                'devicePreset',
                'transform',
                'frameTransform',
                'opacity',
                'blend',
                'fill',
                'stroke',
                'shadow',
                'screenFill',
                'frameScreen',
            ]);
        case 'group':
            return new Set<SectionKey>(['transform', 'opacity', 'blend']);
        case 'callout':
            return new Set<SectionKey>([
                'transform',
                'opacity',
                'blend',
                'fill',
                'stroke',
                'shadow',
                'calloutSource',
                'calloutLeader',
            ]);
    }
}
