@using Orchard.Fields.Settings
@using Orchard.Utility.Extensions;

@{
    string name = Model.ContentField.DisplayName;
    LinkFieldSettings settings = Model.ContentField.PartFieldDefinition.Settings.GetModel<LinkFieldSettings>();
    string text = Model.ContentField.Text;
    switch(settings.LinkTextMode) {
        case LinkTextMode.Static:
            text = settings.StaticText;
            break;
        case LinkTextMode.Url:
            text = Model.ContentField.Value;
            break;
        case LinkTextMode.Optional:
            if (String.IsNullOrWhiteSpace(text)) {
                text = Model.ContentField.Value;
            }
            break;
    }
}

@if (!String.IsNullOrEmpty(Model.ContentField.Value))
{
    <span class="link-field link-field-@name.HtmlClassify()">
        @name <a href="@Model.ContentField.Value" @if (!string.IsNullOrWhiteSpace(Model.ContentField.Target)) { <text> target="@Model.ContentField.Target" </text>   }>@text</a>
    </span>
}
