import { delegateCombine, delegateRemove } from './type';
import { ShapefileConverter as ShapefileConverter_internal } from "./ShapefileConverter";
import { fromRect, toRect, ensureBool } from "./componentUtil";
import { IgcAsyncCompletedEventArgs } from './igc-async-completed-event-args';
import { IgcShapefileRecord } from './igc-shapefile-record';
import { IgcShapeFilterRecordEventArgs } from './igc-shape-filter-record-event-args';
/**
 * Class used to convert Shapefiles into CLR objects.
*/
export class IgcShapeDataSource {
    constructor() {
        //@@ZoneRunner
        this._importPending = null;
        this._importPending_wrapped = null;
        this._importCompleted = null;
        this._importCompleted_wrapped = null;
        this._filter = null;
        this._filter_wrapped = null;
        this._implementation = this.createImplementation();
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    }
    createImplementation() {
        return new ShapefileConverter_internal();
    }
    get i() {
        return this._implementation;
    }
    onImplementationCreated() {
    }
    _provideImplementation(i) {
        this._implementation = i;
        this._implementation.externalObject = this;
        this.onImplementationCreated();
    }
    //   private _databaseSource: string;
    ///**
    // * Gets the string Uri path of the .dbf portion of the Shapefile
    //*/
    //   get databaseSource(): string {
    //       return this._databaseSource;
    //   }
    ///**
    // * Sets the string Uri path of the .dbf portion of the Shapefile
    //*/
    //   set databaseSource(v: string) {
    //       this._databaseSource = v;
    //   }
    //   private _shapefileSource: string;
    ///**
    // * Gets the string Uri path of the .shp portion of the Shapefile
    //*/
    //   get shapefileSource(): string {
    //       return this._shapefileSource;
    //   }
    ///**
    // * Sets the string Uri path of the .shp portion of the Shapefile
    //*/
    //   set shapefileSource(v: string) {
    //       this._shapefileSource = v;
    //   }
    dataBind() {
        //this.i.shapefileSource = null;
        //this.i.databaseSource = null;
        //if (this._shapefileSource && this._databaseSource) {
        //    this.i.shapefileSource = new Uri(0, this._shapefileSource);
        //    this.i.databaseSource = new Uri(0, this._databaseSource);
        //}
    }
    /**
    * Gets the point data.
    */
    getPointData() {
        let list = this.i.getPointData();
        let ret = [];
        for (var i = 0; i < list.count; i++) {
            var shapeRecord = list.item(i);
            if (!shapeRecord.externalObject) {
                let e = new IgcShapefileRecord();
                e._implementation = shapeRecord;
                shapeRecord.externalObject = e;
            }
            ret.push(shapeRecord.externalObject);
        }
        return ret;
    }
    get name() {
        return this.i.name;
    }
    set name(v) {
        this.i.name = v;
    }
    /**
     * Gets the world bounding rectangle, as read from the header of the Shapefile.
    */
    get worldRect() {
        return fromRect(this.i.worldRect);
    }
    set worldRect(v) {
        this.i.worldRect = toRect(v);
    }
    /**
     * Gets the world bounding rectangle, based on the filtered shapes
    */
    get computedWorldRect() {
        return fromRect(this.i.computedWorldRect);
    }
    set computedWorldRect(v) {
        this.i.computedWorldRect = toRect(v);
    }
    /**
     * Gets the shape type, as read from the header of the Shapefile.
    */
    get shapeType() {
        return this.i.shapeType;
    }
    /**
     * Gets the header of the Shapefile.
    */
    get shapeHeader() {
        return this.i.shapeHeader;
    }
    set shapeHeader(v) {
        this.i.shapeHeader = v;
    }
    /**
     * The Uri of the .shp portion of the Shapefile.
    */
    get deferImportCompleted() {
        return this.i.deferImportCompleted;
    }
    set deferImportCompleted(v) {
        this.i.deferImportCompleted = ensureBool(v);
    }
    /**
     * The Uri of the .shp portion of the Shapefile.
    */
    get shapefileSource() {
        return this.i.shapefileSource;
    }
    set shapefileSource(v) {
        this.i.shapefileSource = v;
    }
    /**
     * The Uri of the .dbf portion of the Shapefile.
    */
    get databaseSource() {
        return this.i.databaseSource;
    }
    set databaseSource(v) {
        this.i.databaseSource = v;
    }
    /**
     * The total number of ShapefileRecords in the collection.
    */
    get count() {
        return this.i.count;
    }
    getWorldBounds(useComputed) {
        let iv = this.i.getWorldBounds(useComputed);
        return fromRect(iv);
    }
    setWorldBounds(setComputed, bounds) {
        this.i.setWorldBounds(setComputed, toRect(bounds));
    }
    sendImportCompleted() {
        this.i.sendImportCompleted();
    }
    getRecordsCount() {
        let iv = this.i.getRecordsCount();
        return (iv);
    }
    getRecord(index) {
        let iv = this.i.getRecord(index);
        return (iv == null ? null : iv.externalObject);
    }
    getRecordBounds(index) {
        let iv = this.i.getRecordBounds(index);
        return fromRect(iv);
    }
    getRecordFieldNames(index) {
        let iv = this.i.getRecordFieldNames(index);
        return (iv);
    }
    getRecordValue(index, fieldName) {
        let iv = this.i.getRecordValue(index, fieldName);
        return (iv);
    }
    removeRecord(index) {
        this.i.removeRecord(index);
    }
    shiftShapes(recordIndex, offsetX, offsetY) {
        this.i.shiftShapes(recordIndex, offsetX, offsetY);
    }
    getMaxLongitude(recordIndex, useLargestShape, fromLongitude, toLongitude) {
        let iv = this.i.getMaxLongitude(recordIndex, useLargestShape, fromLongitude, toLongitude);
        return (iv);
    }
    setRecordValue(index, fieldName, value) {
        this.i.setRecordValue(index, fieldName, value);
    }
    getRecordValues(fieldName) {
        let iv = this.i.getRecordValues(fieldName);
        return (iv);
    }
    setRecordValues(fieldName, values) {
        this.i.setRecordValues(fieldName, values);
    }
    getLargestShapeBoundsForRecord(index) {
        let iv = this.i.getLargestShapeBoundsForRecord(index);
        return fromRect(iv);
    }
    /**
     * Event raised when the Shapefile has been imported from both the ShapefileSource and DatabaseSource Uris.
    */
    get importPending() {
        return this._importPending;
    }
    set importPending(ev) {
        if (this._importPending_wrapped !== null) {
            this.i.importPending = delegateRemove(this.i.importPending, this._importPending_wrapped);
            this._importPending_wrapped = null;
            this._importPending = null;
        }
        this._importPending = ev;
        this._importPending_wrapped = (o, e) => {
            let outerArgs = new IgcAsyncCompletedEventArgs();
            outerArgs._provideImplementation(e);
            if (this.beforeImportPending) {
                this.beforeImportPending(this, outerArgs);
            }
            if (this._importPending) {
                this._importPending(this, outerArgs);
            }
        };
        this.i.importPending = delegateCombine(this.i.importPending, this._importPending_wrapped);
    }
    /**
     * Event raised when the Shapefile has been imported from both the ShapefileSource and DatabaseSource Uris.
    */
    get importCompleted() {
        return this._importCompleted;
    }
    set importCompleted(ev) {
        if (this._importCompleted_wrapped !== null) {
            this.i.importCompleted = delegateRemove(this.i.importCompleted, this._importCompleted_wrapped);
            this._importCompleted_wrapped = null;
            this._importCompleted = null;
        }
        this._importCompleted = ev;
        this._importCompleted_wrapped = (o, e) => {
            let outerArgs = new IgcAsyncCompletedEventArgs();
            outerArgs._provideImplementation(e);
            if (this.beforeImportCompleted) {
                this.beforeImportCompleted(this, outerArgs);
            }
            if (this._importCompleted) {
                this._importCompleted(this, outerArgs);
            }
        };
        this.i.importCompleted = delegateCombine(this.i.importCompleted, this._importCompleted_wrapped);
    }
    get filter() {
        return this._filter;
    }
    set filter(ev) {
        if (this._filter_wrapped !== null) {
            this.i.filter = delegateRemove(this.i.filter, this._filter_wrapped);
            this._filter_wrapped = null;
            this._filter = null;
        }
        this._filter = ev;
        this._filter_wrapped = (o, e) => {
            let outerArgs = new IgcShapeFilterRecordEventArgs();
            outerArgs._provideImplementation(e);
            if (this.beforeFilter) {
                this.beforeFilter(this, outerArgs);
            }
            if (this._filter) {
                this._filter(this, outerArgs);
            }
        };
        this.i.filter = delegateCombine(this.i.filter, this._filter_wrapped);
    }
}
//# sourceMappingURL=igc-shape-data-source.js.map
