class CropperModal extends Directive('hn.enterprise')
    constructor: (cropperModalService) ->
        ###
            Example:
            <a href cropper-modal="'/modules/enterprise/images/ben.jpg'"
                    cropper-modal-title="Crop Circles!"
                    cropper-modal-result="foo">crop dis! result:[{{ foo }}]</a>
        ###

        # TODO: this directive could benefit from requiring ng-model and setting result in there,
        # and/or setting initial crop position from that value.
        return {
            scope: {
                cropperModal: "="
                cropperModalTitle: "@"
                cropperModalResult: "="
            }
            link: (scope, elem) ->
                elem.on('click', (e) ->
                    e.preventDefault()
                    cropperModalService.open({
                        imageUrl: scope.cropperModal
                        modalTitle: scope.cropperModalTitle
                        cropperOptions: {
                            autoCropArea: 0.5
                        }
                        onCrop: (data, closeFn) ->
                            console.log('cropped:', data)
                            scope.cropperModalResult = data
                            closeFn()
                    })
                )

        }