Electronic, magnetic, optical, and edge-reactivity properties of semiconducting and metallic WS2 nanoribbons