<div class="ma_page_content">
	<div class="ma_pc_inner">
		<div class="container">
			<div class="content ds_import_sc">
				<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="#f50" d="M11.56,8.87V17H20.32V17C22.17,16.87 23,15.73 23,14.33C23,12.85 21.88,11.66 20.38,11.66C20,11.66 19.68,11.74 19.35,11.88C19.11,9.54 17.12,7.71 14.67,7.71C13.5,7.71 12.39,8.15 11.56,8.87M10.68,9.89C10.38,9.71 10.06,9.57 9.71,9.5V17H11.1V9.34C10.95,9.5 10.81,9.7 10.68,9.89M8.33,9.35V17H9.25V9.38C9.06,9.35 8.87,9.34 8.67,9.34C8.55,9.34 8.44,9.34 8.33,9.35M6.5,10V17H7.41V9.54C7.08,9.65 6.77,9.81 6.5,10M4.83,12.5C4.77,12.5 4.71,12.44 4.64,12.41V17H5.56V10.86C5.19,11.34 4.94,11.91 4.83,12.5M2.79,12.22V16.91C3,16.97 3.24,17 3.5,17H3.72V12.14C3.64,12.13 3.56,12.12 3.5,12.12C3.24,12.12 3,12.16 2.79,12.22M1,14.56C1,15.31 1.34,15.97 1.87,16.42V12.71C1.34,13.15 1,13.82 1,14.56Z" /></svg>
				<h3 class="light">{{LANG Import From soundcloud.}}</h3>
				<input type="url" name="soundcloudurl" id="soundcloudurl" class="form-control" value="" placeholder="https://soundcloud.com/fouad007/cendere-medium">
				<p>{{LANG Enter the soundcloud track link and click the button below.}}</p>
				<button class="btn btn-primary btn-mat" id="btnimport">{{LANG Import}}</button>
			</div>
		</div>
	</div>
</div>
<div class="modal fade" id="messagebox" tabindex="-1" role="dialog" aria-labelledby="messagebox" aria-hidden="true" data-id="0">
	<div class="modal-dialog mat_box" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<h5 class="modal-title">{{LANG Import From soundcloud.}}</h5>
			</div>
			<div class="modal-body">{{LANG Are you sure you want to delete this track?}}</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">{{LANG Close}}</button>
			</div>
		</div>
	</div>
</div>

<script>
    function isUrlValid(url) {
        return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url);
    }
    $(function () {
        $('#btnimport').click(function(event) {
            event.preventDefault();
            var soundTrackLink = $('#soundcloudurl').val();
            if( isUrlValid(soundTrackLink) === false ){
                $('#messagebox').find('.modal-body').html("{{LANG Please enter valid soundcloud track url.}}");
                $('#messagebox').modal('show');
                return false;
			}
            $('#btnimport').prop('disabled', true );
            $('#btnimport').text('{{LANG Please wait...}}');
            $('#importloader').removeClass('hidden');
            var postForm = new FormData();
            	postForm.append( 'track_link', $('#soundcloudurl').val() );
            $.ajax({
                type: 'POST',
                url: '{{CONFIG ajax_url}}/soundcloud?hash_id=' + $('.main_session').val(),
                data: postForm,
                processData: false,
                contentType: false,
                success: function(data) {
                    if (data.status == 200) {
                        $('#btnimport').prop('disabled', false );
                        $('#btnimport').text('{{LANG Import}}');
                        $('#importloader').addClass('hidden');
                        $('#soundcloudurl').val('');
                        $('#soundcloudurl').focus();
                        var trackid = data.trackid;
                        setTimeout(function () {
                            goToAjaxLink('edit-track/' + trackid);
                        }, 1000);
                    } else if (data.status == 400) {
                        $('#messagebox').find('.modal-body').html(data.message);
                        $('#messagebox').modal('show');
                    } else {
                        $('#messagebox').find('.modal-body').html("{{LANG Error found while importing your track, please try again later.}}");
                        $('#messagebox').modal('show');
                    }
                    $('#btnimport').prop('disabled', false );
                    $('#btnimport').text('{{LANG Import}}');
                    $('#importloader').addClass('hidden');
                    $('#soundcloudurl').val('');
                    $('#soundcloudurl').focus();
                }
            });
        });
    });
</script>