import { Group, geometry } from '@progress/kendo-drawing';
import { Border, Margin, Padding, RenderMode } from './field-types';
import { ValidationResult } from './validation';

/**
 * Supported symbologies (encodings) for the Barcode component.
 */
export type BarcodeType =
    'EAN8' | 'EAN13' | 'UPCE' | 'UPCA' | 'Code11' | 'Code39' | 'Code39Extended' |
    'Code93' | 'Code93Extended' | 'Code128' | 'Code128A' | 'Code128B' | 'Code128C' |
    'GS1-128' | 'MSImod10' | 'MSImod11' | 'MSImod1010' | 'MSImod1110' | 'POSTNET';

/**
 * The Barcode text label configuration.
 */
export interface BarcodeText {
    /**
     * The color of the text. Any valid CSS color string will work here, including hex and rgb.
     *
     * @default "black"
     */
    color?: string;

    /**
     * The font of the text.
     *
     * @default "16px Consolas, Monaco, Sans Mono, monospace, sans-serif"
     */
    font?: string;

    /**
     * The margin of the text. A numeric value sets all margins.
     *
     * @default 0
     */
    margin?: Margin | number;

    /**
     * A flag indicating of the Barcode text label is visible.
     *
     * If set to false the barcode will not display the value as a text below the barcode lines.
     *
     * @default true
     */
    visible?: boolean;
}

/**
 * The Barcode configuration options.
 */
export interface BarcodeOptions {
    /**
     * The background color of the Barcode. Accepts a valid CSS color string, including hex and rgb.
     *
     * @default "white"
     */
    background?: string;

    /**
     * The border of the Barcode.
     */
    border?: Border;

    /**
     * If set to `true`, the Barcode will display the checksum digit next to the value in the text area.
     *
     * @default true
     */
    checksum?: boolean;

    /**
     * The color of the Barcode. Accepts a valid CSS color string, including hex and rgb.
     *
     * @default "black"
     */
    color?: string;

    /**
     * The height of the Barcode in pixels.
     */
    height?: number;

    /**
     * The padding of the barcode. A numeric value sets all paddings.
     *
     * @default 0
     */
    padding?: Padding | number;

    /**
     * Sets the preferred rendering mode of the Barcode.
     *
     * The supported values are:
     * * "canvas" - renders the component as a Canvas element.
     * * "svg" - renders the component as an inline SVG document.
     *
     * @default "svg"
     */
    renderAs?: RenderMode;

    /**
     * The Barcode text label configuration.
     */
    text?: BarcodeText;

    /**
      * The symbology (encoding) the Barcode will use.
      *
      * @default "Code39"
      */
    type: BarcodeType;

    /**
     * The value of the Barcode.
     */
    value: number | string;

    /**
     * The width of the Barcode in pixels.
     */
    width?: number;
}

export class Barcode {
    constructor(element: Element, options: BarcodeOptions, errorHandler?: (error: Error) => void);

    public redraw(): void;
    public setOptions(options: BarcodeOptions): void;
    public exportVisual(): Group;
}

export function barcodeValidator(type: BarcodeType, size: geometry.Size): (value: number | string) => ValidationResult;
